Exemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        voted_ids = json.loads(request.POST['users'])
        proposal = self.get_object()
        pid = proposal.id
        voter_group = request.user.get_default_group(self.community) \
            if request.user.is_authenticated() \
            else ''

        val = request.POST['val']

        value = self._vote_values_map(val)
        if value == None:
            return HttpResponseBadRequest('vote value not valid')

        vote_failed = []
        for user_id in voted_ids:
            vote, valid = self._do_vote(ProposalVoteBoard, proposal, user_id,
                                        value, True, voter_group)
            if valid == ProposalVoteMixin.VOTE_OVERRIDE_ERR:
                vote_failed.append({
                    'uid': user_id,
                    'val': self._vote_values_map(vote.value),
                })

        return json_response({
            'result':
            'ok',
            'html':
            render_to_string('issues/_vote_reset_panel.html', {
                'proposal': proposal,
                'community': self.community,
            }),
            'override_fail':
            vote_failed,
            'sum':
            render_to_string(
                'issues/_member_vote_sum.html', {
                    'proposal': proposal,
                    'community': self.community,
                    'board_attending': board_voters_on_proposal(proposal),
                })
        })
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        voted_ids = json.loads(request.POST['users'])
        proposal = self.get_object()
        pid = proposal.id
        voter_group = request.user.get_default_group(self.community) \
            if request.user.is_authenticated() \
            else ''

        val = request.POST['val']

        value = self._vote_values_map(val)
        if value == None:
            return HttpResponseBadRequest('vote value not valid')

        vote_failed = []
        for user_id in voted_ids:
            vote, valid = self._do_vote(ProposalVoteBoard, proposal,
                                        user_id, value, True, voter_group)
            if valid == ProposalVoteMixin.VOTE_OVERRIDE_ERR:
                vote_failed.append({'uid': user_id, 'val': self._vote_values_map(vote.value), })

        return json_response({
            'result': 'ok',
            'html': render_to_string('issues/_vote_reset_panel.html',
                                     {
                                         'proposal': proposal,
                                         'community': self.community,
                                     }),
            'override_fail': vote_failed,
            'sum': render_to_string('issues/_member_vote_sum.html',
                                    {
                                        'proposal': proposal,
                                        'community': self.community,
                                        'board_attending': board_voters_on_proposal(proposal),
                                    })
        })
Exemplo n.º 3
0
    def post(self, request, *args, **kwargs):

        is_board = request.POST.get('board', False)
        user_id = request.POST.get('user', request.user.id)
        voter_id = request.user.id
        voter_group = request.user.get_default_group(self.community) \
            if request.user.is_authenticated() \
            else ''
        val = request.POST['val']
        if is_board:
            # vote for board member by chairman or board member
            vote_class = ProposalVoteBoard
        else:
            # straw vote by member
            vote_class = ProposalVote

        proposal = self.get_object()
        pid = proposal.id
        vote_panel_tpl = 'issues/_vote_panel.html' if val == 'reset' \
            else 'issues/_vote_reset_panel.html'

        res_panel_tpl = 'issues/_board_vote_res.html' if is_board \
            else 'issues/_vote_reset_panel.html'
        vote_response = {
            'result': 'ok',
            'html': render_to_string(res_panel_tpl,
                                     {
                                         'proposal': proposal,
                                         'community': self.community,
                                         'vote_status': val,
                                     }),
        }

        value = ''
        if val == 'reset':
            vote = get_object_or_404(vote_class,
                                     proposal_id=pid, user_id=user_id)
            vote.delete()
            related_arguments = ProposalVoteArgumentRanking.objects.filter(user=request.user, argument__proposal_vote__proposal=proposal)
            if related_arguments.count():
                related_arguments.delete()
            vote_response['html'] = render_to_string(vote_panel_tpl,
                                                     {
                                                         'proposal': proposal,
                                                         'community': self.community
                                                     })

            return json_response(vote_response)
        else:
            value = self._vote_values_map(val)
        if value == None:
            return HttpResponseBadRequest('vote value not valid')

        vote, valid = self._do_vote(vote_class, proposal, user_id, value,
                                    is_board, voter_group)
        if valid == ProposalVoteMixin.VOTE_OK:
            vote_response['html'] = render_to_string(res_panel_tpl,
                                                     {
                                                         'proposal': proposal,
                                                         'community': self.community,
                                                         'vote_status': val,
                                                         'user': self.request.user
                                                     })
            if is_board and voter_group == DefaultGroups.CHAIRMAN:
                vote_response['sum'] = render_to_string('issues/_member_vote_sum.html',
                                                        {
                                                            'proposal': proposal,
                                                            'community': self.community,
                                                            'board_attending': board_voters_on_proposal(proposal),
                                                        })
        else:
            vote_response['result'] = 'err'
            if valid == ProposalVoteMixin.VOTE_OVERRIDE_ERR:
                vote_response['override_fail'] = [{'uid': user_id,
                                                   'val': self._vote_values_map(vote.value),
                                                  }]

        return json_response(vote_response)
