forked from DGNum/gestioCOF
Remove the num field in CofProfile
This commit is contained in:
parent
76dcaf7d51
commit
dba8a0a857
5 changed files with 28 additions and 33 deletions
|
@ -132,7 +132,6 @@ def ProfileInfo(field, short_description, boolean=False):
|
||||||
|
|
||||||
User.profile_login_clipper = FkeyLookup("profile__login_clipper",
|
User.profile_login_clipper = FkeyLookup("profile__login_clipper",
|
||||||
"Login clipper")
|
"Login clipper")
|
||||||
User.profile_num = FkeyLookup("profile__num", "Numéro")
|
|
||||||
User.profile_phone = ProfileInfo("phone", "Téléphone")
|
User.profile_phone = ProfileInfo("phone", "Téléphone")
|
||||||
User.profile_occupation = ProfileInfo("occupation", "Occupation")
|
User.profile_occupation = ProfileInfo("occupation", "Occupation")
|
||||||
User.profile_departement = ProfileInfo("departement", "Departement")
|
User.profile_departement = ProfileInfo("departement", "Departement")
|
||||||
|
@ -159,10 +158,12 @@ class UserProfileAdmin(UserAdmin):
|
||||||
is_cof.short_description = 'Membre du COF'
|
is_cof.short_description = 'Membre du COF'
|
||||||
is_cof.boolean = True
|
is_cof.boolean = True
|
||||||
|
|
||||||
list_display = ('profile_num',) + UserAdmin.list_display \
|
list_display = (
|
||||||
|
UserAdmin.list_display
|
||||||
+ ('profile_login_clipper', 'profile_phone', 'profile_occupation',
|
+ ('profile_login_clipper', 'profile_phone', 'profile_occupation',
|
||||||
'profile_mailing_cof', 'profile_mailing_bda',
|
'profile_mailing_cof', 'profile_mailing_bda',
|
||||||
'profile_mailing_bda_revente', 'is_cof', 'is_buro', )
|
'profile_mailing_bda_revente', 'is_cof', 'is_buro', )
|
||||||
|
)
|
||||||
list_display_links = ('username', 'email', 'first_name', 'last_name')
|
list_display_links = ('username', 'email', 'first_name', 'last_name')
|
||||||
list_filter = UserAdmin.list_filter \
|
list_filter = UserAdmin.list_filter \
|
||||||
+ ('profile__is_cof', 'profile__is_buro', 'profile__mailing_cof',
|
+ ('profile__is_cof', 'profile__is_buro', 'profile__mailing_cof',
|
||||||
|
|
|
@ -3,13 +3,11 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.forms.widgets import RadioSelect, CheckboxSelectMultiple
|
from django.forms.widgets import RadioSelect, CheckboxSelectMultiple
|
||||||
from django.forms.formsets import BaseFormSet, formset_factory
|
from django.forms.formsets import BaseFormSet, formset_factory
|
||||||
from django.db.models import Max
|
|
||||||
from django.core.validators import MinLengthValidator
|
from django.core.validators import MinLengthValidator
|
||||||
|
|
||||||
from gestioncof.models import CofProfile, EventCommentValue, \
|
from gestioncof.models import CofProfile, EventCommentValue, \
|
||||||
CalendarSubscription, Club
|
CalendarSubscription, Club
|
||||||
from gestioncof.widgets import TriStateCheckbox
|
from gestioncof.widgets import TriStateCheckbox
|
||||||
from gestioncof.shared import lock_table, unlock_table
|
|
||||||
|
|
||||||
from bda.models import Spectacle
|
from bda.models import Spectacle
|
||||||
|
|
||||||
|
@ -237,7 +235,6 @@ class RegistrationProfileForm(forms.ModelForm):
|
||||||
self.fields['mailing_cof'].initial = True
|
self.fields['mailing_cof'].initial = True
|
||||||
self.fields['mailing_bda'].initial = True
|
self.fields['mailing_bda'].initial = True
|
||||||
self.fields['mailing_bda_revente'].initial = True
|
self.fields['mailing_bda_revente'].initial = True
|
||||||
self.fields['num'].widget.attrs['readonly'] = True
|
|
||||||
|
|
||||||
self.fields.keyOrder = [
|
self.fields.keyOrder = [
|
||||||
'login_clipper',
|
'login_clipper',
|
||||||
|
@ -245,7 +242,6 @@ class RegistrationProfileForm(forms.ModelForm):
|
||||||
'occupation',
|
'occupation',
|
||||||
'departement',
|
'departement',
|
||||||
'is_cof',
|
'is_cof',
|
||||||
'num',
|
|
||||||
'type_cotiz',
|
'type_cotiz',
|
||||||
'mailing_cof',
|
'mailing_cof',
|
||||||
'mailing_bda',
|
'mailing_bda',
|
||||||
|
@ -253,24 +249,9 @@ class RegistrationProfileForm(forms.ModelForm):
|
||||||
'comments'
|
'comments'
|
||||||
]
|
]
|
||||||
|
|
||||||
def save(self, *args, **kw):
|
|
||||||
instance = super(RegistrationProfileForm, self).save(*args, **kw)
|
|
||||||
if instance.is_cof and not instance.num:
|
|
||||||
# Generate new number
|
|
||||||
try:
|
|
||||||
lock_table(CofProfile)
|
|
||||||
aggregate = CofProfile.objects.aggregate(Max('num'))
|
|
||||||
instance.num = aggregate['num__max'] + 1
|
|
||||||
instance.save()
|
|
||||||
self.cleaned_data['num'] = instance.num
|
|
||||||
self.data['num'] = instance.num
|
|
||||||
finally:
|
|
||||||
unlock_table(CofProfile)
|
|
||||||
return instance
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CofProfile
|
model = CofProfile
|
||||||
fields = ("login_clipper", "num", "phone", "occupation",
|
fields = ("login_clipper", "phone", "occupation",
|
||||||
"departement", "is_cof", "type_cotiz", "mailing_cof",
|
"departement", "is_cof", "type_cotiz", "mailing_cof",
|
||||||
"mailing_bda", "mailing_bda_revente", "comments")
|
"mailing_bda", "mailing_bda_revente", "comments")
|
||||||
|
|
||||||
|
|
18
gestioncof/migrations/0011_remove_cofprofile_num.py
Normal file
18
gestioncof/migrations/0011_remove_cofprofile_num.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('gestioncof', '0010_delete_custommail'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='cofprofile',
|
||||||
|
name='num',
|
||||||
|
),
|
||||||
|
]
|
|
@ -35,7 +35,6 @@ class CofProfile(models.Model):
|
||||||
user = models.OneToOneField(User, related_name="profile")
|
user = models.OneToOneField(User, related_name="profile")
|
||||||
login_clipper = models.CharField("Login clipper", max_length=8, blank=True)
|
login_clipper = models.CharField("Login clipper", max_length=8, blank=True)
|
||||||
is_cof = models.BooleanField("Membre du COF", default=False)
|
is_cof = models.BooleanField("Membre du COF", default=False)
|
||||||
num = models.IntegerField("Numéro d'adhérent", blank=True, default=0)
|
|
||||||
phone = models.CharField("Téléphone", max_length=20, blank=True)
|
phone = models.CharField("Téléphone", max_length=20, blank=True)
|
||||||
occupation = models.CharField(_("Occupation"),
|
occupation = models.CharField(_("Occupation"),
|
||||||
default="1A",
|
default="1A",
|
||||||
|
|
|
@ -400,9 +400,6 @@ def registration_form2(request, login_clipper=None, username=None,
|
||||||
def registration(request):
|
def registration(request):
|
||||||
if request.POST:
|
if request.POST:
|
||||||
request_dict = request.POST.copy()
|
request_dict = request.POST.copy()
|
||||||
# num ne peut pas être défini manuellement
|
|
||||||
if "num" in request_dict:
|
|
||||||
del request_dict["num"]
|
|
||||||
member = None
|
member = None
|
||||||
login_clipper = None
|
login_clipper = None
|
||||||
success = False
|
success = False
|
||||||
|
@ -442,7 +439,6 @@ def registration(request):
|
||||||
member = user_form.save()
|
member = user_form.save()
|
||||||
profile, _ = CofProfile.objects.get_or_create(user=member)
|
profile, _ = CofProfile.objects.get_or_create(user=member)
|
||||||
was_cof = profile.is_cof
|
was_cof = profile.is_cof
|
||||||
request_dict["num"] = profile.num
|
|
||||||
# Maintenant on remplit le formulaire de profil
|
# Maintenant on remplit le formulaire de profil
|
||||||
profile_form = RegistrationProfileForm(request_dict,
|
profile_form = RegistrationProfileForm(request_dict,
|
||||||
instance=profile)
|
instance=profile)
|
||||||
|
@ -500,11 +496,11 @@ def registration(request):
|
||||||
# Messages
|
# Messages
|
||||||
if success:
|
if success:
|
||||||
msg = ("L'inscription de {:s} (<tt>{:s}</tt>) a été "
|
msg = ("L'inscription de {:s} (<tt>{:s}</tt>) a été "
|
||||||
"enregistrée avec succès"
|
"enregistrée avec succès."
|
||||||
.format(member.get_full_name(), member.email))
|
.format(member.get_full_name(), member.email))
|
||||||
if member.profile.is_cof:
|
if member.profile.is_cof:
|
||||||
msg += "Il est désormais membre du COF n°{:d} !".format(
|
msg += "\nIl est désormais membre du COF n°{:d} !".format(
|
||||||
member.profile.num)
|
member.profile.id)
|
||||||
messages.success(request, msg, extra_tags='safe')
|
messages.success(request, msg, extra_tags='safe')
|
||||||
return render(request, "gestioncof/registration_post.html",
|
return render(request, "gestioncof/registration_post.html",
|
||||||
{"user_form": user_form,
|
{"user_form": user_form,
|
||||||
|
@ -569,7 +565,7 @@ def export_members(request):
|
||||||
writer = unicodecsv.writer(response)
|
writer = unicodecsv.writer(response)
|
||||||
for profile in CofProfile.objects.filter(is_cof=True).all():
|
for profile in CofProfile.objects.filter(is_cof=True).all():
|
||||||
user = profile.user
|
user = profile.user
|
||||||
bits = [profile.num, user.username, user.first_name, user.last_name,
|
bits = [profile.id, user.username, user.first_name, user.last_name,
|
||||||
user.email, profile.phone, profile.occupation,
|
user.email, profile.phone, profile.occupation,
|
||||||
profile.departement, profile.type_cotiz]
|
profile.departement, profile.type_cotiz]
|
||||||
writer.writerow([str(bit) for bit in bits])
|
writer.writerow([str(bit) for bit in bits])
|
||||||
|
@ -588,7 +584,7 @@ def csv_export_mega(filename, qs):
|
||||||
comments = "---".join(
|
comments = "---".join(
|
||||||
[comment.content for comment in reg.comments.all()])
|
[comment.content for comment in reg.comments.all()])
|
||||||
bits = [user.username, user.first_name, user.last_name, user.email,
|
bits = [user.username, user.first_name, user.last_name, user.email,
|
||||||
profile.phone, profile.num,
|
profile.phone, profile.id,
|
||||||
profile.comments if profile.comments else "", comments]
|
profile.comments if profile.comments else "", comments]
|
||||||
|
|
||||||
writer.writerow([str(bit) for bit in bits])
|
writer.writerow([str(bit) for bit in bits])
|
||||||
|
@ -610,7 +606,7 @@ def export_mega_remarksonly(request):
|
||||||
user = reg.user
|
user = reg.user
|
||||||
profile = user.profile
|
profile = user.profile
|
||||||
bits = [user.username, user.first_name, user.last_name, user.email,
|
bits = [user.username, user.first_name, user.last_name, user.email,
|
||||||
profile.phone, profile.num, profile.comments, val.content]
|
profile.phone, profile.id, profile.comments, val.content]
|
||||||
writer.writerow([str(bit) for bit in bits])
|
writer.writerow([str(bit) for bit in bits])
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
Loading…
Add table
Reference in a new issue