コード例 #1
0
ファイル: views.py プロジェクト: echelon-tw/twly-voter-guide
def biller_detail(request, legislator_id, ad):
    qs = Q(
        content=request.GET['keyword']) if request.GET.get('keyword') else Q()
    ly = get_object_or_404(LegislatorDetail.objects,
                           ad=ad,
                           legislator_id=legislator_id)
    if len(qs):
        bills_id = [
            x.uid
            for x in SearchQuerySet().filter(qs).models(Bill).order_by('-uid')
        ]
        bills = ly.bills.select_related('bill').prefetch_related(
            'bill__laws').filter(legislator_id=ly.id,
                                 role='sponsor',
                                 bill_id__in=bills_id)
    else:
        bills = ly.bills.select_related('bill').prefetch_related(
            'bill__laws').filter(legislator_id=ly.id, role='sponsor')
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    get_params = '&'.join([
        '%s=%s' % (x, request.GET[x]) for x in ['keyword']
        if request.GET.get(x)
    ])
    return render(
        request, 'legislator/biller_detail.html', {
            'keyword_obj': keywords,
            'hot_keyword': keywords[:5],
            'bills': bills,
            'ly': ly,
            'keyword': request.GET.get('keyword', ''),
            'get_params': get_params
        })
コード例 #2
0
ファイル: views.py プロジェクト: nyampire/twly-voter-guide
def voter_detail(request, legislator_id, index, keyword_url):
    keyword, keyword_valid, votes, error, notvote, query = None, False, None, False, False, Q()
    ly = get_legislator(legislator_id)
    if not ly:
        return HttpResponseRedirect('/')
    #--> 沒投票的表決是否搜尋
    if 'notvote' in request.GET:
        notvote = request.GET['notvote']
        if notvote:
            query = Q(decision__isnull=False)
    #<--
    # 脫黨投票
    if index == 'conscience':
        query = query & Q(legislator_id=ly.id, conflict=True)
    else:
        query = query & Q(legislator_id=ly.id)
    #<--
    if 'keyword' in request.GET:
        keyword = re.sub(u'[,。/\、;][=-<>?:"{}|+_()!@#%$︿&*~~`!@#$%^&*_+-=,./<>?;:\'\"\[\]{}\|()]',' ',request.GET['keyword']).strip()
    elif keyword_url:
        keyword = keyword_url.strip()
    if keyword:
        keyword_valid = True
        votes = Legislator_Vote.objects.select_related().filter(query & reduce(operator.and_, (Q(vote__content__icontains=x) for x in keyword.split()))).order_by('-vote')
        if votes:
            keyword_obj = Keyword.objects.filter(category=2, content=keyword.strip())
            if keyword_obj:
                keyword_obj.update(hits=F('hits')+1)
            else:
                k = Keyword(content=keyword.strip(), category=2, valid=True, hits=1)
                k.save()
    else:
        votes = Legislator_Vote.objects.select_related().filter(query).order_by('-vote')
    vote_addup = votes.values('decision').annotate(totalNum=Count('vote', distinct=True)).order_by('-decision')
    return render(request,'legislator/voter_detail.html', {'keyword_obj':keyword_list(2),'ly':ly,'index':index,'votes':votes,'keyword':keyword,'error':error,'vote_addup':vote_addup,'notvote':notvote})
コード例 #3
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def biller_detail(request,legislator_id,keyword_url):
    law, error, keyword, proposertype = None, False, None, False
    ly = LegislatorDetail.objects.get(ad=8, legislator_id=legislator_id)
    if ly:
        ly.hits = F('hits') + 1
        ly.save(update_fields=['hits'])
    query = Q(proposer__id=ly.id, legislator_bill__priproposer=True)
    if 'proposertype' in request.GET:
        proposertype = request.GET['proposertype']
        if proposertype:
            query = Q(proposer__id=ly.id)
    bills = Bill.objects.filter(query)
    #laws = bills.values('law').distinct().order_by('law')
    #if 'law' in request.GET:
    #    law = request.GET['law']
    #    if law:
    #        query = query & Q(law=law)
    if 'keyword' in request.GET:
        keyword = re.sub(u'[,。/\、;][=-<>?:"{}|+_()!@#%$︿&*~~`!@#$%^&*_+-=,./<>?;:\'\"\[\]{}\|()]',' ',request.GET['keyword']).strip()
    elif keyword_url:
        keyword = keyword_url.strip()
    if keyword:
        bills = bills.filter(query & reduce(operator.or_, (Q(abstract__icontains=x) for x in keyword.split())))
    else:
        bills = bills.filter(query)
    return render(request,'legislator/biller_detail.html', {'keyword_obj':keyword_list(3),'bills':bills,'ly':ly,'keyword':keyword,'error':error,'proposertype':proposertype})
