Skip to content

Commit

Permalink
Clean up #18
Browse files Browse the repository at this point in the history
  • Loading branch information
howawong committed Mar 27, 2018
1 parent 06c3d34 commit 0404ac8
Show file tree
Hide file tree
Showing 25 changed files with 204 additions and 119 deletions.
6 changes: 3 additions & 3 deletions gov_track_hk_web/api/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.db import models
from datetime import datetime


class Consultation(models.Model):
lang = models.CharField(max_length=128)
date = models.DateTimeField()
link = models.CharField(max_length=1024)
key = models.CharField(max_length=128)
title = models.CharField(max_length=1024)

class Meta:
unique_together = ('lang', 'key')

def __unicode__(self):
return self.link + "-" + self.title.encode("utf-8") + "-" + self.lang


97 changes: 71 additions & 26 deletions gov_track_hk_web/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,77 @@
from django.conf.urls import url, include
from django.conf.urls import include, url
from rest_framework import routers

from api import views

router = routers.DefaultRouter()
router.register(r'latest_bills', views.LatestBillsViewSet, base_name='latest_bills')
router.register(r'latest_votes', views.LatestVotesViewSet, base_name='latest_votes')
router.register(r'votes_search/(?P<keyword>.*)', views.VotesSearchViewSet, base_name='votes_search')
router.register(r'parties', views.PartiesViewSet)
router.register(r'meetings', views.MeetingsViewSet, base_name='meetings')
router.register(r'meetings/(?P<year>[0-9]+)', views.MeetingsViewSet, base_name='meetings')
router.register(r'questions', views.LatestQuestionsViewSet, base_name='questions')
router.register(r'questions/(?P<keyword>\w*)', views.LatestQuestionsViewSet, base_name='questions')
router.register(r'questions/(?P<keyword>\w*)/(?P<page>[0-9]+)', views.LatestQuestionsViewSet, base_name='questions')
router.register(r'most_present', views.MostPresentIndividualsViewSet, base_name='most_present')
router.register(r'most_absent', views.MostAbsentIndividualsViewSet, base_name='most_absent')
router.register(r'most_speech', views.MostSpeechIndividualsViewSet, base_name='most_speech')
router.register(r'subscribe', views.SubscribeViewSet, base_name='subscribe')
router.register(r'consultations', views.ConsultationsViewSet, base_name='consultations')
router.register(r'weather', views.WeatherViewSet, base_name='weather')
router.register(r'party/(?P<pk>.+)', views.PartyDetailViewSet, base_name='party')
router.register(r'bills', views.AllBillsViewSet, base_name='bills')
router.register(r'news', views.NewsViewSet, base_name='news')
router.register(r'bills/(?P<keyword>\w*)', views.AllBillsViewSet, base_name='bills')
router.register(r'bills/(?P<keyword>\w*)/(?P<page>[0-9]+)', views.AllBillsViewSet, base_name='bills')
router.register(r'important_motion', views.ImportantMotionViewSet, base_name='important_motion')
router.register(r'speeches/(?P<keyword>\w*)', views.MeetingSpeechSearchViewSet, base_name='speeches')
router.register(r'speeches', views.MeetingSpeechSearchViewSet, base_name='speeches')
router.register(r'latest_bills',
views.LatestBillsViewSet,
base_name='latest_bills')
router.register(r'latest_votes',
views.LatestVotesViewSet,
base_name='latest_votes')
router.register(r'votes_search/(?P<keyword>.*)',
views.VotesSearchViewSet,
base_name='votes_search')
router.register(r'parties',
views.PartiesViewSet)
router.register(r'meetings',
views.MeetingsViewSet,
base_name='meetings')
router.register(r'meetings/(?P<year>[0-9]+)',
views.MeetingsViewSet,
base_name='meetings')
router.register(r'questions',
views.LatestQuestionsViewSet,
base_name='questions')
router.register(r'questions/(?P<keyword>\w*)',
views.LatestQuestionsViewSet,
base_name='questions')
router.register(r'questions/(?P<keyword>\w*)/(?P<page>[0-9]+)',
views.LatestQuestionsViewSet,
base_name='questions')
router.register(r'most_present',
views.MostPresentIndividualsViewSet,
base_name='most_present')
router.register(r'most_absent',
views.MostAbsentIndividualsViewSet,
base_name='most_absent')
router.register(r'most_speech',
views.MostSpeechIndividualsViewSet,
base_name='most_speech')
router.register(r'subscribe',
views.SubscribeViewSet,
base_name='subscribe')
router.register(r'consultations',
views.ConsultationsViewSet,
base_name='consultations')
router.register(r'weather',
views.WeatherViewSet,
base_name='weather')
router.register(r'party/(?P<pk>.+)',
views.PartyDetailViewSet,
base_name='party')
router.register(r'bills',
views.AllBillsViewSet,
base_name='bills')
router.register(r'news',
views.NewsViewSet,
base_name='news')
router.register(r'bills/(?P<keyword>\w*)',
views.AllBillsViewSet,
base_name='bills')
router.register(r'bills/(?P<keyword>\w*)/(?P<page>[0-9]+)',
views.AllBillsViewSet,
base_name='bills')
router.register(r'important_motion',
views.ImportantMotionViewSet,
base_name='important_motion')
router.register(r'speeches/(?P<keyword>\w*)',
views.MeetingSpeechSearchViewSet,
base_name='speeches')
router.register(r'speeches',
views.MeetingSpeechSearchViewSet,
base_name='speeches')
urlpatterns = [
url(r'', include(router.urls))
]


