diff --git a/Ernestophone/settings-example.py b/Ernestophone/settings-example.py index 481ec5d..cd61502 100644 --- a/Ernestophone/settings-example.py +++ b/Ernestophone/settings-example.py @@ -96,7 +96,7 @@ STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'media/partitions'), ) -TEMPLATE_DIRS = ( +TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates/gestion/'), os.path.join(BASE_DIR, 'templates/'), ) @@ -104,4 +104,3 @@ TEMPLATE_DIRS = ( AUTH_PROFILE_MODEL = 'gestion.ErnestoUser' LOGIN_URL = "/login" - diff --git a/Ernestophone/urls.py b/Ernestophone/urls.py index 1a47a08..487bd71 100644 --- a/Ernestophone/urls.py +++ b/Ernestophone/urls.py @@ -3,20 +3,28 @@ from django.contrib import admin from django.conf.urls.static import static from django.conf import settings -urlpatterns = patterns('', +urlpatterns = patterns( + '', # Examples: url(r'^$', 'gestion.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^login/?$', 'gestion.views.login', ), - url(r'^logout/?$', 'django.contrib.auth.views.logout', {'next_page': '/'}, ), + url(r'^logout/?$', 'django.contrib.auth.views.logout', {'next_page': '/'}), url(r'^registration/?$', 'gestion.views.inscription_membre'), url(r'^change/?', 'gestion.views.change_membre'), url(r'^password/?', 'gestion.views.change_password'), - url(r'^user/password/reset/$', 'django.contrib.auth.views.password_reset', {'post_reset_redirect': '/user/password/reset/done/'}, name="password_reset"), - url(r'^user/password/reset/done/$', 'django.contrib.auth.views.password_reset_done'), - url(r'^user/password/reset/(?P[0-9A-Za-z]+)-(?P.+)/$', 'django.contrib.auth.views.password_reset_confirm', {'post_reset_redirect': '/user/password/done/'}, name="password_reset_confirm"), - url(r'^user/password/done/$', 'django.contrib.auth.views.password_reset_complete'), + url(r'^user/password/reset/$', 'django.contrib.auth.views.password_reset', + {'post_reset_redirect': '/user/password/reset/done/'}, + name="password_reset"), + url(r'^user/password/reset/done/$', + 'django.contrib.auth.views.password_reset_done'), + url(r'^user/password/reset/(?P[0-9A-Za-z]+)-(?P.+)/$', + 'django.contrib.auth.views.password_reset_confirm', + {'post_reset_redirect': '/user/password/done/'}, + name="password_reset_confirm"), + url(r'^user/password/done/$', + 'django.contrib.auth.views.password_reset_complete'), url(r'^admin/', include(admin.site.urls)), url(r'^partitions/', include('partitions.urls')), url(r'^pads/', include('pads.urls')), diff --git a/calendrier/admin.py b/calendrier/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/calendrier/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/calendrier/calend.py b/calendrier/calend.py index a061a4f..e91c321 100644 --- a/calendrier/calend.py +++ b/calendrier/calend.py @@ -1,8 +1,8 @@ from django.utils.html import conditional_escape as esc from itertools import groupby -from django.utils.safestring import mark_safe -from calendar import HTMLCalendar, monthrange -from datetime import * +from calendar import HTMLCalendar +from datetime import date + class EventCalendar(HTMLCalendar): @@ -22,8 +22,11 @@ class EventCalendar(HTMLCalendar): body.append('' % ev.id) body.append(esc(ev.nom)) body.append('
') - return self.day_cell(cssclass, '
%d
%s' % (day, ''.join(body))) - return self.day_cell(cssclass, '
%d
' % day) + return self.day_cell(cssclass, + '
%d
%s' + % (day, ''.join(body))) + return self.day_cell(cssclass, + '
%d
' % day) return self.day_cell('noday', ' ') def formatmonth(self, year, month): @@ -31,11 +34,10 @@ class EventCalendar(HTMLCalendar): return super(EventCalendar, self).formatmonth(year, month) def group_by_day(self, pEvents): - field = lambda ev: ev.date.day + def field(ev): ev.date.day return dict( [(dat, list(items)) for dat, items in groupby(pEvents, field)] ) def day_cell(self, cssclass, body): return '%s' % (cssclass, body) - diff --git a/calendrier/forms.py b/calendrier/forms.py index b69e21d..c012310 100644 --- a/calendrier/forms.py +++ b/calendrier/forms.py @@ -2,42 +2,65 @@ from django import forms from calendrier.models import Event, Participants from gestion.models import ErnestoUser + class ModifEventForm(forms.ModelForm): class Meta: model = Event exclude = ['slug'] widgets = { - 'description': forms.Textarea(attrs={"placeholder":"facultatif, balises html supportées"}), - 'date': forms.TextInput(attrs={"placeholder": 'jj/mm/aaaa'}), - 'debut': forms.TextInput(attrs={"placeholder": 'hh:mm'}), - 'fin': forms.TextInput(attrs={"placeholder": 'hh:mm facultatif'}) + 'description': forms.Textarea(attrs={ + "placeholder": "facultatif, balises html supportées"}), + 'date': forms.TextInput(attrs={"placeholder": 'jj/mm/aaaa'}), + 'debut': forms.TextInput(attrs={"placeholder": 'hh:mm'}), + 'fin': forms.TextInput(attrs={"placeholder": 'hh:mm facultatif'}) } + class SendMail(forms.Form): - message = forms.CharField(max_length=2000, widget=forms.Textarea(attrs={"placeholder":"Remplir ici pour remplacer le mail automatique"}), required=False) + message = forms.CharField( + max_length=2000, + widget=forms.Textarea( + attrs={"placeholder": + "Remplir ici pour remplacer le mail automatique"}), + required=False) + class EventForm(forms.ModelForm): - sendmail = forms.BooleanField(initial=False, label="Envoyer l'invitation à la liste fanfare", required=False) - message = forms.CharField(max_length=2000, widget=forms.Textarea(attrs={"placeholder":"Remplir ici pour remplacer le mail automatique"}), required=False) + sendmail = forms.BooleanField( + initial=False, + label="Envoyer l'invitation à la liste fanfare", + required=False) + message = forms.CharField( + max_length=2000, + widget=forms.Textarea( + attrs={"placeholder": + "Remplir ici pour remplacer le mail automatique"}), + required=False) + class Meta: model = Event exclude = ['slug'] widgets = { - 'nomcourt': forms.TextInput(attrs={"placeholder": '9 caractères max'}), - 'description': forms.Textarea(attrs={"placeholder":"facultatif, balises html supportées"}), - 'date': forms.TextInput(attrs={"placeholder": 'jj/mm/aaaa'}), - 'debut': forms.TextInput(attrs={"placeholder": 'hh:mm'}), - 'fin': forms.TextInput(attrs={"placeholder": 'hh:mm facultatif'}) + 'nomcourt': forms.TextInput( + attrs={"placeholder": '9 caractères max'}), + 'description': forms.Textarea( + attrs={"placeholder": "facultatif, balises html supportées"}), + 'date': forms.TextInput(attrs={"placeholder": 'jj/mm/aaaa'}), + 'debut': forms.TextInput(attrs={"placeholder": 'hh:mm'}), + 'fin': forms.TextInput(attrs={"placeholder": 'hh:mm facultatif'}) } - + + class ParticipantsForm(forms.ModelForm): class Meta: model = Participants fields = ('reponse', 'details') widgets = { - 'details': forms.Textarea(attrs={"placeholder": "50 caractères max"}), + 'details': forms.Textarea( + attrs={"placeholder": "50 caractères max"}), } + class ChangeDoodleName(forms.ModelForm): def __init__(self, *args, **kwargs): super(ChangeDoodleName, self).__init__(*args, **kwargs) @@ -52,4 +75,3 @@ class ChangeDoodleName(forms.ModelForm): class Meta: model = ErnestoUser fields = ('doodlename',) - diff --git a/calendrier/migrations/0001_initial.py b/calendrier/migrations/0001_initial.py index 0fa96ad..aebc813 100644 --- a/calendrier/migrations/0001_initial.py +++ b/calendrier/migrations/0001_initial.py @@ -14,16 +14,21 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Event', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + primary_key=True, auto_created=True)), ('nom', models.CharField(max_length=100)), - ('nomcourt', models.CharField(verbose_name='Nom court', max_length=9)), + ('nomcourt', models.CharField(verbose_name='Nom court', + max_length=9)), ('date', models.DateField()), ('debut', models.TimeField()), ('fin', models.TimeField(blank=True, null=True)), - ('slug', models.CharField(max_length=7, editable=False, unique=True)), + ('slug', models.CharField(max_length=7, editable=False, + unique=True)), ('lieu', models.CharField(max_length=200)), ('description', models.TextField(blank=True)), - ('calendrier', models.BooleanField(verbose_name='Afficher dans le calendrier pour tous', default=False)), + ('calendrier', models.BooleanField( + verbose_name='Afficher dans le calendrier pour tous', + default=False)), ], options={ 'verbose_name': 'Événement', @@ -33,8 +38,14 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Participants', fields=[ - ('id', models.AutoField(verbose_name='ID', serialize=False, primary_key=True, auto_created=True)), - ('reponse', models.CharField(verbose_name='Réponse', choices=[('oui', 'Oui'), ('non', 'Non'), ('pe', 'Peut-être')], default='non', max_length=20)), + ('id', models.AutoField(verbose_name='ID', serialize=False, + primary_key=True, auto_created=True)), + ('reponse', models.CharField(verbose_name='Réponse', + choices=[ + ('oui', 'Oui'), + ('non', 'Non'), + ('pe', 'Peut-être')], + default='non', max_length=20)), ('details', models.CharField(blank=True, max_length=50)), ('event', models.ForeignKey(to='calendrier.Event')), ('participant', models.ForeignKey(to='gestion.ErnestoUser')), diff --git a/calendrier/migrations/0002_event_desc_users.py b/calendrier/migrations/0002_event_desc_users.py index 47eefb8..905f7ae 100644 --- a/calendrier/migrations/0002_event_desc_users.py +++ b/calendrier/migrations/0002_event_desc_users.py @@ -14,7 +14,10 @@ class Migration(migrations.Migration): migrations.AddField( model_name='event', name='desc_users', - field=models.TextField(null=True, verbose_name='Infos (visible seulement des fanfaron-ne-s)', blank=True), + field=models.TextField( + null=True, + verbose_name='Infos (visible seulement des fanfaron-ne-s)', + blank=True), preserve_default=True, ), ] diff --git a/calendrier/models.py b/calendrier/models.py index 18d34c4..96eb583 100644 --- a/calendrier/models.py +++ b/calendrier/models.py @@ -7,6 +7,7 @@ ANSWERS = ( ('pe', 'Peut-être'), ) + class Event(models.Model): nom = models.CharField(max_length=100) nomcourt = models.CharField(max_length=9, verbose_name="Nom court") @@ -16,8 +17,13 @@ class Event(models.Model): slug = models.CharField(max_length=7, editable=False, unique=True) lieu = models.CharField(max_length=200) description = models.TextField(blank=True) - desc_users = models.TextField(blank=True, verbose_name="Infos (visible seulement des fanfaron-ne-s)", null=True) - calendrier = models.BooleanField(default=False, verbose_name="Afficher dans le calendrier pour tous") + desc_users = models.TextField( + blank=True, + verbose_name="Infos (visible seulement des fanfaron-ne-s)", + null=True) + calendrier = models.BooleanField( + default=False, + verbose_name="Afficher dans le calendrier pour tous") def __str__(self): return self.nom @@ -25,10 +31,12 @@ class Event(models.Model): class Meta: verbose_name = "Événement" + class Participants(models.Model): event = models.ForeignKey(Event) participant = models.ForeignKey(ErnestoUser) - reponse = models.CharField("Réponse", max_length = 20, default = "non", choices = ANSWERS) + reponse = models.CharField("Réponse", max_length=20, default="non", + choices=ANSWERS) details = models.CharField(max_length=50, blank=True) # Create your models here. diff --git a/calendrier/templatetags/frenchmonth.py b/calendrier/templatetags/frenchmonth.py index ffc4b6b..12b1324 100644 --- a/calendrier/templatetags/frenchmonth.py +++ b/calendrier/templatetags/frenchmonth.py @@ -2,6 +2,7 @@ from django import template register = template.Library() + @register.filter def frenchmonth(tex): rep = tex @@ -21,7 +22,7 @@ def frenchmonth(tex): rep = "Juillet" if tex == "August": rep = "Août" - if tex == "September": + if tex == "September": rep = "Septembre" if tex == "October": rep = "Octobre" diff --git a/calendrier/templatetags/translate.py b/calendrier/templatetags/translate.py index f9093fc..64416bc 100644 --- a/calendrier/templatetags/translate.py +++ b/calendrier/templatetags/translate.py @@ -3,6 +3,7 @@ from django.utils.safestring import mark_safe register = template.Library() + @register.filter def translate(tex): tex = tex.replace("January", "Janvier", 1) diff --git a/calendrier/tests.py b/calendrier/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/calendrier/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/calendrier/urls.py b/calendrier/urls.py index 22a4723..606e5ee 100644 --- a/calendrier/urls.py +++ b/calendrier/urls.py @@ -1,7 +1,8 @@ from django.conf.urls import patterns, url from calendrier.views import EventUpdate, EventDelete -urlpatterns = patterns('calendrier.views', +urlpatterns = patterns( + 'calendrier.views', url(r'^new$', 'create_event'), url(r'^$', 'home'), url(r'^edition/(?P\d+)$', EventUpdate.as_view()), diff --git a/gestion/.admin.py.swp b/gestion/.admin.py.swp deleted file mode 100644 index 95ea267..0000000 Binary files a/gestion/.admin.py.swp and /dev/null differ diff --git a/gestion/.models.py.swp b/gestion/.models.py.swp deleted file mode 100644 index 1efcb2b..0000000 Binary files a/gestion/.models.py.swp and /dev/null differ diff --git a/gestion/admin.py b/gestion/admin.py index 1920c5c..4c537e1 100644 --- a/gestion/admin.py +++ b/gestion/admin.py @@ -4,9 +4,11 @@ from gestion.models import ErnestoUser from django.contrib.auth.admin import UserAdmin from calendrier.models import Event + class UserProfileInline(admin.StackedInline): model = ErnestoUser - + + def ProfileInfo(field, short_description, boolean=False): def getter(self): try: @@ -23,16 +25,21 @@ User.profile_is_ern = ProfileInfo("is_ernesto", "Ernestophoniste") User.profile_is_chef = ProfileInfo("is_chef", "Chef Fanfare") User.profile_get_mails = ProfileInfo("mails", "Recevoir les mails") + class UserProfileAdmin(UserAdmin): - list_display = ('username', 'first_name', 'last_name', 'email', 'profile_phone', 'profile_instru', 'profile_is_ern', 'profile_is_chef',) + list_display = ('username', 'first_name', 'last_name', 'email', + 'profile_phone', 'profile_instru', 'profile_is_ern', + 'profile_is_chef',) list_display_links = ('username', 'email', 'first_name', 'last_name',) list_filter = ('profile__instru',) ordering = ('username',) - search_fields = ('username', 'first_name', 'last_name', 'profile__phone', 'profile__instru',) - inlines = [ UserProfileInline, ] - fieldsets = (('Général', { 'fields': ('username', 'password', 'first_name', 'last_name', ) }), - ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser' )}) -) + search_fields = ('username', 'first_name', 'last_name', 'profile__phone', + 'profile__instru',) + inlines = [UserProfileInline, ] + fieldsets = (('Général', {'fields': ('username', 'password', 'first_name', + 'last_name', )}), + ('Permissions', {'fields': ('is_active', 'is_staff', + 'is_superuser')})) admin.site.unregister(User) diff --git a/gestion/admin.pyc b/gestion/admin.pyc deleted file mode 100644 index 9dd3570..0000000 Binary files a/gestion/admin.pyc and /dev/null differ diff --git a/gestion/forms.py b/gestion/forms.py index d90a311..df0eb3d 100644 --- a/gestion/forms.py +++ b/gestion/forms.py @@ -1,19 +1,24 @@ from django import forms from gestion.models import ErnestoUser from django.contrib.auth.models import User -from django.contrib.auth.forms import UserCreationForm, UserChangeForm +from django.contrib.auth.forms import UserCreationForm + class RegistrationFormUser(UserCreationForm): class Meta: model = User - fields = ('username', 'first_name', 'last_name', 'password1', 'password2', 'email',) + fields = ('username', 'first_name', 'last_name', 'password1', + 'password2', 'email',) + class InscriptionMembreForm(forms.ModelForm): validation = forms.CharField(max_length=100, widget=forms.PasswordInput) + class Meta: model = ErnestoUser fields = ("phone", "instru", ) + class ChangeMembreForm(forms.ModelForm): first_name = forms.CharField(max_length=30, required=False) last_name = forms.CharField(max_length=50, required=False) diff --git a/gestion/migrations/0001_initial.py b/gestion/migrations/0001_initial.py index df53c3d..db24536 100644 --- a/gestion/migrations/0001_initial.py +++ b/gestion/migrations/0001_initial.py @@ -15,11 +15,19 @@ class Migration(migrations.Migration): migrations.CreateModel( name='ErnestoUser', fields=[ - ('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')), - ('is_ernesto', models.BooleanField(default=True, verbose_name="Membre de l'Ernestophone")), - ('is_chef', models.BooleanField(default=False, verbose_name='Chef Fanfare')), - ('phone', models.CharField(max_length=20, verbose_name='Telephone', blank=True)), - ('instru', models.CharField(max_length=40, verbose_name='Instrument joué', blank=True)), + ('id', models.AutoField(auto_created=True, serialize=False, + primary_key=True, verbose_name='ID')), + ('is_ernesto', models.BooleanField( + default=True, + verbose_name="Membre de l'Ernestophone")), + ('is_chef', models.BooleanField(default=False, + verbose_name='Chef Fanfare')), + ('phone', models.CharField(max_length=20, + verbose_name='Telephone', + blank=True)), + ('instru', models.CharField(max_length=40, + verbose_name='Instrument joué', + blank=True)), ('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)), ], options={ diff --git a/gestion/migrations/0002_auto_20150413_1705.py b/gestion/migrations/0002_auto_20150413_1705.py index ecee72b..bf0684c 100644 --- a/gestion/migrations/0002_auto_20150413_1705.py +++ b/gestion/migrations/0002_auto_20150413_1705.py @@ -15,11 +15,13 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='ernestouser', name='phone', - field=models.CharField(max_length=20, blank=True, verbose_name='Téléphone'), + field=models.CharField(max_length=20, blank=True, + verbose_name='Téléphone'), ), migrations.AlterField( model_name='ernestouser', name='user', - field=models.OneToOneField(to=settings.AUTH_USER_MODEL, related_name='profile'), + field=models.OneToOneField(to=settings.AUTH_USER_MODEL, + related_name='profile'), ), ] diff --git a/gestion/migrations/0003_auto_20151014_1904.py b/gestion/migrations/0003_auto_20151014_1904.py index bdd9ee4..e3157ac 100644 --- a/gestion/migrations/0003_auto_20151014_1904.py +++ b/gestion/migrations/0003_auto_20151014_1904.py @@ -13,18 +13,21 @@ class Migration(migrations.Migration): operations = [ migrations.AlterModelOptions( name='ernestouser', - options={'verbose_name_plural': 'Profil Ernestophoniste', 'verbose_name': 'Profil Ernestophoniste'}, + options={'verbose_name_plural': 'Profil Ernestophoniste', + 'verbose_name': 'Profil Ernestophoniste'}, ), migrations.AddField( model_name='ernestouser', name='doodlename', - field=models.CharField(max_length=30, default='afafa', blank=True, verbose_name='Nom pour le doodle'), + field=models.CharField(max_length=30, default='afafa', blank=True, + verbose_name='Nom pour le doodle'), preserve_default=False, ), migrations.AddField( model_name='ernestouser', name='slug', - field=models.CharField(max_length=7, default='fafafa', editable=False, unique=True), + field=models.CharField(max_length=7, default='fafafa', + editable=False, unique=True), preserve_default=False, ), ] diff --git a/gestion/migrations/0004_ernestouser_mails.py b/gestion/migrations/0004_ernestouser_mails.py index fe1825f..79a3944 100644 --- a/gestion/migrations/0004_ernestouser_mails.py +++ b/gestion/migrations/0004_ernestouser_mails.py @@ -14,7 +14,8 @@ class Migration(migrations.Migration): migrations.AddField( model_name='ernestouser', name='mails', - field=models.BooleanField(default=True, verbose_name='Recevoir les mails'), + field=models.BooleanField(default=True, + verbose_name='Recevoir les mails'), preserve_default=True, ), ] diff --git a/gestion/models.py b/gestion/models.py index 00d0abc..851fcba 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -3,14 +3,16 @@ from django.db import models from django.contrib.auth.models import User + class ErnestoUser(models.Model): - user = models.OneToOneField(User, related_name = "profile") + user = models.OneToOneField(User, related_name="profile") is_ernesto = models.BooleanField("Membre de l'Ernestophone", default=True) is_chef = models.BooleanField("Chef Fanfare", default=False) phone = models.CharField("Téléphone", max_length=20, blank=True) instru = models.CharField("Instrument joué", max_length=40, blank=True) slug = models.CharField(max_length=7, editable=False, unique=True) - doodlename = models.CharField("Nom pour le doodle", max_length=30, blank=True) + doodlename = models.CharField("Nom pour le doodle", max_length=30, + blank=True) mails = models.BooleanField("Recevoir les mails", default=True) class Meta: diff --git a/gestion/tests.py b/gestion/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/gestion/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/gestion/views.py b/gestion/views.py index dfe671d..3acdcfe 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -1,21 +1,19 @@ -from django.shortcuts import render, redirect +from django.shortcuts import render from django.contrib.auth.views import login as django_login_view from django.contrib.auth.models import User -from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm +from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.decorators import login_required -from email.mime.multipart import MIMEMultipart -from email.mime.text import MIMEText +from datetime import datetime -from datetime import * -import smtplib - -from gestion.forms import InscriptionMembreForm, RegistrationFormUser, ChangeMembreForm +from gestion.forms import InscriptionMembreForm, RegistrationFormUser, \ + ChangeMembreForm from gestion.models import ErnestoUser from propositions.utils import generer from calendrier.views import calendar + def inscription_membre(request): if request.method == 'POST': requbis = request.POST.copy() @@ -33,12 +31,13 @@ def inscription_membre(request): try: ErnestoUser.objects.get(slug=code) except: - temp=False + temp = False member.save() - (profile, _) = ErnestoUser.objects.get_or_create(user = member, slug=code) - comp_form = InscriptionMembreForm(requbis, instance = profile) + (profile, _) = ErnestoUser.objects.get_or_create(user=member, + slug=code) + comp_form = InscriptionMembreForm(requbis, instance=profile) obj = comp_form.save(commit=False) - obj.slug=code + obj.slug = code obj.save() envoi = True return render(request, 'gestion/thanks.html', locals()) @@ -47,6 +46,7 @@ def inscription_membre(request): user_form = RegistrationFormUser() return render(request, 'gestion/registration.html', locals()) + @login_required def change_password(request): if request.method == 'POST': @@ -59,34 +59,39 @@ def change_password(request): form = PasswordChangeForm(request.user) return render(request, 'gestion/changepasswd.html', locals()) + @login_required def change_membre(request): if request.method == 'POST': - requbis=request.POST.copy() - form = ChangeMembreForm(requbis, instance = request.user) + requbis = request.POST.copy() + form = ChangeMembreForm(requbis, instance=request.user) if form.is_valid(): form.save() - success=True + success = True else: form = ChangeMembreForm(instance=request.user) return render(request, 'gestion/change.html', locals()) + def home(request): lToday = datetime.now() return calendar(request, lToday.year, lToday.month) + def login(request): if request.method == "POST" and "username" in request.POST: try: - user = User.objects.get(username = request.POST["username"]) + user = User.objects.get(username=request.POST["username"]) if not user.is_active: error = "Votre compte n'est pas actif" return render(request, "gestion/login.html", locals()) if not user.has_usable_password() or user.password in ("", "!"): - return render(request, "error.html", {"error_type": "no_password"}) + return render(request, "error.html", + {"error_type": "no_password"}) except User.DoesNotExist: pass - return django_login_view(request, template_name = 'login.html', ) + return django_login_view(request, template_name='login.html') + @login_required def divers(request): diff --git a/pads/admin.py b/pads/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/pads/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/pads/forms.py b/pads/forms.py index 6302ae5..61adf1e 100644 --- a/pads/forms.py +++ b/pads/forms.py @@ -1,6 +1,7 @@ from django import forms from pads.models import Pad + class PadForm(forms.ModelForm): class Meta: model = Pad diff --git a/pads/migrations/0001_initial.py b/pads/migrations/0001_initial.py index 5f33b55..92bea97 100644 --- a/pads/migrations/0001_initial.py +++ b/pads/migrations/0001_initial.py @@ -13,7 +13,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Pad', fields=[ - ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)), + ('id', models.AutoField(verbose_name='ID', primary_key=True, + auto_created=True, serialize=False)), ('nom', models.CharField(max_length=100)), ('url', models.URLField()), ('date', models.DateField(verbose_name='Créé le')), diff --git a/pads/models.py b/pads/models.py index 207feeb..db0d967 100644 --- a/pads/models.py +++ b/pads/models.py @@ -4,11 +4,11 @@ from django.db import models class Pad(models.Model): nom = models.CharField(max_length=100) url = models.URLField() - date = models.DateField(verbose_name="Créé le") + date = models.DateField(verbose_name="Créé le") def __str__(self): return self.nom class Meta: - verbose_name="Pad" + verbose_name = "Pad" # Create your models here. diff --git a/pads/tests.py b/pads/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/pads/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/pads/urls.py b/pads/urls.py index fc772f9..e325058 100644 --- a/pads/urls.py +++ b/pads/urls.py @@ -1,7 +1,9 @@ from django.conf.urls import patterns, url from pads.views import PadUpdate, PadDelete -urlpatterns = patterns('pads.views', + +urlpatterns = patterns( + 'pads.views', url(r'^$', 'liste_pads'), url(r'^ajouter$', 'add_pad'), url(r'^edition/(?P\d+)$', PadUpdate.as_view()), diff --git a/pads/views.py b/pads/views.py index 3b09eb1..d0f0344 100644 --- a/pads/views.py +++ b/pads/views.py @@ -10,11 +10,13 @@ from pads.forms import PadForm from partitions.decorators import chef_required + @login_required def liste_pads(request): pads = Pad.objects.all().order_by("-date") return render(request, "pads/liste.html", locals()) + @chef_required def add_pad(request): if request.method == "POST": @@ -28,15 +30,17 @@ def add_pad(request): form = PadForm() return render(request, "pads/create.html", locals()) + class PadUpdate(UpdateView): model = Pad - template_name="pads/update.html" - success_url=reverse_lazy(liste_pads) + template_name = "pads/update.html" + success_url = reverse_lazy(liste_pads) @method_decorator(chef_required) def dispatch(self, *args, **kwargs): return super(PadUpdate, self).dispatch(*args, **kwargs) + class PadDelete(DeleteView): model = Pad template_name = "pads/delete.html" diff --git a/partitions/admin.py b/partitions/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/partitions/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/partitions/decorators.py b/partitions/decorators.py index 3b0dcc2..50a7ea9 100644 --- a/partitions/decorators.py +++ b/partitions/decorators.py @@ -1,5 +1,6 @@ from django.contrib.auth.decorators import user_passes_test + def is_chef(user): try: profile = user.profile diff --git a/partitions/forms.py b/partitions/forms.py index f0b50ae..0fe9bb9 100644 --- a/partitions/forms.py +++ b/partitions/forms.py @@ -1,10 +1,11 @@ from django import forms + class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField() + class UploadMorceauForm(forms.Form): titre = forms.CharField(max_length=100) auteur = forms.CharField(max_length=100) - diff --git a/partitions/migrations/0001_initial.py b/partitions/migrations/0001_initial.py index 1356b49..06abb6a 100644 --- a/partitions/migrations/0001_initial.py +++ b/partitions/migrations/0001_initial.py @@ -13,7 +13,8 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Partition', fields=[ - ('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')), + ('id', models.AutoField(auto_created=True, serialize=False, + primary_key=True, verbose_name='ID')), ('nom', models.CharField(max_length=100)), ('part', models.FileField(upload_to='partitions/')), ], diff --git a/partitions/migrations/0002_partitionset.py b/partitions/migrations/0002_partitionset.py index 2325abc..e067289 100644 --- a/partitions/migrations/0002_partitionset.py +++ b/partitions/migrations/0002_partitionset.py @@ -14,10 +14,12 @@ class Migration(migrations.Migration): migrations.CreateModel( name='PartitionSet', fields=[ - ('id', models.AutoField(primary_key=True, verbose_name='ID', auto_created=True, serialize=False)), + ('id', models.AutoField(primary_key=True, verbose_name='ID', + auto_created=True, serialize=False)), ('nom', models.CharField(max_length=100)), ('auteur', models.CharField(max_length=100)), - ('pupitres', models.ManyToManyField(to='partitions.Partition')), + ('pupitres', models.ManyToManyField( + to='partitions.Partition')), ], options={ }, diff --git a/partitions/migrations/0004_remove_partition_morceau.py b/partitions/migrations/0004_remove_partition_morceau.py index 2124470..67cdc89 100644 --- a/partitions/migrations/0004_remove_partition_morceau.py +++ b/partitions/migrations/0004_remove_partition_morceau.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations class Migration(migrations.Migration): diff --git a/partitions/migrations/0006_partitionset_category_and_infos.py b/partitions/migrations/0006_partitionset_category_and_infos.py index 9e53a56..c5ff556 100644 --- a/partitions/migrations/0006_partitionset_category_and_infos.py +++ b/partitions/migrations/0006_partitionset_category_and_infos.py @@ -14,13 +14,20 @@ class Migration(migrations.Migration): migrations.AddField( model_name='partitionset', name='category', - field=models.CharField(choices=[('active', 'Actif'), ('incoming', 'À venir'), ('old', 'Archive')], max_length=8, verbose_name='Types de partitions', default='incoming'), + field=models.CharField(choices=[ + ('active', 'Actif'), + ('incoming', 'À venir'), + ('old', 'Archive')], + max_length=8, + verbose_name='Types de partitions', + default='incoming'), preserve_default=True, ), migrations.AddField( model_name='partitionset', name='infos', - field=models.TextField(null=True, blank=True, verbose_name='Infos utiles'), + field=models.TextField(null=True, blank=True, + verbose_name='Infos utiles'), preserve_default=True, ), ] diff --git a/partitions/models.py b/partitions/models.py index 2f79474..33b07cf 100644 --- a/partitions/models.py +++ b/partitions/models.py @@ -9,6 +9,7 @@ PARTITION_TYPES = ( ("old", "Archive"), ) + class Partition(models.Model): nom = models.CharField(max_length=100) part = models.FileField(upload_to="partitions/") @@ -18,17 +19,18 @@ class Partition(models.Model): return self.nom def delete(self, *args, **kwargs): - os.remove(os.path.join(Ernestophone.settings.MEDIA_ROOT, self.part.name)) + os.remove(os.path.join(Ernestophone.settings.MEDIA_ROOT, + self.part.name)) super(Partition, self).delete(*args, **kwargs) + class PartitionSet(models.Model): nom = models.CharField(max_length=100) auteur = models.CharField(max_length=100) category = models.CharField('Types de partitions', max_length=8, - choices=PARTITION_TYPES, default="incoming") + choices=PARTITION_TYPES, default="incoming") infos = models.TextField("Infos utiles", null=True, blank=True) def __str__(self): return("%s - %s [%s]" % (self.nom, self.auteur, - self.get_category_display())) - + self.get_category_display())) diff --git a/partitions/tests.py b/partitions/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/partitions/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/partitions/urls.py b/partitions/urls.py index bf5fe2a..6a7917b 100644 --- a/partitions/urls.py +++ b/partitions/urls.py @@ -1,14 +1,19 @@ from django.conf.urls import patterns, url -urlpatterns = patterns('partitions.views', +urlpatterns = patterns( + 'partitions.views', url(r'^$', 'liste'), url(r'^(?P[^/]+)/(?P[^/]+)/?$', 'listepart'), url(r'^(?P[^/]+)/(?P[^/]+)/upload/?$', 'upload'), url(r'^(?P[^/]+)/(?P[^/]+)/delete/?$', 'delete_morc'), url(r'^(?P[^/]+)/(?P[^/]+)/conf/?$', 'conf_delete_morc'), - url(r'^(?P[^/]+)/(?P[^/]+)/see/(?P\d+)/?$', 'see'), - url(r'^(?P[^/]+)/(?P[^/]+)/(?P\d+)/$', 'download'), - url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/delete/?$', 'delete'), - url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/conf/?$', 'conf_delete'), + url(r'^(?P[^/]+)/(?P[^/]+)/see/(?P\d+)/?$', + 'see'), + url(r'^(?P[^/]+)/(?P[^/]+)/(?P\d+)/$', + 'download'), + url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/delete/?$', + 'delete'), + url(r'^(?P[^/]+)/(?P[^/]+)/(?P[^/]+)/conf/?$', + 'conf_delete'), url(r'^new/?$', 'ajouter_morceau'), ) diff --git a/propositions/admin.py b/propositions/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/propositions/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/propositions/forms.py b/propositions/forms.py index 1d6ef95..d3cff7c 100644 --- a/propositions/forms.py +++ b/propositions/forms.py @@ -1,6 +1,7 @@ from django import forms from propositions.models import Prop + class PropForm(forms.ModelForm): class Meta: model = Prop @@ -9,4 +10,4 @@ class PropForm(forms.ModelForm): 'lien': forms.TextInput(attrs={"placeholder": "facultatif"}), 'nom': forms.TextInput(attrs={"placeholder": "Nom du morceau"}), 'artiste': forms.TextInput(attrs={"placeholder": "facultatif"}), - } + } diff --git a/propositions/models.py b/propositions/models.py index fedc48e..edfc240 100644 --- a/propositions/models.py +++ b/propositions/models.py @@ -6,9 +6,10 @@ REP = ( ('non', 'Non'), ) + class Prop(models.Model): - nom = models.CharField(max_length=100) - artiste = models.CharField(blank=True, max_length=100) + 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") @@ -18,12 +19,13 @@ class Prop(models.Model): return self.nom class Meta: - verbose_name="Proposition" - + 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) + reponse = models.CharField("Réponse", max_length=20, blank=True, + choices=REP) # Create your models here. - diff --git a/propositions/templatetags/getresponse.py b/propositions/templatetags/getresponse.py index 83378c3..941e016 100644 --- a/propositions/templatetags/getresponse.py +++ b/propositions/templatetags/getresponse.py @@ -3,6 +3,7 @@ from propositions.models import Reponses register = template.Library() + @register.inclusion_tag("propositions/reponse.html") def getresponse(user, prop): try: diff --git a/propositions/tests.py b/propositions/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/propositions/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/propositions/urls.py b/propositions/urls.py index 85282de..ae0aa70 100644 --- a/propositions/urls.py +++ b/propositions/urls.py @@ -1,7 +1,8 @@ from django.conf.urls import patterns, url from propositions.views import PropDelete -urlpatterns = patterns('propositions.views', +urlpatterns = patterns( + 'propositions.views', url(r'^$', 'liste'), url(r'^new/?$', 'create_prop'), url(r'^(?P\d+)/oui/?$', 'repoui'), diff --git a/propositions/utils.py b/propositions/utils.py index c4d5797..fb81d5b 100644 --- a/propositions/utils.py +++ b/propositions/utils.py @@ -1,6 +1,7 @@ import string import random + def generer(*args): caracteres = string.ascii_letters + string.digits aleatoire = [random.choice(caracteres) for _ in range(6)] diff --git a/propositions/views.py b/propositions/views.py index f27c51e..44a7055 100644 --- a/propositions/views.py +++ b/propositions/views.py @@ -9,6 +9,7 @@ from propositions.forms import PropForm from propositions.models import Prop from propositions.models import Reponses + @login_required def create_prop(request): if request.method == "POST": @@ -24,12 +25,14 @@ def create_prop(request): 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) @@ -39,7 +42,7 @@ def repoui(request, id): if p.reponse == "oui": prop.nboui -= 1 else: - prop.nbnon-=1 + prop.nbnon -= 1 p.delete() except Reponses.DoesNotExist: pass @@ -50,26 +53,29 @@ def repoui(request, id): rep.save() prop.nboui += 1 prop.save() - return redirect('propositions.views.liste') + return redirect('propositions.views.liste') + class PropDelete(DeleteView): model = Prop - template_name= "propositions/delete.html" + 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) + 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): + 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 test(request, pk): error = "Connard" @@ -77,6 +83,7 @@ def test(request, pk): return redirect(PropDelete.as_view()) return render(request, "propositions/liste.html", locals()) + @login_required def repnon(request, id): prop = Prop.objects.get(id=id)