コード例 #4
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def proposer_detail(request, legislator_id, keyword_url):
    error,keyword,proposertype = False,None,False
    ly = LegislatorDetail.objects.get(ad=8, legislator_id=legislator_id)
    if ly:
        ly.hits = F('hits') + 1
        ly.save(update_fields=['hits'])
    query = Q(proposer__id=ly.id, legislator_proposal__priproposer=True)
    if 'proposertype' in request.GET:
        proposertype = request.GET['proposertype']
        if proposertype:
            query = Q(proposer__id=ly.id)
    if 'keyword' in request.GET:
        keyword = re.sub(u'[,。/\、;][=-<>?:"{}|+_()!@#%$︿&*~~`!@#$%^&*_+-=,./<>?;:\'\"\[\]{}\|()]',' ',request.GET['keyword']).strip()
    elif keyword_url:
        keyword = keyword_url.strip()
    if keyword:
        proposal = Proposal.objects.filter(query & reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-sitting__date')
        if proposal:
            proposal.filter(hits__isnull=False).update(hits=F('hits')+1)
            proposal.filter(hits__isnull=True).update(hits=1)
            keyword_obj = Keyword.objects.filter(category=1, content=keyword.strip())
            if keyword_obj:
                keyword_obj.update(hits=F('hits')+1)
            else:
                k = Keyword(content=keyword.strip(), category=1, valid=True, hits=1)
                k.save()
    else:
        proposal = Proposal.objects.filter(query).order_by('-sitting__date')
    return render(request,'legislator/proposer_detail.html', {'keyword_obj':keyword_list(1),'proposal':proposal,'ly':ly,'keyword':keyword,'error':error,'proposertype':proposertype})
コード例 #5
0
ファイル: views.py プロジェクト: flaing/twly-voter-guide
def voter_detail(request, legislator_id, index, ad):
    votes, notvote, query = None, False, Q()
    ad = ad or 8
    ly = get_legislator(legislator_id, ad)
    if not ly:
        return HttpResponseRedirect('/')
    #--> 依投票類型分類
    decision_query = {"agree": Q(decision=1), "disagree": Q(decision=-1), "abstain": Q(decision=0), "notvote": Q(decision__isnull=True)}
    if 'decision' in request.GET:
        decision = request.GET['decision']
        if decision_query.get(decision):
            query = decision_query.get(decision)
    #<--
    # 脫黨投票
    if index == 'conscience':
        query = query & Q(legislator_id=ly.id, conflict=True)
    else:
        query = query & Q(legislator_id=ly.id)
    #<--
    keyword = keyword_normalize(request.GET)
    if keyword:
        votes = Legislator_Vote.objects.select_related().filter(query & reduce(operator.and_, (Q(vote__content__icontains=x) for x in keyword.split()))).order_by('-vote__sitting__date')
        if votes:
            keyword_been_searched(keyword, 2)
    else:
        votes = Legislator_Vote.objects.select_related().filter(query).order_by('-vote__sitting__date')
    vote_addup = votes.values('decision').annotate(totalNum=Count('vote', distinct=True)).order_by('-decision')
    return render(request,'legislator/voter_detail.html', {'keyword_obj':keyword_list(2),'ly':ly,'index':index,'votes':votes,'keyword':keyword,'vote_addup':vote_addup,'notvote':notvote})
コード例 #6
0
def votes(request, county, index='normal'):
    result = None
    if index == 'conscience':
        query = Q(sitting__county=county, conflict=True)
    else:
        query = Q(sitting__county=county)
    #--> 依表決結果分類
    if 'result' in request.GET:
        result = request.GET['result']
        query = query & Q(result=result)
    #<--
    keyword = keyword_normalize(request.GET)
    if keyword:
        votes = Votes.objects.filter(query & reduce(operator.and_, (Q(
            content__icontains=x) for x in keyword.split()))).order_by(
                '-date', 'vote_seq')
        if votes:
            keyword_been_searched(keyword, 'votes')
    else:
        votes = Votes.objects.filter(query).order_by('-date', 'vote_seq')
    return render(
        request, 'votes/votes.html', {
            'county': county,
            'votes': votes,
            'index': index,
            'keyword': keyword,
            'result': result,
            'keyword_hot': keyword_list('votes')
        })
コード例 #7
0
def biller_detail(request, legislator_id, ad):
    ly = get_object_or_404(LegislatorDetail.objects, ad=ad, legislator_id=legislator_id)
    bills = ly.bills.filter(legislator_id=ly.id, priproposer=True)
    qs = Q(uid__in=bills.values_list('bill_id', flat=True))
    qs = qs & Q(content=request.GET['keyword']) if request.GET.get('keyword') else qs
    bills = SearchQuerySet().filter(qs).models(Bill).order_by('-last_action_at')
    keywords = keyword_list(3)
    return render(request, 'legislator/biller_detail.html',  {'keyword_obj': keywords, 'hot_keyword': keywords[:5], 'bills': bills, 'ly': ly, 'keyword': request.GET.get('keyword', '')})
コード例 #8
0
ファイル: views.py プロジェクト: IanWang/twly-voter-guide
def bills(request):
    if request.GET.get('keyword'):
        bills_uid = [x.uid for x in SearchQuerySet().filter(content=request.GET['keyword']).models(Bill).order_by('-uid')]
        bills = Bill.objects.filter(uid__in=bills_uid)
    else:
        bills = Bill.objects.filter(ad=8)
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    return render(request, 'bill/bills.html', {'bills': bills, 'keyword_obj': keywords, 'hot_keyword': keywords[:5], 'keyword': request.GET.get('keyword', '')})
コード例 #9
0
ファイル: views.py プロジェクト: g0v/twly-voter-guide
def bills(request):
    if request.GET.get('keyword'):
        bills_uid = [x.uid for x in SearchQuerySet().filter(content=request.GET['keyword']).models(Bill)]
        bills = Bill.objects.filter(uid__in=bills_uid).prefetch_related('laws').order_by('-uid')
    else:
        bills = Bill.objects.all().prefetch_related('laws').order_by('-uid')
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    get_params = '&'.join(['%s=%s' % (x, request.GET[x]) for x in ['keyword'] if request.GET.get(x)])
    return render(request, 'bill/bills.html', {'bills': bills, 'keyword_obj': keywords, 'hot_keyword': keywords[:5], 'keyword': request.GET.get('keyword', ''), 'get_params': get_params})
コード例 #10
0
ファイル: views.py プロジェクト: IanWang/twly-voter-guide
def biller_detail(request, legislator_id, ad):
    qs = Q(content=request.GET['keyword']) if request.GET.get('keyword') else Q()
    bills_id = [x.uid for x in SearchQuerySet().filter(qs).models(Bill).order_by('-uid')]
    ly = get_object_or_404(LegislatorDetail.objects, ad=ad, legislator_id=legislator_id)
    if len(qs):
        bills = ly.bills.select_related('bill').filter(legislator_id=ly.id, role='sponsor', bill_id__in=bills_id)
    else:
        bills = ly.bills.select_related('bill').filter(legislator_id=ly.id, role='sponsor')
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    return render(request, 'legislator/biller_detail.html',  {'keyword_obj': keywords, 'hot_keyword': keywords[:5], 'bills': bills, 'ly': ly, 'keyword': request.GET.get('keyword', '')})
コード例 #11
0
ファイル: views.py プロジェクト: FallwinDs/twly-voter-guide
def bills(request, keyword_url, index):
    query = Q()
    keyword = keyword_normalize(request, keyword_url)
    if keyword:
        bills = Bill.objects.filter(reduce(operator.or_, (Q(abstract__icontains=x) | Q(summary__icontains=x) for x in keyword.split())))
        query = Q(reduce(operator.or_, (Q(abstract__icontains=x) | Q(summary__icontains=x) for x in keyword.split())))
        if bills:
            keyword_been_searched(keyword, 3)
    if index == 'normal':
        bills = Bill.objects.filter(query, last_action__isnull=False).order_by('-last_action_at')[:100]
    elif index == 'rejected':
        bills = Bill.objects.filter(query & Q(ttsmotions__progress='退回程序')).annotate(totalNum=Count('ttsmotions__id')).filter(totalNum__gt=1).order_by('-totalNum')
    return render(request,'bill/bills.html', {'index':index, 'keyword_obj':keyword_list(3), 'keyword':keyword, 'bills':bills})
コード例 #12
0
def bills(request, category, county):
    query = Q(county=county)
    if request.GET.get('has_tag') == 'yes':
        query = query & Q(uid__in=Standpoints.objects.filter(
            bill__isnull=False).values_list('bill_id', flat=True).distinct())
    elif request.GET.get('has_tag') == 'no':
        query = query & ~Q(uid__in=Standpoints.objects.filter(
            bill__isnull=False).values_list('bill_id', flat=True).distinct())
    if category == 'councilors':
        query = query & Q(uid__in=Councilors_Bills.objects.all().values_list(
            'bill_id', flat=True).distinct())
    elif category == 'city_gov':

        query = query & Q(uid__in=Mayors_Bills.objects.all().values_list(
            'bill_id', flat=True).distinct())
    query = query & Q(uid__in=Standpoints.objects.filter(
        title=request.GET['tag'], bill__isnull=False).values_list(
            'bill_id', flat=True).distinct()) if request.GET.get(
                'tag') else query
    keyword = request.GET.get('keyword', '')
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(
            abstract__icontains=x) for x in split_unicode_chrs(keyword))))
        if bills:
            keyword_been_searched(keyword, 'bills', county)
    else:
        bills = Bills.objects.filter(query)
    bills = bills.extra(
                     select={
                         'tags': "SELECT json_agg(row) FROM (SELECT title, pro FROM standpoints_standpoints su WHERE su.bill_id = bills_bills.uid ORDER BY su.pro DESC) row",
                     },
                 )\
                 .order_by('-election_year', '-uid')
    bills = paginate(request, bills)
    standpoints = Standpoints.objects.filter(
        county=county,
        bill__isnull=False).values_list('title',
                                        flat=True).order_by('-pro').distinct()
    get_params = '&'.join([
        '%s=%s' % (x, request.GET[x]) for x in ['keyword', 'has_tag', 'tag']
        if request.GET.get(x)
    ])
    return render(
        request, 'bills/bills.html', {
            'county': county,
            'keyword_hot': keyword_list('bills', county),
            'category': category,
            'bills': bills,
            'standpoints': standpoints,
            'get_params': get_params
        })
