Example #1
0
    def post(self, request, *args, **kwargs):
        object_id = kwargs['pk']
        try:
            object_id = int(kwargs['pk'])
        except:
            return HttpResponseBadRequest()
        user_input_type = request.POST.get('user_input_type', None)
        vote = get_object_or_404(Vote, pk=object_id)
        mk_names = Member.objects.values_list('name', flat=True)
        if user_input_type == 'agenda':
            try:
                agenda_id = int(request.POST.get('agenda'))
            except:
                return HttpResponseBadRequest()
            agenda = Agenda.objects.get(pk=agenda_id)
            reasoning = request.POST.get('reasoning', '')
            usv = UserSuggestedVote.objects.filter(user=request.user,
                                                   agenda=agenda,
                                                   vote=vote)
            if usv:
                usv = usv[0]
                usv.reasoning = reasoning
                usv.sent_to_editor = False
                usv.save()
            else:
                usv = UserSuggestedVote(user=request.user,
                                        agenda=agenda,
                                        vote=vote,
                                        reasoning=reasoning)
                usv.save()

        else:  # adding an MK (either for or against)
            mk_name = difflib.get_close_matches(request.POST.get('mk_name'),
                                                mk_names)[0]
            mk = Member.objects.get(name=mk_name)
            stand = None
            if user_input_type == 'mk-for':
                stand = 'for'
            if user_input_type == 'mk-against':
                stand = 'against'
            if stand:
                va = VoteAction.objects.filter(member=mk, vote=vote)
                if va:
                    va = va[0]
                    va.type = stand
                    va.save()
                else:
                    va = VoteAction(member=mk, vote=vote, type=stand)
                    va.save()
                vote.update_vote_properties()

        return HttpResponseRedirect('.')
Example #2
0
    def post(self, request, *args, **kwargs):
        object_id = kwargs['pk']
        try:
            object_id = int(kwargs['pk'])
        except:
            return HttpResponseBadRequest()
        user_input_type = request.POST.get('user_input_type',None)
        vote = get_object_or_404(Vote, pk=object_id)
        mk_names = Member.objects.values_list('name',flat=True)
        if user_input_type == 'agenda':
            try:
                agenda_id = int(request.POST.get('agenda'))
            except:
                return HttpResponseBadRequest()
            agenda = Agenda.objects.get(pk=agenda_id)
            reasoning = request.POST.get('reasoning','')
            usv = UserSuggestedVote.objects.filter(user = request.user,
                                agenda = agenda,
                                vote = vote)
            if usv:
                usv = usv[0]
                usv.reasoning = reasoning
                usv.sent_to_editor = False
                usv.save()
            else:
                usv = UserSuggestedVote(user = request.user,
                                agenda = agenda,
                                vote = vote,
                                reasoning = reasoning)
                usv.save()

        else: # adding an MK (either for or against)
            mk_name = difflib.get_close_matches(request.POST.get('mk_name'), mk_names)[0]
            mk = Member.objects.get(name=mk_name)
            stand = None
            if user_input_type == 'mk-for':
                stand = 'for'
            if user_input_type == 'mk-against':
                stand = 'against'
            if stand:
                va = VoteAction.objects.filter(member=mk, vote=vote)
                if va:
                    va = va[0]
                    va.type=stand
                    va.save()
                else:
                    va = VoteAction(member=mk, vote=vote, type=stand)
                    va.save()
                vote.update_vote_properties()

        return HttpResponseRedirect('.')
