Exemple #1
0
def update_editors_agendas(request):
    if request.method == 'POST':
        vl_formset = VoteLinkingFormSet(request.POST)
        if vl_formset.is_valid():
            # TODO: check the user's permission
            for a in vl_formset.cleaned_data:
                try:
                    av = AgendaVote.objects.get(
                           agenda__id=a['agenda_id'],
                           vote__id = a['vote_id'])
                    av.score = a['weight']
                    av.reasoning = a['reasoning']
                    av.save()
                except AgendaVote.DoesNotExist:
                    av = AgendaVote(
                           agenda_id=int(a['agenda_id']),
                           vote_id=int(a['vote_id']),
                           score = a['weight'],
                           reasoning = a['reasoning'])
                    av.save()
            return HttpResponseRedirect(reverse('vote-detail', kwargs={'object_id':a['vote_id']}))
        else:
            # TODO: Error handling: what to do with illeal forms?
            pass

    else:
        return HttpResponseNotAllowed(['POST'])
Exemple #2
0
def update_editors_agendas(request):
    if request.method == 'POST':
        vote_id = None
        vl_formset = VoteLinkingFormSet(request.POST)
        if vl_formset.is_valid():
            # TODO: check the user's permission
            for a in vl_formset.cleaned_data:
                if a:
                    if a['DELETE']:
                        try:
                            vote_id = a['vote_id']
                            av = AgendaVote.objects.get(
                                agenda__id=a['agenda_id'],
                                vote__id=a['vote_id'])
                            av.delete()
                        except AgendaVote.DoesNotExist:
                            pass
                    else:  # not delete, so try to create
                        try:
                            vote_id = a['vote_id']
                            print "vote id = %s" % vote_id
                            av = AgendaVote.objects.get(
                                agenda__id=a['agenda_id'],
                                vote__id=a['vote_id'])
                            av.score = a['weight']
                            av.reasoning = a['reasoning']
                            av.save()
                        except AgendaVote.DoesNotExist:
                            av = AgendaVote(agenda_id=int(a['agenda_id']),
                                            vote_id=int(a['vote_id']),
                                            score=a['weight'],
                                            reasoning=a['reasoning'])
                            av.save()
                else:
                    print "invalid form"
            if vote_id:
                return HttpResponseRedirect(
                    reverse('vote-detail', kwargs={'object_id': vote_id}))
            else:
                return HttpResponseRedirect(reverse('vote-list'))

        else:
            # TODO: Error handling: what to do with illeal forms?
            print "invalid formset"
            return HttpResponseRedirect(reverse('vote-list'))

    else:
        return HttpResponseNotAllowed(['POST'])
Exemple #3
0
def update_editors_agendas(request):
    if request.method == 'POST':
        vote_id = None
        vl_formset = VoteLinkingFormSet(request.POST)
        if vl_formset.is_valid():
            # TODO: check the user's permission
            for a in vl_formset.cleaned_data:
                if a:
                    if a['DELETE']:
                        try:
                            vote_id = a['vote_id']
                            av = AgendaVote.objects.get(
                                   agenda__id=a['agenda_id'],
                                   vote__id = a['vote_id'])
                            av.delete()
                        except AgendaVote.DoesNotExist:
                            pass
                    else: # not delete, so try to create
                        try:
                            vote_id = a['vote_id']
                            print "vote id = %s" % vote_id
                            av = AgendaVote.objects.get(
                                   agenda__id=a['agenda_id'],
                                   vote__id = a['vote_id'])
                            av.score = a['weight']
                            av.reasoning = a['reasoning']
                            av.save()
                        except AgendaVote.DoesNotExist:
                            av = AgendaVote(
                                   agenda_id=int(a['agenda_id']),
                                   vote_id=int(a['vote_id']),
                                   score = a['weight'],
                                   reasoning = a['reasoning'])
                            av.save()
                else:
                    print "invalid form"
            if vote_id:
                return HttpResponseRedirect(reverse('vote-detail', kwargs={'object_id':vote_id}))
            else:
                return HttpResponseRedirect(reverse('vote-list'))

        else:
            # TODO: Error handling: what to do with illeal forms?
            print "invalid formset"
            return HttpResponseRedirect(reverse('vote-list'))

    else:
        return HttpResponseNotAllowed(['POST'])