コード例 #13
0
def bills(request):
    qs = Q(content=request.GET["keyword"]) if request.GET.get("keyword") else Q()
    qs = qs & Q(last_action=request.GET["progress"]) if request.GET.get("progress") else qs
    bills = SearchQuerySet().filter(qs).models(Bill).order_by("-last_action_at")
    keywords = keyword_list(3)
    return render(
        request,
        "bill/bills.html",
        {
            "index": "",
            "bills": bills,
            "keyword_obj": keywords,
            "hot_keyword": keywords[:5],
            "keyword": request.GET.get("keyword", ""),
            "progress": request.GET.get("progress", ""),
        },
    )
コード例 #14
0
def bills(request):
    if request.GET.get('keyword'):
        bills_uid = [
            x.uid for x in SearchQuerySet().filter(
                content=request.GET['keyword']).models(Bill).order_by('-uid')
        ]
        bills = Bill.objects.filter(uid__in=bills_uid)
    else:
        bills = Bill.objects.filter(ad=8)
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    return render(
        request, 'bill/bills.html', {
            'bills': bills,
            'keyword_obj': keywords,
            'hot_keyword': keywords[:5],
            'keyword': request.GET.get('keyword', '')
        })
コード例 #15
0
ファイル: views.py プロジェクト: inno-v/councilor-voter-guide
def bills(request, county, index):
    query = Q(county=county)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(
            abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    return render(
        request, 'bills/bills.html', {
            'county': county,
            'index': index,
            'keyword_hot': keyword_list('bills'),
            'keyword': keyword,
            'bills': bills
        })
コード例 #16
0
ファイル: views.py プロジェクト: flaing/twly-voter-guide
def proposer_detail(request, legislator_id):
    proposertype = False
    ly = get_legislator(legislator_id, ad=8)
    if not ly:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=ly.id, legislator_proposal__priproposer=True)
    if 'proposertype' in request.GET:
        proposertype = request.GET['proposertype']
        if proposertype:
            query = Q(proposer__id=ly.id)
    keyword = keyword_normalize(request.GET)
    if keyword:
        proposal = Proposal.objects.filter(query & reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-sitting__date')
        if proposal:
            keyword_been_searched(keyword, 1)
    else:
        proposal = Proposal.objects.filter(query).order_by('-sitting__date')
    return render(request,'legislator/proposer_detail.html', {'keyword_obj':keyword_list(1),'proposal':proposal,'ly':ly,'keyword':keyword,'proposertype':proposertype})
コード例 #17
0
def votes(request, county):
    qs = Q(sitting__county=county)
    if request.GET.get('has_tag') == 'yes':
        qs = qs & Q(uid__in=Standpoints.objects.exclude(
            vote__isnull=True).values_list('vote_id', flat=True).distinct())
    elif request.GET.get('has_tag') == 'no':
        qs = qs & ~Q(uid__in=Standpoints.objects.exclude(
            vote__isnull=True).values_list('vote_id', flat=True).distinct())
    if request.GET.get('tag'):
        vote_ids = Standpoints.objects.filter(
            county=county, title=request.GET['tag']).values_list('vote',
                                                                 flat=True)
        qs = qs & Q(uid__in=vote_ids)
    keyword = request.GET.get('keyword', '')
    if keyword:
        votes = Votes.objects.filter(qs & reduce(operator.and_, (Q(
            content__icontains=x) for x in keyword.split())))
        if votes:
            keyword_been_searched(keyword, 'votes', county)
    else:
        votes = Votes.objects.filter(qs)
    votes = votes.extra(
                     select={
                         'tags': "SELECT json_agg(row) FROM (SELECT title, pro FROM standpoints_standpoints su WHERE su.vote_id = votes_votes.uid ORDER BY su.pro DESC) row",
                     },
                 )\
                 .order_by('-date', 'vote_seq')
    votes = paginate(request, votes)
    standpoints = Standpoints.objects.filter(
        county=county,
        vote__isnull=False).values_list('title',
                                        flat=True).order_by('-pro').distinct()
    get_params = '&'.join([
        '%s=%s' % (x, request.GET[x]) for x in ['keyword', 'has_tag', 'tag']
        if request.GET.get(x)
    ])
    return render(
        request, 'votes/votes.html', {
            'county': county,
            'votes': votes,
            'hot_keyword': keyword_list('votes', county),
            'standpoints': standpoints,
            'get_params': get_params
        })
コード例 #18
0
ファイル: views.py プロジェクト: flaing/twly-voter-guide
def biller_detail(request, legislator_id):
    proposertype = False
    ly = get_legislator(legislator_id, ad=8)
    if not ly:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=ly.id, legislator_bill__priproposer=True)
    if 'proposertype' in request.GET:
        proposertype = request.GET['proposertype']
        if proposertype:
            query = Q(proposer__id=ly.id)
    bills = Bill.objects.filter(query)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = bills.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split())))
        if bills:
            keyword_been_searched(keyword, 3)
    else:
        bills = bills.filter(query)
    return render(request,'legislator/biller_detail.html', {'keyword_obj':keyword_list(3),'bills':bills,'ly':ly,'keyword':keyword,'proposertype':proposertype})
