Example #1
0
    def post(self, request, **kwargs):

        object_id = kwargs['pk']
        if not object_id:
            return HttpResponseBadRequest()

        bill = get_object_or_404(Bill, pk=object_id)
        user_input_type = request.POST.get('user_input_type')
        vote_types = ['approval vote','first vote','pre vote']
        if user_input_type in vote_types:
            i = vote_types.index(user_input_type)
            vote = Vote.objects.get(pk=request.POST.get('vote_id'))
            if i == 0:
                bill.approval_vote = vote
            elif i == 1:
                bill.first_vote = vote
            elif i == 2:
                bill.pre_votes.add(vote)
            else:
                #FIXME: maybe different response.
                return HttpResponseRedirect(".")
            bill.update_stage()
            action.send(request.user, verb='added-vote-to-bill',
                    description=vote,
                    target=bill,
                    timestamp=datetime.datetime.now())
        elif user_input_type == 'budget_est':
            try:
                budget_est = BillBudgetEstimation.objects.get(bill=bill,estimator=request.user)
            except BillBudgetEstimation.DoesNotExist:
                budget_est = BillBudgetEstimation(bill=bill,estimator=request.user)
            #FIXME: breakage! sanitize!
            form = BudgetEstimateForm(bill,request.user,request.POST)
            if form.is_valid():
                budget_est.one_time_gov = form.cleaned_data['be_one_time_gov']
                budget_est.yearly_gov = form.cleaned_data['be_yearly_gov']
                budget_est.one_time_ext = form.cleaned_data['be_one_time_ext']
                budget_est.yearly_ext = form.cleaned_data['be_yearly_ext']
                budget_est.summary = form.cleaned_data['be_summary']
                budget_est.save()
            else:
                return self.get(request,budget_ests_form=form)
            #botg = request.POST.get('be_one_time_gov')
            #byg = request.POST.get('be_yearly_gov')
            #bote = request.POST.get('be_one_time_ext')
            #bye = request.POST.get('be_yearly_ext')
            #bs = request.POST.get('be_summary')
            #budget_est.one_time_gov = int(botg) if botg != "" else None
            #budget_est.yearly_gov = int(byg) if byg != "" else None
            #budget_est.one_time_ext = int(bote) if bote != "" else None
            #budget_est.yearly_ext = int(bye) if bye != "" else None
            #budget_est.summary = bs if bs != "" else None
        else:
            return HttpResponseBadRequest()

        return HttpResponseRedirect(".")
Example #2
0
    def post(self, request, **kwargs):

        object_id = kwargs['pk']
        if not object_id:
            return HttpResponseBadRequest()

        bill = get_object_or_404(Bill, pk=object_id)
        user_input_type = request.POST.get('user_input_type')
        vote_types = ['approval vote', 'first vote', 'pre vote']
        if user_input_type in vote_types:
            i = vote_types.index(user_input_type)
            vote = Vote.objects.get(pk=request.POST.get('vote_id'))
            if i == 0:
                bill.approval_vote = vote
            elif i == 1:
                bill.first_vote = vote
            elif i == 2:
                bill.pre_votes.add(vote)
            else:
                #FIXME: maybe different response.
                return HttpResponseRedirect(".")
            bill.update_stage()
            action.send(request.user,
                        verb='added-vote-to-bill',
                        description=vote,
                        target=bill,
                        timestamp=datetime.datetime.now())
        elif user_input_type == 'budget_est':
            try:
                budget_est = BillBudgetEstimation.objects.get(
                    bill=bill, estimator=request.user)
            except BillBudgetEstimation.DoesNotExist:
                budget_est = BillBudgetEstimation(bill=bill,
                                                  estimator=request.user)
            #FIXME: breakage! sanitize!
            form = BudgetEstimateForm(bill, request.user, request.POST)
            if form.is_valid():
                budget_est.one_time_gov = form.cleaned_data['be_one_time_gov']
                budget_est.yearly_gov = form.cleaned_data['be_yearly_gov']
                budget_est.one_time_ext = form.cleaned_data['be_one_time_ext']
                budget_est.yearly_ext = form.cleaned_data['be_yearly_ext']
                budget_est.summary = form.cleaned_data['be_summary']
                budget_est.save()
            else:
                return self.get(request, budget_ests_form=form)
            #botg = request.POST.get('be_one_time_gov')
            #byg = request.POST.get('be_yearly_gov')
            #bote = request.POST.get('be_one_time_ext')
            #bye = request.POST.get('be_yearly_ext')
            #bs = request.POST.get('be_summary')
            #budget_est.one_time_gov = int(botg) if botg != "" else None
            #budget_est.yearly_gov = int(byg) if byg != "" else None
            #budget_est.one_time_ext = int(bote) if bote != "" else None
            #budget_est.yearly_ext = int(bye) if bye != "" else None
            #budget_est.summary = bs if bs != "" else None
        elif user_input_type == 'change_bill_name':
            if request.user.has_perm(
                    'laws.change_bill') and 'bill_name' in request.POST.keys():
                new_title = request.POST.get('bill_name')
                new_popular_name = request.POST.get('popular_name')
                logger.info(
                    'user %d is updating bill %s. new_title=%s, new_popular_name=%s'
                    %
                    (request.user.id, object_id, new_title, new_popular_name))
                Bill.objects.filter(pk=object_id).update(
                    title=new_title,
                    full_title=new_title,
                    popular_name=new_popular_name)
            else:
                return HttpResponseForbidden()
        else:
            return HttpResponseBadRequest()

        return HttpResponseRedirect(".")