Exemplo n.º 4
0
    def get_context_data(self, **kwargs):
        """add meeting for the latest straw voting result
           add 'previous_res' var if found previous registered results for this meeting
        """
        context = super(ProposalDetailView, self).get_context_data(**kwargs)
        m_id = self.request.GET.get('m_id', None)
        o = self.get_object()

        if m_id:
            context['meeting_context'] = get_object_or_404(Meeting, id=m_id,
                                                           community=self.community)
            participants = context['meeting_context'].participants.all()
        else:
            context['meeting_context'] = None
            participants = o.issue.community.upcoming_meeting_participants.all()

        try:
            group = self.request.user.memberships.get(community=self.issue.community).default_group_name
        except:
            group = ""

        board_votes = ProposalVoteBoard.objects.filter(proposal=o)
        board_attending = board_voters_on_proposal(o)

        is_current = o.issue.is_current
        context['res'] = o.get_straw_results()

        results = VoteResult.objects.filter(proposal=o) \
            .order_by('-meeting__held_at')

        if o.issue.is_upcoming and \
                self.community.upcoming_meeting_is_published and \
                self.community.straw_vote_ended:
            context['meeting'] = self.community.draft_meeting()
        else:
            if results.count():
                context['meeting'] = results[0].meeting
            else:
                context['meeting'] = None

        if not board_votes.exists():
            self._init_board_votes(board_attending)
        show_to_member = group == DefaultGroups.MEMBER and o.decided_at_meeting
        show_to_board = (group == DefaultGroups.BOARD or \
                         group == DefaultGroups.SECRETARY) and \
                        (is_current or o.decided_at_meeting)
        show_to_chairman = group == DefaultGroups.CHAIRMAN and o.decided
        show_board_vote_result = o.register_board_votes and \
                                 board_votes.exclude(
                                     value=ProposalVoteValue.NEUTRAL).count() and \
                                 (show_to_member or show_to_board or show_to_chairman)
        context['issue_frame'] = self.request.GET.get('s', None)
        context['board_attending'] = board_attending
        context['user_vote'] = o.board_vote_by_member(self.request.user.id)
        context['show_board_vote_result'] = show_board_vote_result
        context['chairman_can_vote'] = is_current and not o.decided
        context['board_votes'] = self.board_votes_dict()
        context['can_board_vote_self'] = is_current and not o.decided and \
                                         (group == DefaultGroups.BOARD or \
                                          group == DefaultGroups.SECRETARY) and \
                                         self.request.user in board_attending
        rel_proposals = self.object.issue.proposals
        context['proposals'] = rel_proposals.object_access_control(
            user=self.request.user, community=self.community)
        return context
