Exemple #1
0
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})
Exemple #2
0
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})
def keyword_been_searched(keyword, category):
    keyword_obj = Keyword.objects.filter(category=category, content=keyword)
    if keyword_obj:
        keyword_obj.update(hits=F('hits')+1)
    else:
        k = Keyword(content=keyword, category=category, valid=True, hits=1)
        k.save()
Exemple #4
0
def keyword_been_searched(keyword, category):
    keyword_obj = Keyword.objects.filter(category=category, content=keyword)
    if keyword_obj:
        keyword_obj.update(hits=F('hits') + 1)
    else:
        k = Keyword(content=keyword, category=category, valid=True, hits=1)
        k.save()
Exemple #5
0
	def test_save_and_retrieve_keyword(self):
		word = 'junior'
		word_1 = Keyword()
		word_1.word = word
		word_1.save()

		saved_words = Keyword.objects.all()
		self.assertEqual(saved_words.count(), 1)

		saved_word_1 = saved_words[0]

		self.assertEqual(saved_word_1.word, word)
Exemple #6
0
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)})
Exemple #7
0
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})
Exemple #8
0
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)})