Example #3
0
    def post(self, request, **kwargs):

        object_id = kwargs['pk']
        if not object_id:
            return HttpResponseBadRequest()

        bill = get_object_or_404(Bill, pk=object_id)
        user_input_type = request.POST.get('user_input_type')
        vote_types = ['approval vote', 'first vote', 'pre vote']
        if user_input_type in vote_types:
            i = vote_types.index(user_input_type)
            vote = Vote.objects.get(pk=request.POST.get('vote_id'))
            if i == 0:
                bill.approval_vote = vote
            elif i == 1:
                bill.first_vote = vote
            elif i == 2:
                bill.pre_votes.add(vote)
            else:
                # FIXME: maybe different response.
                return HttpResponseRedirect(".")
            bill.update_stage()
            action.send(request.user, verb='added-vote-to-bill',
                        description=vote,
                        target=bill,
                        timestamp=datetime.datetime.now())
        elif user_input_type == 'budget_est':
            try:
                budget_est = BillBudgetEstimation.objects.get(bill=bill, estimator=request.user)
            except BillBudgetEstimation.DoesNotExist:
                budget_est = BillBudgetEstimation(bill=bill, estimator=request.user)
            # FIXME: breakage! sanitize!
            form = BudgetEstimateForm(bill, request.user, request.POST)
            if form.is_valid():
                budget_est.one_time_gov = form.cleaned_data['be_one_time_gov']
                budget_est.yearly_gov = form.cleaned_data['be_yearly_gov']
                budget_est.one_time_ext = form.cleaned_data['be_one_time_ext']
                budget_est.yearly_ext = form.cleaned_data['be_yearly_ext']
                budget_est.summary = form.cleaned_data['be_summary']
                budget_est.save()
            else:
                return self.get(request, budget_ests_form=form)
                # botg = request.POST.get('be_one_time_gov')
                # byg = request.POST.get('be_yearly_gov')
                # bote = request.POST.get('be_one_time_ext')
                # bye = request.POST.get('be_yearly_ext')
                # bs = request.POST.get('be_summary')
                # budget_est.one_time_gov = int(botg) if botg != "" else None
                # budget_est.yearly_gov = int(byg) if byg != "" else None
                # budget_est.one_time_ext = int(bote) if bote != "" else None
                # budget_est.yearly_ext = int(bye) if bye != "" else None
                # budget_est.summary = bs if bs != "" else None
        elif user_input_type == 'change_bill_name':
            if request.user.has_perm('laws.change_bill') and 'bill_name' in request.POST.keys():
                new_title = request.POST.get('bill_name')
                new_popular_name = request.POST.get('popular_name')
                logger.info('user %d is updating bill %s. new_title=%s, new_popular_name=%s' %
                            (request.user.id, object_id, new_title,
                             new_popular_name))
                Bill.objects.filter(pk=object_id).update(title=new_title, full_title=new_title,
                                                         popular_name=new_popular_name)
            else:
                return HttpResponseForbidden()
        elif user_input_type == 'knesset_proposal':
            kp = KnessetProposal.objects.get(pk=request.POST.get('kp_id'))
            if not kp.bill:  # kp already has a bill
                kp.bill = bill
                kp.save()
        else:
            return HttpResponseBadRequest()

        return HttpResponseRedirect(".")
