Browse Source

added LiveSlide links

pull/10/head
crunch 4 months ago
parent
commit
7033015322
4 changed files with 43 additions and 3 deletions
  1. +4
    -0
      Consulta_project/polls/admin.py
  2. +7
    -0
      Consulta_project/polls/templates/admin/guardian/model/change_form.html
  3. +4
    -2
      Consulta_project/polls/urls.py
  4. +28
    -1
      Consulta_project/polls/views.py

+ 4
- 0
Consulta_project/polls/admin.py View File

@@ -86,6 +86,10 @@ class PollAdmin(GuardedModelAdmin):

extra_context['owner'] = bool(request.user == poll.get_owner())
extra_context['unlocked'] = poll.is_unlocked
extra_context['poll'] = poll
extra_context['begin_url'] = request.build_absolute_uri(reverse('poll-begin', args=(poll.slug, )))
extra_context['stats_url'] = request.build_absolute_uri(reverse('poll-stats', args=(poll.slug, )))
extra_context['end_url'] = request.build_absolute_uri(reverse('poll-end', args=(poll.slug, )))
extra_context['superuser'] = request.user.is_superuser

return self.changeform_view(request, object_id, form_url, extra_context)


+ 7
- 0
Consulta_project/polls/templates/admin/guardian/model/change_form.html View File

@@ -2,6 +2,12 @@
{% load i18n admin_urls %}

{% block field_sets %}
{% if change_poll or superuser %}
<p style="font-weight: bolder;">Enter these links into the PowerPoint Liveslides Add-In:</p>
<p style="color:darkcyan; font-weight: bold;"><small style="color: black; font-weight: lighter;">Begin URL:</small> {{ begin_url }}</p>
<p style="color:darkcyan; font-weight: bold;"><small style="color: black; font-weight: lighter;">Stats URL:</small> {{ stats_url }}</p>
<p style="color:darkcyan; font-weight: bold;"><small style="color: black; font-weight: lighter;">End URL:</small> {{ end_url }}</p>
{% endif %}
{% for fieldset in adminform %}
{% include "admin/polls/includes/fieldset.html" %}
{% endfor %}
@@ -9,6 +15,7 @@

{% block object-tools-items %}
{% url opts|admin_urlname:'permissions' original.pk|admin_urlquote as history_url %}

{% if owner or superuser %}
<li><a href="{% add_preserved_filters history_url %}" class="permissionslink">{% trans "Object Permissions" %}</a></li>
{% endif %}


+ 4
- 2
Consulta_project/polls/urls.py View File

@@ -6,8 +6,10 @@ urlpatterns = [
path('', views.polls, name='polls'),
path('qr/', include(qr_code_urls, namespace="qr_code")),
path('<slug:slug>/', views.poll_detail, name='poll-detail'),
path('<slug:slug>/share', views.share, name='poll-share'),
path('<slug:slug>/stats', views.stats, name='poll-stats'),
path('<slug:slug>/begin/', views.begin, name='poll-begin'),
path('<slug:slug>/end/', views.end, name='poll-end'),
path('<slug:slug>/share/', views.share, name='poll-share'),
path('<slug:slug>/stats/', views.stats, name='poll-stats'),
path('<slug:slug>/questions/<int:question>/',
views.question_detail, name='question-detail'),
path('<slug:slug>/questions/<int:question>/vote/', views.vote, name='vote'),


+ 28
- 1
Consulta_project/polls/views.py View File

@@ -1,5 +1,5 @@
from django.shortcuts import render
from django.http import Http404, HttpResponseRedirect
from django.http import Http404, HttpResponseRedirect, HttpResponseForbidden
from django.urls import reverse
from .models import Poll, Question, Answer
from django.shortcuts import get_object_or_404, get_list_or_404
@@ -95,3 +95,30 @@ def vote(request, question, **kwargs):
print("Vote successful")
choice.save()
return HttpResponseRedirect(reverse('poll-detail', kwargs={'slug':question.poll.slug}))

def begin(request, slug):
poll = Poll.objects.get(slug=slug)

if not(request.user.is_superuser or poll.get_owner() == request.user):
return HttpResponseForbidden("You need to own this Poll or have change permissions to change its status!")
else:
if not(poll.is_unlocked()):
poll.unlocked = True
poll.save()
return HttpResponseRedirect(reverse('poll-share', kwargs={'slug':poll.slug}))

return HttpResponseRedirect(reverse('poll-share', kwargs={'slug':poll.slug}))

def end(request, slug):
poll = Poll.objects.get(slug=slug)

if not(request.user.is_superuser or poll.get_owner() == request.user):
return HttpResponseForbidden("You need to own this Poll or have change permissions to change its status!")
else:
if (poll.is_unlocked()):
poll.unlocked = False
poll.save()
return HttpResponseRedirect(reverse('index'))

return HttpResponseRedirect(reverse('index'))


Loading…
Cancel
Save