def create_tag_and_add_to_item(request, app, object_type, object_id): """adds tag with name=request.POST['tag'] to the tag list, and tags the given object with it **** Currently not used anywhere, sine we don't want to allow users to add more tags for now. """ if request.method == 'POST' and 'tag' in request.POST: tag = request.POST['tag'].strip() msg = "user %s is creating tag %s on object_type %s and object_id %s".encode('utf8') % (request.user.username, tag, object_type, object_id) logger.info(msg) notify_responsible_adult(msg) if len(tag)<3: return HttpResponseBadRequest() tags = Tag.objects.filter(name=tag) if not tags: try: tag = Tag.objects.create(name=tag) except Exception: logger.warn("can't create tag %s" % tag) return HttpResponseBadRequest() if len(tags)==1: tag = tags[0] if len(tags)>1: logger.warn("More than 1 tag: %s" % tag) return HttpResponseBadRequest() return _add_tag_to_object(request.user, app, object_type, object_id, tag) else: return HttpResponseNotAllowed(['POST'])
def bill_unbind_vote(request, object_id, vote_id): try: bill = Bill.objects.get(pk=object_id) vote = Vote.objects.get(pk=vote_id) except ObjectDoesNotExist: raise Http404 if request.method == 'POST': # actually unbind explanation = request.POST.get('explanation', '') msg = u'%s is unbinding vote %s from bill %s. explanation: %s' % \ (str(request.user).decode('utf8'), vote_id, object_id, explanation) notify_responsible_adult(msg) logger.info(msg) if vote in bill.pre_votes.all(): bill.pre_votes.remove(vote) if vote == bill.first_vote: bill.first_vote = None if vote == bill.approval_vote: bill.approval_vote = None bill.update_stage(force_update=True) return HttpResponseRedirect(reverse('bill-detail', args=[object_id])) else: # approve unbind context = RequestContext(request, {'object': bill, 'vote': vote}) return render_to_response("laws/bill_unbind_vote.html", context)
def bill_unbind_vote(request, object_id, vote_id): try: bill = Bill.objects.get(pk=object_id) vote = Vote.objects.get(pk=vote_id) except ObjectDoesNotExist: raise Http404 if request.method != 'POST': context = RequestContext (request, {'object': bill, 'vote':vote}) return render_to_response("laws/bill_unbind_vote.html", context) # actually unbind explanation = request.POST.get('explanation','') msg = u'{} is unbinding vote {} from bill {}. explanation: {}'.format( request.user, #str(request.user).decode('utf8'), vote_id, object_id, explanation) notify_responsible_adult(msg) logger.info(msg) if vote in bill.pre_votes.all(): bill.pre_votes.remove(vote) if vote == bill.first_vote: bill.first_vote = None if vote == bill.approval_vote: bill.approval_vote = None bill.update_stage(force_update=True) return HttpResponseRedirect(reverse('bill-detail', args=[object_id]))
def create_tag_and_add_to_item(request, app, object_type, object_id): """adds tag with name=request.POST['tag'] to the tag list, and tags the given object with it""" if request.method == "POST" and "tag" in request.POST: tag = request.POST["tag"].strip() msg = "user %s is creating tag %s on object_type %s and object_id %s".encode("utf8") % ( request.user.username, tag, object_type, object_id, ) logger.info(msg) notify_responsible_adult(msg) if len(tag) < 3: return HttpResponseBadRequest() tags = Tag.objects.filter(name=tag) if not tags: try: tag = Tag.objects.create(name=tag) except Exception: logger.warn("can't create tag %s" % tag) return HttpResponseBadRequest() if len(tags) == 1: tag = tags[0] if len(tags) > 1: logger.warn("More than 1 tag: %s" % tag) return HttpResponseBadRequest() return _add_tag_to_object(request.user, app, object_type, object_id, tag) else: return HttpResponseNotAllowed(["POST"])
def bill_unbind_knesset_proposal(request, object_id): try: bill = Bill.objects.get(pk=object_id) knesset_proposal = bill.knesset_proposal except ObjectDoesNotExist: raise Http404 if request.method == 'POST': # actually unbind explanation = request.POST.get('explanation', '') msg = u'%s is unbinding knesset proposal %s from bill %s. explanation: %s' % \ (str(request.user).decode('utf8'), knesset_proposal.pk, object_id, explanation) notify_responsible_adult(msg) logger.info(msg) knesset_proposal.bill = None knesset_proposal.save() return HttpResponseRedirect(reverse('bill-detail', args=[object_id])) else: # approve unbind context = RequestContext(request, { 'object': bill, 'knesset_proposal': knesset_proposal }) return render_to_response("laws/bill_unbind_knesset_proposal.html", context)
def bill_unbind_committee_meeting(request, object_id, cm_id, cm_stage): try: bill = Bill.objects.get(pk=object_id) cm = CommitteeMeeting.objects.get(pk=cm_id) except ObjectDoesNotExist: raise Http404 if request.method == 'POST': # actually unbind explanation = request.POST.get('explanation', '') msg = u'%s is unbinding committee meeting %s from bill %s at meeting stage %s. explanation: %s' % \ (str(request.user).decode('utf8'), cm_id, object_id, cm_stage, explanation) notify_responsible_adult(msg) logger.info(msg) if cm_stage == "2": bill.second_committee_meetings.remove(cm) else: bill.first_committee_meetings.remove(cm) return HttpResponseRedirect(reverse('bill-detail', args=[object_id])) else: # approve unbind context = RequestContext(request, {'object': bill, 'cm': cm}) return render_to_response("laws/bill_unbind_committee_meeting.html", context)
def bill_unbind_vote(request, object_id, vote_id): try: bill = Bill.objects.get(pk=object_id) vote = Vote.objects.get(pk=vote_id) except ObjectDoesNotExist: raise Http404 if request.method == "POST": # actually unbind explanation = request.POST.get("explanation", "") msg = u"%s is unbinding vote %s from bill %s. explanation: %s" % ( str(request.user).decode("utf8"), vote_id, object_id, explanation, ) notify_responsible_adult(msg) logger.info(msg) if vote in bill.pre_votes.all(): bill.pre_votes.remove(vote) if vote == bill.first_vote: bill.first_vote = None if vote == bill.approval_vote: bill.approval_vote = None bill.update_stage(force_update=True) return HttpResponseRedirect(reverse("bill-detail", args=[object_id])) else: # approve unbind context = RequestContext(request, {"object": bill, "vote": vote}) return render_to_response("laws/bill_unbind_vote.html", context)