Bawa
This commit is contained in:
parent
ed2fafe61a
commit
20a02d1013
57 changed files with 698 additions and 44 deletions
0
propositions/__init__.py
Normal file
0
propositions/__init__.py
Normal file
BIN
propositions/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
propositions/__pycache__/admin.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
propositions/__pycache__/forms.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/forms.cpython-34.pyc
Normal file
Binary file not shown.
BIN
propositions/__pycache__/models.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
BIN
propositions/__pycache__/urls.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/urls.cpython-34.pyc
Normal file
Binary file not shown.
BIN
propositions/__pycache__/utils.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/utils.cpython-34.pyc
Normal file
Binary file not shown.
BIN
propositions/__pycache__/views.cpython-34.pyc
Normal file
BIN
propositions/__pycache__/views.cpython-34.pyc
Normal file
Binary file not shown.
3
propositions/admin.py
Normal file
3
propositions/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
12
propositions/forms.py
Normal file
12
propositions/forms.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django import forms
|
||||
from propositions.models import Prop
|
||||
|
||||
class PropForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Prop
|
||||
fields = ('nom', 'artiste', 'lien')
|
||||
widgets = {
|
||||
'lien': forms.TextInput(attrs={"placeholder": "facultatif"}),
|
||||
'nom': forms.TextInput(attrs={"placeholder": "Nom du morceau"}),
|
||||
'artiste': forms.TextInput(attrs={"placeholder": "facultatif"}),
|
||||
}
|
29
propositions/models.py
Normal file
29
propositions/models.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from django.db import models
|
||||
from gestion.models import ErnestoUser
|
||||
|
||||
REP = (
|
||||
('oui', 'Oui'),
|
||||
('non', 'Non'),
|
||||
)
|
||||
|
||||
class Prop(models.Model):
|
||||
nom = models.CharField(max_length=100)
|
||||
artiste = models.CharField(blank=True, max_length=100)
|
||||
user = models.ForeignKey(ErnestoUser, verbose_name="Proposé par")
|
||||
lien = models.URLField(blank=True)
|
||||
nboui = models.IntegerField(default=0, verbose_name="oui")
|
||||
nbnon = models.IntegerField(default=0, verbose_name="non")
|
||||
|
||||
def __str__(self):
|
||||
return self.nom
|
||||
|
||||
class Meta:
|
||||
verbose_name="Proposition"
|
||||
|
||||
class Reponses(models.Model):
|
||||
prop = models.ForeignKey(Prop)
|
||||
part = models.ForeignKey(ErnestoUser)
|
||||
reponse = models.CharField("Réponse", max_length=20, blank=True, choices=REP)
|
||||
|
||||
# Create your models here.
|
||||
|
BIN
propositions/templatetags/__pycache__/getresponse.cpython-34.pyc
Normal file
BIN
propositions/templatetags/__pycache__/getresponse.cpython-34.pyc
Normal file
Binary file not shown.
12
propositions/templatetags/getresponse.py
Normal file
12
propositions/templatetags/getresponse.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django import template
|
||||
from propositions.models import Reponses
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.inclusion_tag("propositions/reponse.html")
|
||||
def getresponse(user, prop):
|
||||
try:
|
||||
rep = Reponses.objects.get(prop=prop, part=user)
|
||||
return {"reponse": rep.reponse}
|
||||
except Reponses.DoesNotExist:
|
||||
return {}
|
3
propositions/tests.py
Normal file
3
propositions/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
10
propositions/urls.py
Normal file
10
propositions/urls.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from django.conf.urls import patterns, url
|
||||
from propositions.views import PropDelete
|
||||
|
||||
urlpatterns = patterns('propositions.views',
|
||||
url(r'^$', 'liste'),
|
||||
url(r'^new/?$', 'create_prop'),
|
||||
url(r'^(?P<id>\d+)/oui/?$', 'repoui'),
|
||||
url(r'^(?P<id>\d+)/non/?$', 'repnon'),
|
||||
url(r'^(?P<pk>\d+)/supprimer/?$', PropDelete.as_view()),
|
||||
)
|
7
propositions/utils.py
Normal file
7
propositions/utils.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
import string
|
||||
import random
|
||||
|
||||
def generer(*args):
|
||||
caracteres = string.ascii_letters + string.digits
|
||||
aleatoire = [random.choice(caracteres) for _ in range(6)]
|
||||
return ''.join(aleatoire)
|
101
propositions/views.py
Normal file
101
propositions/views.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.views.generic import DeleteView
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
import string
|
||||
import random
|
||||
|
||||
from propositions.forms import PropForm
|
||||
from propositions.models import Prop
|
||||
from propositions.models import Reponses
|
||||
from propositions.utils import generer
|
||||
from gestion.models import ErnestoUser
|
||||
|
||||
@login_required
|
||||
def create_prop(request):
|
||||
if request.method == "POST":
|
||||
form = PropForm(request.POST)
|
||||
if form.is_valid():
|
||||
obj = form.save(commit=False)
|
||||
obj.nboui = 0
|
||||
obj.nbnon = 0
|
||||
obj.user = request.user.profile
|
||||
obj.save()
|
||||
envoi = True
|
||||
else:
|
||||
form = PropForm()
|
||||
return render(request, "propositions/create.html", locals())
|
||||
|
||||
@login_required
|
||||
def liste(request):
|
||||
props = Prop.objects.all().order_by('-nboui', 'nbnon', 'nom')
|
||||
n = len(props)
|
||||
return render(request, 'propositions/liste.html', locals())
|
||||
|
||||
|
||||
@login_required
|
||||
def repoui(request, id):
|
||||
prop = Prop.objects.get(id=id)
|
||||
participant = request.user.profile
|
||||
try:
|
||||
p = Reponses.objects.get(prop=prop, part=participant)
|
||||
if p.reponse == "oui":
|
||||
prop.nboui -= 1
|
||||
else:
|
||||
prop.nbnon-=1
|
||||
p.delete()
|
||||
except Reponses.DoesNotExist:
|
||||
pass
|
||||
rep = Reponses()
|
||||
rep.prop = prop
|
||||
rep.part = participant
|
||||
rep.reponse = "oui"
|
||||
rep.save()
|
||||
prop.nboui += 1
|
||||
prop.save()
|
||||
return redirect('propositions.views.liste')
|
||||
|
||||
class PropDelete(DeleteView):
|
||||
model = Prop
|
||||
template_name= "propositions/delete.html"
|
||||
success_url = reverse_lazy(liste)
|
||||
|
||||
@method_decorator(login_required)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(PropDelete, self).dispatch(*args, **kwargs)
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
success_url = self.get_success_url()
|
||||
if not ((self.object.user == self.request.user.profile) or self.request.user.profile.is_chef):
|
||||
return redirect('propositions.views.liste')
|
||||
else:
|
||||
self.object.delete()
|
||||
return HttpResponseRedirect(success_url)
|
||||
|
||||
@login_required
|
||||
def repnon(request, id):
|
||||
prop = Prop.objects.get(id=id)
|
||||
participant = request.user.profile
|
||||
try:
|
||||
p = Reponses.objects.get(prop=prop, part=participant)
|
||||
if p.reponse == "oui":
|
||||
prop.nboui -= 1
|
||||
else:
|
||||
prop.nbnon -= 1
|
||||
p.delete()
|
||||
except Reponses.DoesNotExist:
|
||||
pass
|
||||
rep = Reponses()
|
||||
rep.prop = prop
|
||||
rep.part = participant
|
||||
rep.reponse = "non"
|
||||
rep.save()
|
||||
prop.nbnon += 1
|
||||
prop.save()
|
||||
return redirect('propositions.views.liste')
|
||||
|
||||
# Create your views here.
|
Loading…
Add table
Add a link
Reference in a new issue