コード例 #19
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def bills(request, keyword_url, index):
    keyword, query = None, Q()
    if 'keyword' in request.GET:
        keyword = re.sub(u'[,。/\、;][=-<>?:"{}|+_()!@#%$︿&*~~`!@#$%^&*_+-=,./<>?;:\'\"\[\]{}\|()]',' ',request.GET['keyword']).strip()
    elif keyword_url:
        keyword = keyword_url.strip()
    if keyword:
        bills = Bill.objects.filter(reduce(operator.or_, (Q(abstract__icontains=x) for x in keyword.split())))
        query = Q(reduce(operator.or_, (Q(abstract__icontains=x) for x in keyword.split())))
        if bills:
            keyword_obj = Keyword.objects.filter(category=3,content=keyword.strip())
            if keyword_obj:
                keyword_obj.update(hits=F('hits')+1)
            else:
                k = Keyword(content=keyword.strip(),category=3,valid=True,hits=1)
                k.save()
    if index == 'normal':
        bills = Bill.objects.filter(query, last_action__isnull=False, abstract__isnull=False).order_by('-last_action_at')[:100]
    elif index == 'rejected':
        bills = Bill.objects.filter(query & Q(ttsmotions__progress='退回程序')).annotate(totalNum=Count('ttsmotions__id')).order_by('-totalNum')
    return render(request,'bill/bills.html', {'index':index, 'keyword_obj':keyword_list(3), 'keyword':keyword, 'bills':bills})