30 changes: 16 additions & 14 deletions gov_track_hk_web/api/views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# -*- coding: utf-8 -*-
from django.db import IntegrityError
from django.db.models import Q
from django.core.cache import cache
from rest_framework import viewsets
from django.db.models import Count
from legco.models import Vote, Motion, Party, Individual, IndividualVote, VoteSummary, Bill, Question, MeetingHansard, MeetingSpeech, ImportantMotion, ImportantMotion
from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.decorators import detail_route, list_route
from datetime import datetime, timedelta, date
from subscriber.models import Subscriber, News
import re
from datetime import date, datetime, timedelta
from hashlib import md5

import requests
from django.core.cache import cache
from django.db import IntegrityError
from django.db.models import Count, Q
from lxml import etree, html
import re
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from api.models import Consultation
from rest_framework import serializers, viewsets
from rest_framework.authentication import (BasicAuthentication,
SessionAuthentication)
from rest_framework.decorators import detail_route, list_route
from rest_framework.response import Response

from api.models import Consultation
from legco.models import (Bill, ImportantMotion, Individual, IndividualVote,
MeetingHansard, MeetingSpeech, Motion, Party,
Question, Vote, VoteSummary)
from subscriber.models import News, Subscriber


class CsrfExemptSessionAuthentication(SessionAuthentication):
Expand Down
3 changes: 0 additions & 3 deletions gov_track_hk_web/district/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

# Register your models here.
5 changes: 0 additions & 5 deletions gov_track_hk_web/district/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
from __future__ import unicode_literals

from django.db import models

# Create your models here.
3 changes: 0 additions & 3 deletions gov_track_hk_web/district/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.test import TestCase

# Create your tests here.
6 changes: 4 additions & 2 deletions gov_track_hk_web/district/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.conf.urls import url, include
from district.views import *
from django.conf.urls import url

from district.views import index_view

urlpatterns = [
url(r'^$', index_view)
]
8 changes: 5 additions & 3 deletions gov_track_hk_web/district/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.shortcuts import render
from django.db.models import Count
def index_view(request):
return render(request, 'district/index.html', {'nbar': 'home', 'tbar':'dc'})


def index_view(request):
return render(request,
'district/index.html',
{'nbar': 'home', 'tbar': 'dc'})
4 changes: 3 additions & 1 deletion gov_track_hk_web/gov_track_hk_web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.conf.urls import include, url
from django.contrib import admin

from gov_track_hk_web import views