Example #3
0
    def post(self, request, *args, **kwargs):
        object_id = kwargs['pk']
        try:
            object_id = int(kwargs['pk'])
        except:
            return HttpResponseBadRequest()
        user_input_type = request.POST.get('user_input_type', None)
        vote = get_object_or_404(Vote, pk=object_id)
        mk_names = Member.objects.values_list('name', flat=True)
        if user_input_type == 'agenda':
            try:
                agenda_id = int(request.POST.get('agenda'))
            except:
                return HttpResponseBadRequest()
            agenda = Agenda.objects.get(pk=agenda_id)
            reasoning = request.POST.get('reasoning', '')
            usv = UserSuggestedVote.objects.filter(user=request.user,
                                                   agenda=agenda,
                                                   vote=vote)
            if usv:
                usv = usv[0]
                usv.reasoning = reasoning
                usv.sent_to_editor = False
                usv.save()
            else:
                usv = UserSuggestedVote(user=request.user,
                                        agenda=agenda,
                                        vote=vote,
                                        reasoning=reasoning)
                usv.save()

        elif user_input_type == 'add-bill':
            form = AttachBillFromVoteForm(vote, request.POST)

            if form.is_valid():
                vote_type = form.cleaned_data['vote_type']
                bill = form.cleaned_data['bill_model']

                if vote_type == 'approve vote':
                    bill.approval_vote = vote

                elif vote_type == 'first vote':
                    bill.first_vote = vote

                elif vote_type == 'pre vote':
                    bill.pre_votes.add(vote)

                bill.update_stage()
            else:
                return self.get(request, bill_form=form)

        else:  # adding an MK (either for or against)
            mk_name = difflib.get_close_matches(request.POST.get('mk_name'), mk_names)[0]
            mk = Member.objects.get(name=mk_name)
            stand = None
            if user_input_type == 'mk-for':
                stand = 'for'
            if user_input_type == 'mk-against':
                stand = 'against'
            if stand:
                va = VoteAction.objects.filter(member=mk, vote=vote)
                if va:
                    va = va[0]
                    va.type = stand
                    va.save()
                else:
                    va = VoteAction(member=mk, vote=vote, type=stand)
                    va.save()
                vote.update_vote_properties()

        return HttpResponseRedirect('.')
Example #4
0
    def post(self, request, *args, **kwargs):
        object_id = kwargs['pk']
        try:
            object_id = int(kwargs['pk'])
        except:
            return HttpResponseBadRequest()
        user_input_type = request.POST.get('user_input_type', None)
        vote = get_object_or_404(Vote, pk=object_id)
        mk_names = Member.objects.values_list('name', flat=True)
        if user_input_type == 'agenda':
            try:
                agenda_id = int(request.POST.get('agenda'))
            except:
                return HttpResponseBadRequest()
            agenda = Agenda.objects.get(pk=agenda_id)
            reasoning = request.POST.get('reasoning', '')
            usv = UserSuggestedVote.objects.filter(user=request.user,
                                                   agenda=agenda,
                                                   vote=vote)
            if usv:
                usv = usv[0]
                usv.reasoning = reasoning
                usv.sent_to_editor = False
                usv.save()
            else:
                usv = UserSuggestedVote(user=request.user,
                                        agenda=agenda,
                                        vote=vote,
                                        reasoning=reasoning)
                usv.save()

        elif user_input_type == 'add-bill':
            form = AttachBillFromVoteForm(vote, request.POST)

            if form.is_valid():
                vote_type = form.cleaned_data['vote_type']
                bill = form.cleaned_data['bill_model']

                if vote_type == 'approve vote':
                    bill.approval_vote = vote

                elif vote_type == 'first vote':
                    bill.first_vote = vote

                elif vote_type == 'pre vote':
                    bill.pre_votes.add(vote)

                bill.update_stage()
            else:
                return self.get(request, bill_form=form)

        else:  # adding an MK (either for or against)
            mk_name = \
                difflib.get_close_matches(request.POST.get('mk_name'),
                                          mk_names)[0]
            mk = Member.objects.get(name=mk_name)
            stand = None
            if user_input_type == 'mk-for':
                stand = 'for'
            if user_input_type == 'mk-against':
                stand = 'against'
            if stand:
                va = VoteAction.objects.filter(member=mk, vote=vote)
                if va:
                    va = va[0]
                    va.type = stand
                    va.save()
                else:
                    va = VoteAction(member=mk, vote=vote, type=stand)
                    va.save()
                vote.update_vote_properties()

        return HttpResponseRedirect('.')