Example #4
0
    def post(self, request, **kwargs):

        object_id = kwargs['pk']
        if not object_id:
            return HttpResponseBadRequest()

        bill = get_object_or_404(Bill, pk=object_id)
        user_input_type = request.POST.get('user_input_type')
        vote_types = ['approval vote', 'first vote', 'pre vote']
        if user_input_type in vote_types:
            i = vote_types.index(user_input_type)
            vote = Vote.objects.get(pk=request.POST.get('vote_id'))
            if i == 0:
                try:
                    vote_bill_approved = vote.bill_approved
                except ObjectDoesNotExist:
                    vote_bill_approved = None
                if vote_bill_approved and vote_bill_approved.pk != bill.pk:
                    return self.render_post_error(
                        request,
                        bill,
                        _('Vote already linked to another bill'),
                        vote=vote,
                        other_bill=vote_bill_approved)
                bill.approval_vote = vote
            elif i == 1:
                bill.first_vote = vote
            elif i == 2:
                bill.pre_votes.add(vote)
            else:
                return self.render_post_error(request,
                                              bill,
                                              _('Invalid vote type'),
                                              vote=vote)
            bill.update_stage()
            action.send(request.user,
                        verb='added-vote-to-bill',
                        description=vote,
                        target=bill,
                        timestamp=datetime.datetime.now())
        elif user_input_type == 'budget_est':
            try:
                budget_est = BillBudgetEstimation.objects.get(
                    bill=bill, estimator=request.user)
            except BillBudgetEstimation.DoesNotExist:
                budget_est = BillBudgetEstimation(bill=bill,
                                                  estimator=request.user)
            # FIXME: breakage! sanitize!
            form = BudgetEstimateForm(bill, request.user, request.POST)
            if form.is_valid():
                budget_est.one_time_gov = form.cleaned_data['be_one_time_gov']
                budget_est.yearly_gov = form.cleaned_data['be_yearly_gov']
                budget_est.one_time_ext = form.cleaned_data['be_one_time_ext']
                budget_est.yearly_ext = form.cleaned_data['be_yearly_ext']
                budget_est.summary = form.cleaned_data['be_summary']
                budget_est.save()
            else:
                return self.get(request, budget_ests_form=form)
                # botg = request.POST.get('be_one_time_gov')
                # byg = request.POST.get('be_yearly_gov')
                # bote = request.POST.get('be_one_time_ext')
                # bye = request.POST.get('be_yearly_ext')
                # bs = request.POST.get('be_summary')
                # budget_est.one_time_gov = int(botg) if botg != "" else None
                # budget_est.yearly_gov = int(byg) if byg != "" else None
                # budget_est.one_time_ext = int(bote) if bote != "" else None
                # budget_est.yearly_ext = int(bye) if bye != "" else None
                # budget_est.summary = bs if bs != "" else None
        elif user_input_type == 'change_bill_name':
            if request.user.has_perm(
                    'laws.change_bill') and 'bill_name' in request.POST.keys():
                new_title = request.POST.get('bill_name')
                new_popular_name = request.POST.get('popular_name')
                logger.info(
                    'user %d is updating bill %s. new_title=%s, new_popular_name=%s'
                    %
                    (request.user.id, object_id, new_title, new_popular_name))
                Bill.objects.filter(pk=object_id).update(
                    title=new_title,
                    full_title=new_title,
                    popular_name=new_popular_name)
            else:
                return HttpResponseForbidden()
        elif user_input_type == 'knesset_proposal':
            kp = KnessetProposal.objects.get(pk=request.POST.get('kp_id'))
            if kp.bill:
                return self.render_post_error(
                    request,
                    bill,
                    _('The selected Knesset proposal is already linked to another bill'
                      ),
                    knesset_proposal=kp,
                    other_bill=kp.bill)
            else:
                kp.bill = bill
                kp.save()
        elif user_input_type == 'committee_meetings':
            cm = CommitteeMeeting.objects.get(pk=request.POST.get('cm_id'))
            if request.POST.get('cm_stage') == "2":
                bill.second_committee_meetings.add(cm)
            else:
                bill.first_committee_meetings.add(cm)
        else:
            return HttpResponseBadRequest()

        return HttpResponseRedirect(".")