urlpatterns = [
url(r'^$', views.index_view),
url(r'^projects/', views.other_projects_view),
Expand Down
8 changes: 5 additions & 3 deletions gov_track_hk_web/gov_track_hk_web/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django.shortcuts import render

# Create your views here.


def index_view(request):
return render(request, 'index.html', {'tbar': 'home', 'nbar':'home'})

def other_projects_view(request):
return render(request, 'other_projects.html', {'tbar': 'home', 'nbar':'projects'})


return render(request,
'other_projects.html',
{'tbar': 'home', 'nbar':'projects'}
)
15 changes: 9 additions & 6 deletions gov_track_hk_web/legco/admin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from django.contrib import admin
from django import forms
from django.contrib import admin
from django.db import models
from django.utils.html import mark_safe
from legco.models import Party, Individual, Council, Constituency, Meeting, Motion, VoteSummary, IndividualVote, Vote, CouncilMember, CouncilMembershipType
from legco.models import Bill, BillCommittee, BillThirdReading, BillFirstReading, BillSecondReading
from legco.models import MeetingSpeech, MeetingHansard
from legco.models import Question

from legco.models import (Bill, BillCommittee, BillFirstReading,
BillSecondReading, BillThirdReading, Constituency,
Council, CouncilMember, CouncilMembershipType,
Individual, IndividualVote, Meeting, MeetingHansard,
MeetingSpeech, Motion, Party, Question, Vote,
VoteSummary)


class CouncilAdmin(admin.ModelAdmin):
formfield_overrides = {
Expand Down Expand Up @@ -43,4 +47,3 @@ class CouncilMemberAdmin(admin.ModelAdmin):
admin.site.register(MeetingHansard)
admin.site.register(CouncilMember, CouncilMemberAdmin)
admin.site.register(CouncilMembershipType)

5 changes: 4 additions & 1 deletion gov_track_hk_web/legco/bill_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.db import models
from datetime import datetime

from dirtyfields import DirtyFieldsMixin
from django.db import models

from .common_models import *

#

class BillThirdReading(DirtyFieldsMixin, models.Model):
Expand Down
6 changes: 3 additions & 3 deletions gov_track_hk_web/legco/common_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models
from datetime import datetime

from django.db import models


class Keyword(models.Model):
keyword = models.CharField(max_length=128, unique=True)
def __unicode__(self):
Expand All @@ -21,5 +23,3 @@ class Individual(models.Model):
image = models.CharField(max_length=512, blank=True, null=True, default=None)
def __unicode__(self):
return self.name_en + "-" + self.name_ch


5 changes: 4 additions & 1 deletion gov_track_hk_web/legco/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.db import models
from datetime import datetime

from django.db import models

from .bill_model import *
from .common_models import *

# Create your models here.

class Motion(models.Model):
Expand Down
39 changes: 29 additions & 10 deletions gov_track_hk_web/legco/templatetags/legco_extras.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# -*- coding: utf-8 -*
from django import template
from django.template.defaultfilters import stringfilter
from datetime import datetime, date
from legco.models import *
register = template.Library()
import random
from datetime import datetime
register = template.Library()


@register.filter
def parse_date_chinese(d):
if d is datetime and d.replace(tzinfo=None) == datetime.min:
return "未知"
return "%d年%d月%d日" % (d.year, d.month, d.day)


@register.filter
def article_source_chinese(s):
if s == "mingpao":
Expand All @@ -19,33 +20,51 @@ def article_source_chinese(s):
return "蘋果日報"
return ""


@register.filter
def is_date_min(d):
return d.replace(tzinfo=None) == datetime.min
return d.replace(tzinfo=None) == datetime.min


@register.simple_tag
def random_label():
labels = ["label-default", "label-primary", "label-success", "label-info" ,"label-warning" ,"label-danger"]
return labels[random.randint(0,len(labels) - 1)]
labels = ["label-default",
"label-primary",
"label-success",
"label-info",
"label-warning",
"label-danger"]
return labels[random.randint(0, len(labels) - 1)]


@register.simple_tag
def random_panel(i=-1):
labels = ["default", "primary", "success", "info" ,"warning" ,"danger"]
labels = ["default",
"primary",
"success",
"info",
"warning",
"danger"]
if i == -1:
i = random.randint(0,len(labels) - 1)
i = random.randint(0, len(labels) - 1)
return "panel-" + labels[i]


@register.filter
def vote_result_chinese(result):
return "通過" if result.lower() == "passed" else "否決"


@register.filter
def vote_result_color(result):
return "#00ff00" if result.lower() == "passed" else "#ff0000"


@register.filter
def vote_chinese(v):
d = {'YES': '贊成', 'NO': '反對' , 'ABSTAIN': '棄權', 'PRESENT': '出席', 'ABSENT': '缺席'}
d = {'YES': '贊成',
'NO': '反對',
'ABSTAIN': '棄權',
'PRESENT': '出席',
'ABSENT': '缺席'}
return d[v]
6 changes: 3 additions & 3 deletions gov_track_hk_web/legco/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

from django.conf.urls import url, include
from django.conf.urls import include, url

from legco.views import *

urlpatterns = [
url(r'^$', index_view),
url(r'^vote/$', all_votes_view),
Expand All @@ -25,5 +27,3 @@
url(r'^councils/$', councils_view),
url(r'^members/(?P<pk>[0-9]+)/$', members_view),
]


Loading

0 comments on commit 0404ac8

Please sign in to comment.