コード例 #20
0
def bills_category(request, county, index, category):
    query = Q(county=county, category=category)
    keyword = keyword_normalize(request.GET)
    district = request.GET.get('district', None)

    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(
            abstract__icontains=x) for x in split_unicode_chrs(keyword))))
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query)

    if district and district != 'all':
        all_councilor_id_in_district = list(
            set([
                i.id for i in CouncilorsDetail.objects.filter(
                    county=county).filter(district__contains=district)
            ]))
        bills = bills.filter(proposer__in=all_councilor_id_in_district)

    bills = bills.order_by('-uid')

    district_list = list(
        set([
            i.district for i in CouncilorsDetail.objects.filter(
                county=county).filter(~Q(district=''))
        ]))
    return render(
        request, 'bills/bills.html', {
            'category': category,
            'county': county,
            'index': index,
            'keyword_hot': keyword_list('bills'),
            'keyword': keyword,
            'bills': bills,
            'district_list': district_list
        })
コード例 #21
0
ファイル: views.py プロジェクト: HMW/twly-voter-guide
def biller_detail(request, legislator_id, ad):
    qs = Q(content=request.GET["keyword"]) if request.GET.get("keyword") else Q()
    bills_id = [x.uid for x in SearchQuerySet().filter(qs).models(Bill).order_by("-uid")]
    ly = get_object_or_404(LegislatorDetail.objects, ad=ad, legislator_id=legislator_id)
    if len(qs):
        bills = ly.bills.select_related("bill").filter(legislator_id=ly.id, role="sponsor", bill_id__in=bills_id)
    else:
        bills = ly.bills.select_related("bill").filter(legislator_id=ly.id, role="sponsor")
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    get_params = "&".join(["%s=%s" % (x, request.GET[x]) for x in ["keyword"] if request.GET.get(x)])
    return render(
        request,
        "legislator/biller_detail.html",
        {
            "keyword_obj": keywords,
            "hot_keyword": keywords[:5],
            "bills": bills,
            "ly": ly,
            "keyword": request.GET.get("keyword", ""),
            "get_params": get_params,
        },
    )
コード例 #22
0
ファイル: views.py プロジェクト: echelon-tw/twly-voter-guide
def bills(request):
    if request.GET.get('keyword'):
        bills_uid = [
            x.uid for x in SearchQuerySet().filter(
                content=request.GET['keyword']).models(Bill)
        ]
        bills = Bill.objects.filter(
            uid__in=bills_uid).prefetch_related('laws').order_by('-uid')
    else:
        bills = Bill.objects.all().prefetch_related('laws').order_by('-uid')
    bills = paginate(request, bills)
    keywords = keyword_list(3)
    get_params = '&'.join([
        '%s=%s' % (x, request.GET[x]) for x in ['keyword']
        if request.GET.get(x)
    ])
    return render(
        request, 'bill/bills.html', {
            'bills': bills,
            'keyword_obj': keywords,
            'hot_keyword': keywords[:5],
            'keyword': request.GET.get('keyword', ''),
            'get_params': get_params
        })
