--- /dev/null
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Vote',
+ fields=[
+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+ ('choice', models.CharField(max_length=10, verbose_name='Choice')),
+ ('comment', models.TextField(verbose_name='Comment')),
+ ('creation_timestamp', models.DateTimeField(auto_now_add=True)),
+ ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ },
+ bases=(models.Model,),
+ ),
+ ]
--- /dev/null
+from django.conf import settings
+from django.utils.translation import ugettext_lazy as _
+from django.db import models
+
+class Vote(models.Model):
+ user = models.ForeignKey(settings.AUTH_USER_MODEL)
+ choice = models.CharField(_('Choice'), max_length=10)
+ comment = models.TextField(_('Comment'))
+ creation_timestamp = models.DateTimeField(auto_now_add=True)
--- /dev/null
+from django.contrib.auth.decorators import login_required
+from django.shortcuts import redirect
+from django.views.generic.base import TemplateView
+from django.contrib import messages
+
+from .models import Vote
+
+class VoteView(TemplateView):
+ template_name = 'vote.html'
+
+ def dispatch(self, request, *args, **kwargs):
+ try:
+ vote = Vote.objects.get(user=request.user)
+ messages.error(request, 'Non !')
+ return redirect('home')
+ except Vote.DoesNotExist:
+ pass
+ return super(VoteView, self).dispatch(request, *args, **kwargs)
+
+ def post(self, request):
+ choice = request.POST['choice']
+ comment = request.POST['comment']
+
+ vote = Vote(
+ user=request.user,
+ choice=request.POST['choice'],
+ comment=request.POST['comment'])
+ vote.save()
+ messages.success(request, 'Merci !')
+ return redirect('home')
+
+vote = login_required(VoteView.as_view())
'panikdb.aa',
'panikdb.customtags',
'panikdb.stats',
+ 'panikdb.poll',
'gadjo',
'combo.data',
'combo.manager',
div#content div#available-cells ul {
padding: 0;
}
+
+div.poll {
+ border-radius: 10px;
+ margin: 0 auto;
+ text-align: center;
+ max-width: 30em;
+ background: #FF7600;
+ border: 1px solid red;
+}
+
+div.poll a {
+ display: inline-block;
+ width: 100%;
+ padding: 3em;
+ color: white;
+ font-weight: bold;
+}
+
+form.poll img {
+ margin-left: 1em;
+ margin-right: 4em;
+}
+
+form.poll p {
+ margin-top: 1em;
+}
+
+form.poll textarea {
+ width: 100%;
+ max-width: 40em;
+ height: 10em;
+}
+
+form.poll div.buttons {
+ margin-top: 1em;
+}
+
+form.poll div.error {
+ padding: 1ex;
+ max-width: 40em;
+ margin: 2em;
+ border: 2px solid red;
+}
{% endblock %}
{% block content %}
+
+{% if display_poll_button %}
+<div class="poll">
+ <a href="{% url 'vote' %}">Sondage Logo !</a>
+</div>
+{% endif %}
+
<h2>Émissions</h2>
{% for emission in emissions %}
--- /dev/null
+{% extends "base.html" %}
+
+{% block content %}
+
+<h2>Bienvenue sur le sondage Logo de Radio Panik !</h2>
+
+<p>
+Ci-dessous, vous trouverez les deux propositions de logos préparées par
+notre graphiste embauché et validés par le Groupe LOGO.
+</p>
+
+<p>
+Votez pour l'un de ces logos !
+</p>
+
+<p>
+Vous avez aussi la possibilité de faire un commentaire pour justifier votre
+choix ou suggérer une amélioration au logo qui a votre faveur (en effet, un
+dernier travail avec le graphiste est prévu pour peaufiner le logo
+démocratiquement choisi).
+</p>
+
+<p>
+Vous pouvez également vous abstenir, c'est-à-dire que vous ne vous prononcez
+pas pour l'un des logos proposés mais vous devez alors justifier votre
+abstention en complétant la case « commentaire ».
+</p>
+
+<p>
+Vous n'avez qu¹une seule voix par identifiant, tout vote est définitif et
+vous devez voter avant le <strong>LUNDI 18 AVRIL 2016</strong>.
+</p>
+
+<p>
+Merci pour votre participation !
+</p>
+
+<hr/>
+
+<form method="post" class="poll">
+
+ <div class="error" style="display: none;">
+ Oups ! Vous n'avez sélectionné aucun logo proposé ! Veuillez en
+ choisir un. Vous pouvez aussi vous abstenir et ne choisir aucun
+ des deux logos proposés mais dans ce cas, vous devez justifier
+ votre abstention en utilisant la case « COMMENTAIRES ».
+ </div>
+
+{% csrf_token %}
+<div class="choices">
+<label><input type="radio" name="choice" value="1"><img src="/static/ckeditor/ckeditor/plugins/image/images/noimage.png" width="320" height="240" alt="logo 1"/></input></label>
+<label><input type="radio" name="choice" value="2"><img src="/static/ckeditor/ckeditor/plugins/image/images/noimage.png" width="320" height="240" alt="logo 2"/></input></label>
+<label><input type="radio" name="choice" value="3">Abstention</input></label>
+</div>
+
+<p>
+ Commentaire :
+</p>
+<textarea name="comment">
+</textarea>
+
+<div class="buttons">
+<button>Enregistrer mon vote</button>
+</div>
+</form>
+
+<script>
+$('form').on('submit', function() {
+ var comment = $('textarea').val();
+ var choice = $('input[name=choice]:checked').val();
+ if (choice === undefined || (choice == "3" && comment.length < 10)) {
+ $('div.error').show();
+ return false;
+ }
+});
+</script>
+
+{% endblock %}
+
url(r'^combok/soundfiles/', 'panikombo.views.soundfiles'),
url(r'^combok/episodes/', 'panikombo.views.episodes'),
+ url(r'^vote/', 'panikdb.poll.views.vote', name='vote'),
+
url(r'^admin/', include(admin.site.urls)),
)
import emissions.views
import newsletter.views
+from .poll.models import Vote
+
class Home(TemplateView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super(Home, self).get_context_data(**kwargs)
+ try:
+ vote = Vote.objects.get(user=self.request.user)
+ except Vote.DoesNotExist:
+ context['display_poll_button'] = True
context['emissions'] = self.request.user.emissions.all().order_by('title')
context['news_categories'] = self.request.user.news_categories.all().order_by('title')
if self.request.user.has_perm('emissions.add_focus'):