Exemplo n.º 1
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')
        })
Exemplo n.º 2
0
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})
Exemplo n.º 3
0
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)})
Exemplo n.º 4
0
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})
Exemplo n.º 5
0
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})
Exemplo n.º 6
0
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)})
Exemplo n.º 7
0
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})
Exemplo n.º 8
0
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
        })
Exemplo n.º 9
0
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})
Exemplo n.º 10
0
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')})
Exemplo n.º 11
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})
Exemplo n.º 12
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
        })
Exemplo n.º 13
0
                'county': county,
                'councilors': councilors,
                'out_office': out_office,
                'index': index
            })


def biller(request, councilor_id, election_year):
    proposertype = False
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year,
                                                 councilor_id=councilor_id)
    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,
Exemplo n.º 14
0
                "county": county,
                "councilors": councilors,
                "out_office": out_office,
                "index": index,
            },
        )


def biller(request, councilor_id, election_year):
    proposertype = False
    try:
        councilor = CouncilorsDetail.objects.get(election_year=election_year, councilor_id=councilor_id)
    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,