Example #5
0
    def post(self, request, **kwargs):

        object_id = kwargs["pk"]
        if not object_id:
            return HttpResponseBadRequest()

        bill = get_object_or_404(Bill, pk=object_id)
        user_input_type = request.POST.get("user_input_type")
        vote_types = ["approval vote", "first vote", "pre vote"]
        if user_input_type in vote_types:
            i = vote_types.index(user_input_type)
            vote = Vote.objects.get(pk=request.POST.get("vote_id"))
            if i == 0:
                bill.approval_vote = vote
            elif i == 1:
                bill.first_vote = vote
            elif i == 2:
                bill.pre_votes.add(vote)
            else:
                # FIXME: maybe different response.
                return HttpResponseRedirect(".")
            bill.update_stage()
            action.send(
                request.user,
                verb="added-vote-to-bill",
                description=vote,
                target=bill,
                timestamp=datetime.datetime.now(),
            )
        elif user_input_type == "budget_est":
            try:
                budget_est = BillBudgetEstimation.objects.get(bill=bill, estimator=request.user)
            except BillBudgetEstimation.DoesNotExist:
                budget_est = BillBudgetEstimation(bill=bill, estimator=request.user)
            # FIXME: breakage! sanitize!
            form = BudgetEstimateForm(bill, request.user, request.POST)
            if form.is_valid():
                budget_est.one_time_gov = form.cleaned_data["be_one_time_gov"]
                budget_est.yearly_gov = form.cleaned_data["be_yearly_gov"]
                budget_est.one_time_ext = form.cleaned_data["be_one_time_ext"]
                budget_est.yearly_ext = form.cleaned_data["be_yearly_ext"]
                budget_est.summary = form.cleaned_data["be_summary"]
                budget_est.save()
            else:
                return self.get(request, budget_ests_form=form)
            # botg = request.POST.get('be_one_time_gov')
            # byg = request.POST.get('be_yearly_gov')
            # bote = request.POST.get('be_one_time_ext')
            # bye = request.POST.get('be_yearly_ext')
            # bs = request.POST.get('be_summary')
            # budget_est.one_time_gov = int(botg) if botg != "" else None
            # budget_est.yearly_gov = int(byg) if byg != "" else None
            # budget_est.one_time_ext = int(bote) if bote != "" else None
            # budget_est.yearly_ext = int(bye) if bye != "" else None
            # budget_est.summary = bs if bs != "" else None
        elif user_input_type == "change_bill_name":
            if request.user.has_perm("laws.change_bill") and "bill_name" in request.POST.keys():
                new_title = request.POST.get("bill_name")
                new_popular_name = request.POST.get("popular_name")
                logger.info(
                    "user %d is updating bill %s. new_title=%s, new_popular_name=%s"
                    % (request.user.id, object_id, new_title, new_popular_name)
                )
                Bill.objects.filter(pk=object_id).update(
                    title=new_title, full_title=new_title, popular_name=new_popular_name
                )
            else:
                return HttpResponseForbidden()
        else:
            return HttpResponseBadRequest()

        return HttpResponseRedirect(".")