<commit_before>import logging
from datetime import datetime

from pylons.i18n import _

from adhocracy.lib.base import *
from adhocracy.lib.tiles.poll_tiles import PollTile
from adhocracy.lib.tiles.proposal_tiles import ProposalTile
from adhocracy.model import Vote

log = logging.getLogger(__name__)


class PollVotesFilterForm(formencode.Schema):
    allow_extra_fields = True
    result = validators.Int(not_empty=False, if_empty=None, if_missing=None, 
                            min=model.Vote.NO, max=model.Vote.YES)
    
class PollVoteForm(formencode.Schema):
    allow_extra_fields = True
    position = validators.Int(min=model.Vote.NO, max=model.Vote.YES, not_empty=True)


class PollController(BaseController):
    
    def index(self, id, format='html'):
        return self.not_implemented(format=format)
    
        
    def new(self, id, format='html'):
        return self.not_implemented(format=format)
    
    
    def create(self, id, format='html'):
        return self.not_implemented(format=format)
    
        
    def edit(self, id, format='html'):
        return self.not_implemented(format=format)
        
    
    def update(self, id, format='html'):
        return self.not_implemented(format=format)  
    
    
    @RequireInstance
    def show(self, id, format='html'):
        poll = get_entity_or_abort(model.Poll, id)
        require.poll.show(c.poll)
        
        if format == 'json':
            return render_json(poll)
        
        return self.not_implemented(format=format)  
    
    
    @RequireInstance
    @RequireInternalRequest()
    @validate(schema=PollVoteForm(), form="bad_request", post_only=False, on_get=True)
    def vote(self, id, format='html'):
        c.poll = self._get_open_poll(id)
        if c.poll.action != model.Poll.ADOPT:
            abort(400, _("This is not an adoption poll."))
        require.poll.vote(c.poll)
        decision = democracy.Decision(c.user, c.poll)
        votes = decision.make(self.form_result.get("position"))
        
        for vote in votes:
            event.emit(event.T_VOTE_CAST, vote.user, instance=c.instance, 
                    topics=[c.poll.scope], vote=vote, poll=c.poll)
        model.meta.Session.commit()
        
        if format == 'json':
            return render_json(dict(decision=decision,
                                    score=tally.score))
        
        
        redirect(h.entity_url(c.poll.subject))
        
        
    @RequireInstance
    @RequireInternalRequest()
    @validate(schema=PollVoteForm(), form="bad_request", post_only=False, on_get=True)
    def rate(self, id, format='html'):
        # rating is like polling but steps via abstention, i.e. if you have 
        # first voted "for", rating will first go to "abstain" and only
        # then produce "against"-
        c.poll = self._get_open_poll(id)
        if c.poll.action not in [model.Poll.RATE, model.Poll.SELECT]:
            abort(400, _("This is not a rating poll."))
        require.poll.vote(c.poll)
        
        decision = democracy.Decision(c.user, c.poll)
        old = decision.result
        new = self.form_result.get("position")
        position = {(Vote.YES, Vote.YES): Vote.YES,
                    (Vote.ABSTAIN, Vote.YES): Vote.YES,
                    (Vote.NO, Vote.YES): Vote.ABSTAIN,
                    (Vote.YES, Vote.NO): Vote.ABSTAIN,
                    (Vote.ABSTAIN, Vote.NO): Vote.NO,
                    (Vote.NO, Vote.NO): Vote.NO}.get((old, new), new)
        votes = decision.make(position)
        tally = model.Tally.create_from_poll(c.poll)
        model.meta.Session.commit()
        
        if format == 'json':
            return render_json(dict(decision=decision,
                                    score=tally.score))
        
        if c.poll.action == model.Poll.SELECT:
            redirect(h.entity_url(c.poll.selection))
                
        redirect(h.entity_url(c.poll.subject))  
    
        
    @RequireInstance
    @validate(schema=PollVotesFilterForm(), post_only=False, on_get=True)
    def votes(self, id, format='html'):
        c.poll = get_entity_or_abort(model.Poll, id)
        require.poll.show(c.poll)
        decisions = democracy.Decision.for_poll(c.poll)
        if self.form_result.get('result'):
            decisions = filter(lambda d: d.result==self.form_result.get('result'), 
                               decisions)
        c.decisions_pager = pager.scope_decisions(decisions)
        
        if format == 'json':
            return render_json(c.decisions_pager)    
        
        return render("/poll/votes.html")  
        
    
    def ask_delete(self, id):
        c.poll = self._get_open_poll(id)
        require.poll.delete(c.poll)
        return render('/poll/ask_delete.html')
    
       
    def delete(self, id, format):
        c.poll = self._get_open_poll(id)
        require.poll.delete(c.poll)
        c.poll.end()<commit_msg>[svn r973] When viewing Abstain votes, Affirms and Dissents were also listed -> fixed.<commit_after>import logging
from datetime import datetime

from pylons.i18n import _