Exemple #4
0
def update_editors_agendas(request):
    if request.method == 'POST':
        object_type = request.POST.get('form-0-object_type', None)
        object_id = request.POST.get('form-0-vote_id', None)
        if object_type == 'vote':
            vl_formset = VoteLinkingFormSet(request.POST)
        else:
            vl_formset = MeetingLinkingFormSet(request.POST)
        if vl_formset.is_valid():
            for a in vl_formset.cleaned_data:
                if a:
                    # Check that the user is an editor of the agenda
                    # he's trying to edit
                    try:
                        agenda = Agenda.objects.get(pk=a['agenda_id'])
                        if request.user not in agenda.editors.all():
                            return HttpResponseForbidden()
                    except Agenda.DoesNotExist:
                        return HttpResponseForbidden()

                    if a['object_type'] == 'vote':
                        if a['DELETE']:
                            try:
                                object_id = a['vote_id']
                                av = AgendaVote.objects.get(
                                    agenda__id=a['agenda_id'],
                                    vote__id=a['vote_id'])
                                av.delete()
                            except AgendaVote.DoesNotExist:
                                pass
                        else:  # not delete, so try to create
                            if (a['weight'] is not ''
                                    and a['importance'] is not ''):
                                try:
                                    object_id = a['vote_id']
                                    av = AgendaVote.objects.get(
                                        agenda__id=a['agenda_id'],
                                        vote__id=a['vote_id'])
                                    av.score = a['weight']
                                    av.importance = a['importance']
                                    av.reasoning = a['reasoning']
                                    av.save()
                                except AgendaVote.DoesNotExist:
                                    av = AgendaVote(agenda_id=int(
                                        a['agenda_id']),
                                                    vote_id=int(a['vote_id']),
                                                    score=a['weight'],
                                                    importance=a['importance'],
                                                    reasoning=a['reasoning'])
                                    av.save()
                    if a['object_type'] == 'committeemeeting':
                        if a['DELETE']:
                            try:
                                object_id = a['vote_id']
                                av = AgendaMeeting.objects.get(
                                    agenda__id=a['agenda_id'],
                                    meeting__id=a['vote_id'])
                                av.delete()
                            except AgendaMeeting.DoesNotExist:
                                pass
                        else:  # not delete, so try to create
                            try:
                                object_id = a['vote_id']
                                av = AgendaMeeting.objects.get(
                                    agenda__id=a['agenda_id'],
                                    meeting__id=a['vote_id'])
                                av.score = a['weight']
                                av.reasoning = a['reasoning']
                                av.save()
                            except AgendaMeeting.DoesNotExist:
                                av = AgendaMeeting(
                                    agenda_id=int(a['agenda_id']),
                                    meeting_id=int(a['vote_id']),
                                    score=a['weight'],
                                    reasoning=a['reasoning'])
                                av.save()
                else:
                    logger.info("invalid form")

        else:
            # TODO: Error handling: what to do with illeal forms?
            logger.info("invalid formset")
            logger.info("%s" % vl_formset.errors)
        if object_id:
            if object_type == 'vote':
                return HttpResponseRedirect(
                    reverse('vote-detail', kwargs={'object_id': object_id}))
            else:
                return HttpResponseRedirect(
                    reverse('committee-meeting', kwargs={'pk': object_id}))
        else:  # no object id was found, return to list
            if object_type == 'vote':
                return HttpResponseRedirect(reverse('vote-list'))
            else:
                return HttpResponseRedirect(reverse('committee-list'))

    else:
        return HttpResponseNotAllowed(['POST'])
Exemple #5
0
def update_editors_agendas(request):
    if request.method == 'POST':
        object_type = request.POST.get('form-0-object_type',None)
        object_id = request.POST.get('form-0-vote_id',None)
        if object_type=='vote':
            vl_formset = VoteLinkingFormSet(request.POST)
        else:
            vl_formset = MeetingLinkingFormSet(request.POST)
        if vl_formset.is_valid():
            for a in vl_formset.cleaned_data:
                if a:
                    # Check that the user is an editor of the agenda
                    # he's trying to edit
                    try:
                        agenda = Agenda.objects.get(pk=a['agenda_id'])
                        if request.user not in agenda.editors.all():
                            return HttpResponseForbidden()
                    except Agenda.DoesNotExist:
                        return HttpResponseForbidden()

                    if a['object_type'] == 'vote':
                        if a['DELETE']:
                            try:
                                object_id = a['vote_id']
                                av = AgendaVote.objects.get(
                                       agenda__id=a['agenda_id'],
                                       vote__id = a['vote_id'])
                                av.delete()
                            except AgendaVote.DoesNotExist:
                                pass
                        else: # not delete, so try to create
                            if (a['weight'] is not '' and
                                a['importance'] is not ''):
                                try:
                                    object_id = a['vote_id']
                                    av = AgendaVote.objects.get(
                                           agenda__id=a['agenda_id'],
                                           vote__id = a['vote_id'])
                                    av.score = a['weight']
                                    av.importance = a['importance']
                                    av.reasoning = a['reasoning']
                                    av.save()
                                except AgendaVote.DoesNotExist:
                                    av = AgendaVote(
                                           agenda_id=int(a['agenda_id']),
                                           vote_id=int(a['vote_id']),
                                           score = a['weight'],
                                           importance = a['importance'],
                                           reasoning = a['reasoning'])
                                    av.save()
                    if a['object_type'] == 'committeemeeting':
                        if a['DELETE']:
                            try:
                                object_id = a['vote_id']
                                av = AgendaMeeting.objects.get(
                                       agenda__id=a['agenda_id'],
                                       meeting__id = a['vote_id'])
                                av.delete()
                            except AgendaMeeting.DoesNotExist:
                                pass
                        else: # not delete, so try to create
                            try:
                                object_id = a['vote_id']
                                av = AgendaMeeting.objects.get(
                                       agenda__id=a['agenda_id'],
                                       meeting__id = a['vote_id'])
                                av.score = a['weight']
                                av.reasoning = a['reasoning']
                                av.save()
                            except AgendaMeeting.DoesNotExist:
                                av = AgendaMeeting(
                                       agenda_id=int(a['agenda_id']),
                                       meeting_id=int(a['vote_id']),
                                       score = a['weight'],
                                       reasoning = a['reasoning'])
                                av.save()
                else:
                    logger.info("invalid form")

        else:
            # TODO: Error handling: what to do with illeal forms?
            logger.info("invalid formset")
            logger.info("%s" % vl_formset.errors)
        if object_id:
            if object_type=='vote':
                return HttpResponseRedirect(reverse('vote-detail',
                                        kwargs={'object_id':object_id}))
            else:
                return HttpResponseRedirect(reverse('committee-meeting',
                                         kwargs={'pk':object_id}))
        else: # no object id was found, return to list
            if object_type=='vote':
                return HttpResponseRedirect(reverse('vote-list'))
            else:
                return HttpResponseRedirect(reverse('committee-list'))

    else:
        return HttpResponseNotAllowed(['POST'])