Exemplo n.º 5
0
    def post(self, request, *args, **kwargs):

        is_board = request.POST.get('board', False)
        user_id = request.POST.get('user', request.user.id)
        voter_id = request.user.id
        voter_group = request.user.get_default_group(
            self.community) if request.user.is_authenticated else ''
        val = request.POST['val']
        if is_board:
            # vote for board member by chairman or board member
            vote_class = ProposalVoteBoard
        else:
            # straw vote by member
            vote_class = ProposalVote

        proposal = self.get_object()
        pid = proposal.id
        vote_panel_tpl = 'issues/_vote_panel.html' if val == 'reset' \
            else 'issues/_vote_reset_panel.html'

        res_panel_tpl = 'issues/_board_vote_res.html' if is_board \
            else 'issues/_vote_reset_panel.html'
        vote_response = {
            'result':
            'ok',
            'html':
            render_to_string(
                res_panel_tpl, {
                    'proposal': proposal,
                    'community': self.community,
                    'vote_status': val,
                }),
        }

        value = ''
        if val == 'reset':
            vote = get_object_or_404(vote_class,
                                     proposal_id=pid,
                                     user_id=user_id)
            vote.delete()
            related_arguments = ProposalVoteArgumentRanking.objects.filter(
                user=request.user, argument__proposal_vote__proposal=proposal)
            if related_arguments.count():
                related_arguments.delete()
            vote_response['html'] = render_to_string(
                vote_panel_tpl, {
                    'proposal': proposal,
                    'community': self.community
                })

            return json_response(vote_response)
        else:
            value = self._vote_values_map(val)
        if value == None:
            return HttpResponseBadRequest('vote value not valid')

        vote, valid = self._do_vote(vote_class, proposal, user_id, value,
                                    is_board, voter_group)
        if valid == ProposalVoteMixin.VOTE_OK:
            vote_response['html'] = render_to_string(
                res_panel_tpl, {
                    'proposal': proposal,
                    'community': self.community,
                    'vote_status': val,
                    'user': self.request.user
                })
            if is_board and voter_group == DefaultGroups.CHAIRMAN:
                vote_response['sum'] = render_to_string(
                    'issues/_member_vote_sum.html', {
                        'proposal': proposal,
                        'community': self.community,
                        'board_attending': board_voters_on_proposal(proposal),
                    })
        else:
            vote_response['result'] = 'err'
            if valid == ProposalVoteMixin.VOTE_OVERRIDE_ERR:
                vote_response['override_fail'] = [{
                    'uid':
                    user_id,
                    'val':
                    self._vote_values_map(vote.value),
                }]

        return json_response(vote_response)
Exemplo n.º 6
0
    def get_context_data(self, **kwargs):
        """add meeting for the latest straw voting result
           add 'previous_res' var if found previous registered results for this meeting
        """
        context = super(ProposalDetailView, self).get_context_data(**kwargs)
        m_id = self.request.GET.get('m_id', None)
        o = self.get_object()

        if m_id:
            context['meeting_context'] = get_object_or_404(
                Meeting, id=m_id, community=self.community)
            participants = context['meeting_context'].participants.all()
        else:
            context['meeting_context'] = None
            participants = o.issue.community.upcoming_meeting_participants.all(
            )

        try:
            group = self.request.user.memberships.get(
                community=self.issue.community).default_group_name
        except:
            group = ""

        board_votes = ProposalVoteBoard.objects.filter(proposal=o)
        board_attending = board_voters_on_proposal(o)

        is_current = o.issue.is_current
        context['res'] = o.get_straw_results()

        results = VoteResult.objects.filter(proposal=o) \
            .order_by('-meeting__held_at')

        if o.issue.is_upcoming and \
                self.community.upcoming_meeting_is_published and \
                self.community.straw_vote_ended:
            context['meeting'] = self.community.draft_meeting()
        else:
            if results.count():
                context['meeting'] = results[0].meeting
            else:
                context['meeting'] = None

        if not board_votes.exists():
            self._init_board_votes(board_attending)
        show_to_member = group == DefaultGroups.MEMBER and o.decided_at_meeting
        show_to_board = (group == DefaultGroups.BOARD or \
                         group == DefaultGroups.SECRETARY) and \
                        (is_current or o.decided_at_meeting)
        show_to_chairman = group == DefaultGroups.CHAIRMAN and o.decided
        show_board_vote_result = o.register_board_votes and \
                                 board_votes.exclude(
                                     value=ProposalVoteValue.NEUTRAL).count() and \
                                 (show_to_member or show_to_board or show_to_chairman)
        context['issue_frame'] = self.request.GET.get('s', None)
        context['board_attending'] = board_attending
        context['user_vote'] = o.board_vote_by_member(self.request.user.id)
        context['show_board_vote_result'] = show_board_vote_result
        context['chairman_can_vote'] = is_current and not o.decided
        context['board_votes'] = self.board_votes_dict()
        context['can_board_vote_self'] = is_current and not o.decided and \
                                         (group == DefaultGroups.BOARD or \
                                          group == DefaultGroups.SECRETARY) and \
                                         self.request.user in board_attending
        rel_proposals = self.object.issue.proposals
        context['proposals'] = rel_proposals.object_access_control(
            user=self.request.user, community=self.community)
        return context