def view_poll(request, pk): poll = get_object_or_404(UPoll, pk=pk) groups = Group.objects.filter(pk__in=poll.contacts.values_list('groups')) category = None if request.GET.get('poll'): if request.GET.get('start'): poll=Poll.objects.get(pk=pk) start_poll.delay(poll) res = """ <a href="?stop=True&poll=True" data-remote=true id="poll_action" class="btn">Close Poll</a> """ return HttpResponse(res) if request.GET.get('stop'): poll.end() res = HttpResponse( """ <a href="?reopen=True&poll=True" data-remote=true id="poll_action" class="btn">Reopen Poll</a> """) res['Cache-Control'] = 'no-store' return res if request.GET.get("reopen"): poll.end_date = None poll.save() res = HttpResponse( """<a href="?stop=True&poll=True" data-remote=true id="poll_action" class="btn">Close Poll</a> """) res['Cache-Control'] = 'no-store' return res if request.GET.get('viewable'): poll.set_attr('viewable', 'true') res = HttpResponse( '<a href="javascript:void(0)" id="poll_v" class="btn" onclick="loadViewable' '(\'?unviewable=True&poll=True\')">Don\'t Show On Home page</a>') res['Cache-Control'] = 'no-store' return res if request.GET.get('unviewable'): poll.set_attr('viewable', 'false') res = HttpResponse( '<a href="javascript:void(0)" id="poll_v" class="btn" onclick="loadViewable' '(\'?viewable=True&poll=True\')">Show On Home page</a>') res['Cache-Control'] = 'no-store' return res xf, _ = XFormField.objects.get_or_create(name='latest_poll') response = StubScreen.objects.get(slug='question_response') template = 'ureport/polls/view_poll.html' categories = poll.categories.all() category_form = CategoryForm() rule_form = RuleForm2() if request.method == "POST": if request.GET.get('edit'): if request.POST.get('poll[default_response]'): poll.default_response = request.POST['poll[default_response]'] poll.save() if request.POST.get('poll[question]'): poll.question = request.POST['poll[question]'] poll.save() if request.GET.get("ussd", None): question = request.POST.get("question") response = request.POST.get("response") xf.question = question xf.save() response.text = response response.save() if request.GET.get("category", None): if request.GET.get('cat_pk'): category = Category.objects.get(pk=int(request.GET.get('cat_pk'))) else: category = Category() category.poll = poll category_form = CategoryForm(request.POST, instance=category) if category_form.is_valid(): template = "ureport/polls/rules.html" category = category_form.save() request.session['category'] = category else: template = "ureport/polls/category.html" if request.GET.get("rules", None): rule = Rule() rule.category = request.session['category'] rule_form = RuleForm2(request.POST, instance=rule) if rule_form.is_valid: rule_form.save() else: template = "ureport/polls/rules.html" try: poll_is_viewable = poll.get_attr('viewable') except ObjectDoesNotExist: poll_is_viewable = poll.set_attr('viewable', 'true') return render_to_response(template, { 'poll': poll, 'poll_is_viewable': poll_is_viewable, 'xf': xf, 'response': response, 'categories': categories, 'category_form': category_form, 'rule_form': rule_form, 'category': category, 'groups': groups, }, context_instance=RequestContext(request))
def view_poll(request,pk): poll=Poll.objects.get(pk=pk) category=None if request.GET.get('poll'): if request.GET.get('start'): start_poll.delay(poll) res=""" <a href="?stop=True&poll=True" data-remote=true id="poll_action" class="btn">Close Poll</a> """ return HttpResponse(res) if request.GET.get('stop'): poll.end() res=""" <a href="?reopen=True&poll=True" data-remote=true id="poll_action" class="btn">Reopen Poll</a> """ return HttpResponse(res) if request.GET.get("reopen"): poll.end_date=None poll.save() res="""<a href="?stop=True&poll=True" data-remote=true id="poll_action" class="btn">Close Poll</a> """ return HttpResponse(res) xf,_=XFormField.objects.get_or_create(name='latest_poll') response=StubScreen.objects.get(slug='question_response') template='ureport/polls/view_poll.html' categories=poll.categories.all() category_form=CategoryForm() rule_form=RuleForm2() if request.method == "POST": if request.GET.get('edit'): if request.POST.get('poll[default_response]'): poll.default_response=request.POST['poll[default_response]'] poll.save() if request.POST.get('poll[question]'): poll.question=request.POST['poll[question]'] poll.save() if request.GET.get("ussd",None): question=request.POST.get("question") response=request.POST.get("response") xf.question=question xf.save() response.text=response response.save() if request.GET.get("category",None): if request.GET.get('cat_pk'): category=Category.objects.get(pk=int(request.GET.get('cat_pk'))) else: category=Category() category.poll=poll category_form=CategoryForm(request.POST,instance=category) if category_form.is_valid(): template="ureport/polls/rules.html" category=category_form.save() request.session['category'] =category else: template="ureport/polls/category.html" if request.GET.get("rules",None): rule=Rule() rule.category=request.session['category'] rule_form=RuleForm2(request.POST,instance=rule) if rule_form.is_valid: rule_form.save() else: template="ureport/polls/rules.html" return render_to_response(template, { 'poll': poll, 'xf':xf, 'response':response, 'categories': categories, 'category_form':category_form, 'rule_form':rule_form, 'category':category , }, context_instance=RequestContext(request))