コード例 #23
0
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year, councilor_id=councilor_id)
    except Exception, e:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=councilor.id, councilors_bills__petition=False)
    primaryonly = request.GET.get('primaryonly', False)
    if primaryonly:
        query = query & Q(councilors_bills__priproposer=True)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    return render(request, 'councilors/biller.html', {'keyword_hot': keyword_list('bills'), 'county': councilor.county, 'bills': bills, 'councilor': councilor, 'keyword': keyword, 'primaryonly': primaryonly})

def voter(request, councilor_id, election_year):
    votes, notvote, query = None, False, Q()
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year, councilor_id=councilor_id)
    except Exception, e:
        return HttpResponseRedirect('/')
    #--> 依投票類型分類
    decision_query = {"agree": Q(decision=1), "disagree": Q(decision=-1), "abstain": Q(decision=0), "notvote": Q(decision__isnull=True)}
    if 'decision' in request.GET:
        decision = request.GET['decision']
        if decision_query.get(decision):
            query = decision_query.get(decision)
    #<--
    # 脫黨投票
コード例 #24
0
ファイル: views.py プロジェクト: FallwinDs/twly-voter-guide
def votes(request, keyword_url, index='normal'):
    if index == 'conscience':
        query = Q(conflict=True)
    else:
        query = Q()
    keyword = keyword_normalize(request, keyword_url)
    if keyword:
        votes = Vote.objects.filter(query & reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-sitting__date', 'vote_seq')
        if votes:
            keyword_been_searched(keyword, 2)
    else:
        votes = Vote.objects.filter(query).order_by('-sitting__date', 'vote_seq')
    return render(request,'vote/votes.html', {'votes': votes, 'index':index, 'keyword':keyword, 'keyword_obj':keyword_list(2)})
コード例 #25
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def proposals(request,keyword_url):
    keyword,proposal,error = None,None,False
    if 'keyword' in request.GET:
        keyword = re.sub(u'[,。/\、;][=-<>?:"{}|+_()!@#%$︿&*~~`!@#$%^&*_+-=,./<>?;:\'\"\[\]{}\|()]',' ',request.GET['keyword']).strip()
    elif keyword_url:
        keyword = keyword_url.strip()
    if keyword:
        proposal = Proposal.objects.filter(reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-sitting__date')
        if proposal:
            keyword_obj = Keyword.objects.filter(category=1, content=keyword)
            if keyword_obj:
                keyword_obj.update(hits=F('hits')+1)
            elif not keyword_url:
                k = Keyword(content=keyword, category=1, valid=True, hits=1)
                k.save()
    else:
        proposal = Proposal.objects.all().order_by('-sitting__date')[:100]
    return render(request,'proposal/proposals.html', {'proposal':proposal,'keyword':keyword,'error':error,'keyword_obj':keyword_list(1)})
コード例 #26
0
ファイル: views.py プロジェクト: inno-v/councilor-voter-guide
def votes(request, election_year, county, index='normal'):
    result = None
    if index == 'conscience':
        query = Q(conflict=True)
    else:
        query = Q()
    #--> 依表決結果分類
    if 'result' in request.GET:
        result = request.GET['result']
        query = query & Q(result=result)
    #<--
    keyword = keyword_normalize(request.GET)
    if keyword:
        votes = Votes.objects.filter(query & reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-date', 'vote_seq')
        if votes:
            keyword_been_searched(keyword, 'votes')
    else:
        votes = Votes.objects.filter(query).order_by('-date', 'vote_seq')
    return render(request,'votes/votes.html', {'election_year': election_year, 'county': county, 'votes': votes, 'index':index, 'keyword':keyword, 'result':result, 'keyword_hot': keyword_list('votes')})
コード例 #27
0
    keyword = request.GET.get('keyword', '')
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(
            abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills', councilor.county)
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    bills = paginate(request, bills)
    get_params = '&'.join([
        '%s=%s' % (x, request.GET[x]) for x in ['keyword', 'primaryonly']
        if request.GET.get(x)
    ])
    return render(
        request, 'councilors/biller.html', {
            'keyword_hot': keyword_list('bills', councilor.county),
            'county': councilor.county,
            'bills': bills,
            'councilor': councilor,
            'primaryonly': primaryonly,
            'category': None,
            'index': 'councilor',
            'get_params': get_params
        })


def biller_sp(request, councilor_id, election_year):
    councilor = get_object_or_404(CouncilorsDetail.objects,
                                  election_year=election_year,
                                  councilor_id=councilor_id)
    terms_id = tuple(
コード例 #28
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def bills_related_to_issue(request,issue_id):
    keyword, bills = None, None
    keyword = Issue.objects.values_list('title', flat=True).get(pk=issue_id)
    if issue_id:
        bills = Bill.objects.filter(issue_bill__issue_id=issue_id).order_by('date','-pk')
    return render(request,'bill/bills.html', {'keyword':keyword,'bills':bills,'keyword_obj':keyword_list(3)})
コード例 #29
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def votes(request,keyword_url,index='normal'):
    keyword = None
    if index == 'conscience':
        query = Q(conflict=True)
    else:
        query = Q()
    if 'keyword' in request.GET:
        keyword = re.sub(u'[,。/\、;][=-<>?:"{}|+_()!@#%$︿&*~~`!@#$%^&*_+-=,./<>?;:\'\"\[\]{}\|()]',' ',request.GET['keyword']).strip()
    elif keyword_url:
        keyword = keyword_url.strip()
    if keyword:
        votes = Vote.objects.filter(query & reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-sitting__date','-pk')
        if votes:
            keyword_obj = Keyword.objects.filter(category=2,content=keyword)
            if keyword_obj:
                keyword_obj.update(hits=F('hits')+1)
            elif not keyword_url:
                k = Keyword(content=keyword,category=2,valid=True,hits=1)
                k.save()
    else:
        votes = Vote.objects.filter(query).order_by('-uid')
    return render(request,'vote/votes.html', {'votes': votes,'index':index,'keyword':keyword,'keyword_obj':keyword_list(2)})
コード例 #30
0
ファイル: views.py プロジェクト: inno-v/councilor-voter-guide
    except Exception, e:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=councilor.id)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(
            abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    data = bills.values('category').annotate(
        totalNum=Count('id')).order_by('-totalNum')
    return render(
        request, 'councilors/biller.html', {
            'keyword_hot': keyword_list('bills'),
            'bills': bills,
            'councilor': councilor,
            'keyword': keyword,
            'proposertype': proposertype,
            'data': list(data)
        })


def voter(request, councilor_id, election_year):
    votes, notvote, query = None, False, Q()
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year,
                                                 councilor_id=councilor_id)
    except Exception, e:
        return HttpResponseRedirect('/')
コード例 #31
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def proposals_related_to_issue(request,issue_id):
    keyword, proposal = None, None
    keyword = Issue.objects.values_list('title', flat=True).get(pk=issue_id)
    if issue_id:
        proposal = Proposal.objects.filter(issue_proposal__issue_id=issue_id).order_by('date','-pk')
    return render(request,'proposal/proposals.html', {'keyword':keyword,'proposal':proposal,'keyword_obj':keyword_list(1)})
コード例 #32
0
ファイル: views.py プロジェクト: inno-v/councilor-voter-guide
    query = Q(proposer__id=councilor.id)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(
            query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split()))
        ).order_by("-uid")
        if bills:
            keyword_been_searched(keyword, "bills")
    else:
        bills = Bills.objects.filter(query).order_by("-uid")
    data = bills.values("category").annotate(totalNum=Count("id")).order_by("-totalNum")
    return render(
        request,
        "councilors/biller.html",
        {
            "keyword_hot": keyword_list("bills"),
            "bills": bills,
            "councilor": councilor,
            "keyword": keyword,
            "proposertype": proposertype,
            "data": list(data),
        },
    )


def voter(request, councilor_id, election_year):
    votes, notvote, query = None, False, Q()
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year, councilor_id=councilor_id)
    except Exception, e:
        return HttpResponseRedirect("/")
コード例 #33
0
ファイル: views.py プロジェクト: FallwinDs/twly-voter-guide
def proposals(request,keyword_url):
    keyword = keyword_normalize(request, keyword_url)
    if keyword:
        proposal = Proposal.objects.filter(reduce(operator.and_, (Q(content__icontains=x) for x in keyword.split()))).order_by('-sitting__date')
        if proposal:
            keyword_been_searched(keyword, 1)
    else:
        proposal = Proposal.objects.all().order_by('-sitting__date')[:100]
    return render(request,'proposal/proposals.html', {'proposal':proposal, 'keyword':keyword, 'keyword_obj':keyword_list(1)})
コード例 #34
0
    except Exception, e:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=councilor.id, councilors_bills__petition=False)
    primaryonly = request.GET.get('primaryonly', False)
    if primaryonly:
        query = query & Q(councilors_bills__priproposer=True)
    keyword = request.GET.get('keyword', '')
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills', councilor.county)
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    bills = paginate(request, bills)
    get_params = '&'.join(['%s=%s' % (x, request.GET[x]) for x in ['keyword', 'primaryonly'] if request.GET.get(x)])
    return render(request, 'councilors/biller.html', {'keyword_hot': keyword_list('bills', councilor.county), 'county': councilor.county, 'bills': bills, 'councilor': councilor, 'primaryonly': primaryonly, 'category':None, 'index':'councilor', 'get_params': get_params, 'id': 'politics'})

def biller_sp(request, councilor_id, election_year):
    councilor = get_object_or_404(CouncilorsDetail.objects, election_year=election_year, councilor_id=councilor_id)
    terms_id = tuple(CouncilorsDetail.objects.filter(election_year__lte=election_year, councilor_id=councilor_id).values_list('id', flat=True))
    c = connections['default'].cursor()
    c.execute(u'''
        SELECT json_agg(row)
        FROM (
            SELECT
                CASE
                    WHEN priproposer = true AND petition = false THEN '主提案'
                    WHEN petition = false THEN '共同提案'
                    WHEN petition = true THEN '連署'
                END as role,
                s.title,
コード例 #35
0
ファイル: views.py プロジェクト: Swind/councilor-voter-guide
def bills(request, county, index):
    query = Q(county=county)
    keyword = keyword_normalize(request.GET)
    district = request.GET.get('district', None)


    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split())))
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query)

    if district and district != 'all':
        all_councilor_id_in_district = list(set([i.councilor.id for i in CouncilorsDetail.objects.filter(county=county).filter(district=district)]))
        bills = bills.filter(proposer__in=all_councilor_id_in_district)


    bills = bills.order_by('-uid')

    district_list = list(set([i.district for i in CouncilorsDetail.objects.filter(county=county).filter(~Q(district=''))]))
    return render(request, 'bills/bills.html', {'county': county, 'index': index, 'keyword_hot': keyword_list('bills'), 'keyword': keyword, 'bills': bills, 'district_list': district_list})
コード例 #36
0
ファイル: views.py プロジェクト: dehao/twly-voter-guide
def votes_related_to_issue(request,issue_id):
    keyword, votes, index = None, None, 'normal'
    keyword = Issue.objects.values_list('title', flat=True).get(pk=issue_id)
    if issue_id:
        votes = Vote.objects.filter(issue_vote__issue_id=issue_id).order_by('date','-pk')
    date_list = votes.values('date').distinct().order_by('-date')
    return render(request,'vote/votes.html', {'votes': votes,'index':index,'keyword':keyword,'keyword_obj':keyword_list(2),'date_list':date_list})
コード例 #37
0
        bills = Bills.objects.filter(query)
    bills = bills.extra(
                     select={
                         'tags': "SELECT json_agg(row) FROM (SELECT title, pro FROM standpoints_standpoints su WHERE su.bill_id = bills_bills.uid ORDER BY su.pro DESC) row",
                     },
                 )\
                 .order_by('-uid')
    bills = paginate(request, bills)
    get_params = '&'.join([
        '%s=%s' % (x, request.GET[x]) for x in [
            'keyword',
        ] if request.GET.get(x)
    ])
    return render(
        request, 'mayors/biller.html', {
            'keyword_hot': keyword_list('bills', mayor.county),
            'county': mayor.county,
            'bills': bills,
            'mayor': mayor,
            'get_params': get_params,
            'id': 'politics'
        })


def pc(request, mayor_id):
    try:
        mayor = Terms.objects.filter(
            mayor_id=mayor_id).order_by('-election_year')[0]
    except Exception, e:
        return HttpResponseRedirect('/')
    candidate = Candidates_Terms.objects.filter(
コード例 #38
0
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year, councilor_id=councilor_id)
    except Exception, e:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=councilor.id, councilors_bills__petition=False)
    primaryonly = request.GET.get('primaryonly', False)
    if primaryonly:
        query = query & Q(councilors_bills__priproposer=True)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    return render(request, 'councilors/biller.html', {'keyword_hot': keyword_list('bills'), 'county': councilor.county, 'bills': bills, 'councilor': councilor, 'keyword': keyword, 'primaryonly': primaryonly, 'category':None, 'index':'councilor'})

def biller_category(request, councilor_id, election_year, category):
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year, councilor_id=councilor_id)
    except Exception, e:
        return HttpResponseRedirect('/')
    query = Q(proposer__id=councilor.id, councilors_bills__petition=False, category=category)
    primaryonly = request.GET.get('primaryonly', False)
    if primaryonly:
        query = query & Q(councilors_bills__priproposer=True)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills')
コード例 #39
0
ファイル: views.py プロジェクト: inno-v/councilor-voter-guide
def bills(request, county, index):
    query = Q(county=county)
    keyword = keyword_normalize(request.GET)
    if keyword:
        bills = Bills.objects.filter(query & reduce(operator.and_, (Q(abstract__icontains=x) for x in keyword.split()))).order_by('-uid')
        if bills:
            keyword_been_searched(keyword, 'bills')
    else:
        bills = Bills.objects.filter(query).order_by('-uid')
    return render(request, 'bills/bills.html', {'county': county, 'index': index, 'keyword_hot': keyword_list('bills'), 'keyword': keyword, 'bills': bills})