from adhocracy.lib.base import *
from adhocracy.lib.tiles.poll_tiles import PollTile
from adhocracy.lib.tiles.proposal_tiles import ProposalTile
from adhocracy.model import Vote

log = logging.getLogger(__name__)


class PollVotesFilterForm(formencode.Schema):
    allow_extra_fields = True
    result = validators.Int(not_empty=False, if_empty=None, if_missing=None, 
                            min=model.Vote.NO, max=model.Vote.YES)
    
class PollVoteForm(formencode.Schema):
    allow_extra_fields = True
    position = validators.Int(min=model.Vote.NO, max=model.Vote.YES, not_empty=True)


class PollController(BaseController):
    
    def index(self, id, format='html'):
        return self.not_implemented(format=format)
    
        
    def new(self, id, format='html'):
        return self.not_implemented(format=format)
    
    
    def create(self, id, format='html'):
        return self.not_implemented(format=format)
    
        
    def edit(self, id, format='html'):
        return self.not_implemented(format=format)
        
    
    def update(self, id, format='html'):
        return self.not_implemented(format=format)  
    
    
    @RequireInstance
    def show(self, id, format='html'):
        poll = get_entity_or_abort(model.Poll, id)
        require.poll.show(c.poll)
        
        if format == 'json':
            return render_json(poll)
        
        return self.not_implemented(format=format)  
    
    
    @RequireInstance
    @RequireInternalRequest()
    @validate(schema=PollVoteForm(), form="bad_request", post_only=False, on_get=True)
    def vote(self, id, format='html'):
        c.poll = self._get_open_poll(id)
        if c.poll.action != model.Poll.ADOPT:
            abort(400, _("This is not an adoption poll."))
        require.poll.vote(c.poll)
        decision = democracy.Decision(c.user, c.poll)
        votes = decision.make(self.form_result.get("position"))
        
        for vote in votes:
            event.emit(event.T_VOTE_CAST, vote.user, instance=c.instance, 
                    topics=[c.poll.scope], vote=vote, poll=c.poll)
        model.meta.Session.commit()
        
        if format == 'json':
            return render_json(dict(decision=decision,
                                    score=tally.score))
        
        
        redirect(h.entity_url(c.poll.subject))
        
        
    @RequireInstance
    @RequireInternalRequest()
    @validate(schema=PollVoteForm(), form="bad_request", post_only=False, on_get=True)
    def rate(self, id, format='html'):
        # rating is like polling but steps via abstention, i.e. if you have 
        # first voted "for", rating will first go to "abstain" and only
        # then produce "against"-
        c.poll = self._get_open_poll(id)
        if c.poll.action not in [model.Poll.RATE, model.Poll.SELECT]:
            abort(400, _("This is not a rating poll."))
        require.poll.vote(c.poll)
        
        decision = democracy.Decision(c.user, c.poll)
        old = decision.result
        new = self.form_result.get("position")
        position = {(Vote.YES, Vote.YES): Vote.YES,
                    (Vote.ABSTAIN, Vote.YES): Vote.YES,
                    (Vote.NO, Vote.YES): Vote.ABSTAIN,
                    (Vote.YES, Vote.NO): Vote.ABSTAIN,
                    (Vote.ABSTAIN, Vote.NO): Vote.NO,
                    (Vote.NO, Vote.NO): Vote.NO}.get((old, new), new)
        votes = decision.make(position)
        tally = model.Tally.create_from_poll(c.poll)
        model.meta.Session.commit()
        
        if format == 'json':
            return render_json(dict(decision=decision,
                                    score=tally.score))
        
        if c.poll.action == model.Poll.SELECT:
            redirect(h.entity_url(c.poll.selection))
                
        redirect(h.entity_url(c.poll.subject))  
    
        
    @RequireInstance
    @validate(schema=PollVotesFilterForm(), post_only=False, on_get=True)
    def votes(self, id, format='html'):
        c.poll = get_entity_or_abort(model.Poll, id)
        require.poll.show(c.poll)
        decisions = democracy.Decision.for_poll(c.poll)
        if self.form_result.get('result')!='':
            decisions = filter(lambda d: d.result==self.form_result.get('result'), 
                               decisions)
        c.decisions_pager = pager.scope_decisions(decisions)
        
        if format == 'json':
            return render_json(c.decisions_pager)    
        
        return render("/poll/votes.html")  
        
    
    def ask_delete(self, id):
        c.poll = self._get_open_poll(id)
        require.poll.delete(c.poll)
        return render('/poll/ask_delete.html')
    
       
    def delete(self, id, format):
        c.poll = self._get_open_poll(id)
        require.poll.delete(c.poll)
        c.poll.end()
{'fraction_non_alphanumeric': 0.11575885244257197, 'fraction_numerical': 0.0019059083157789147, 'mean_word_length': 2.1431273644388398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485606', 'n_tokens_mistral': 3168, 'n_tokens_neox': 3071, 'n_words': 571}