forked from DGNum/gestioCOF
2786f834a5
- General : - Ajout de la gestion des messages dans le template base - jQuery et bootstrap ajoutés au template base - Ajout de DateTimeWidget utilisant bootstrap-datetimepicker pour les champs DateTime - Account : - Ajout de propriétés aux modèles pour accéder directement à certains éléments sans avoir à passer par les relations - Suppression d'une méthode inutile dans le modèle - Correction de permission dans la vue update - Utilisation des messages pour la création et l'édition d'un compte - Checkout : - gestion initiale CRU
96 lines
2.5 KiB
Python
96 lines
2.5 KiB
Python
from django import forms
|
|
from django.contrib.auth.models import User
|
|
from kfet.models import Account, Checkout
|
|
from gestioncof.models import CofProfile
|
|
|
|
# -----
|
|
# Widgets
|
|
# -----
|
|
|
|
class DateTimeWidget(forms.DateTimeInput):
|
|
def __init__(self, attrs = None):
|
|
super(DateTimeWidget, self).__init__(attrs)
|
|
self.attrs['format'] = '%Y-%m-%d %H:%M'
|
|
class Media:
|
|
css = {
|
|
'all': ('bootstrap-datetimepicker.min.css',)
|
|
}
|
|
js = (
|
|
'moment.js',
|
|
'moment-fr.js',
|
|
'bootstrap-datetimepicker.min.js',
|
|
)
|
|
# -----
|
|
# Account forms
|
|
# -----
|
|
|
|
class AccountForm(forms.ModelForm):
|
|
|
|
# Surcharge pour passer data à Account.save()
|
|
def save(self, data = {}, *args, **kwargs):
|
|
obj = super(AccountForm, self).save(commit = False, *args, **kwargs)
|
|
obj.save(data = data)
|
|
return obj
|
|
|
|
class Meta:
|
|
model = Account
|
|
fields = ['trigramme', 'promo', 'nickname']
|
|
widgets = {
|
|
'trigramme': forms.TextInput(attrs={'autocomplete': 'off'}),
|
|
}
|
|
|
|
class AccountTriForm(AccountForm):
|
|
class Meta(AccountForm.Meta):
|
|
fields = ['trigramme']
|
|
|
|
class AccountNoTriForm(AccountForm):
|
|
class Meta(AccountForm.Meta):
|
|
exclude = ['trigramme']
|
|
|
|
class AccountRestrictForm(AccountForm):
|
|
class Meta(AccountForm.Meta):
|
|
fields = ['promo']
|
|
|
|
class CofForm(forms.ModelForm):
|
|
def clean_is_cof(self):
|
|
instance = getattr(self, 'instance', None)
|
|
if instance and instance.pk:
|
|
return instance.is_cof
|
|
else:
|
|
return False
|
|
class Meta:
|
|
model = CofProfile
|
|
fields = ['login_clipper', 'is_cof', 'departement']
|
|
|
|
class CofRestrictForm(CofForm):
|
|
class Meta(CofForm.Meta):
|
|
fields = ['departement']
|
|
|
|
class UserForm(forms.ModelForm):
|
|
class Meta:
|
|
model = User
|
|
fields = ['username', 'first_name', 'last_name', 'email']
|
|
help_texts = {
|
|
'username': ''
|
|
}
|
|
|
|
class UserRestrictForm(UserForm):
|
|
class Meta(UserForm.Meta):
|
|
fields = ['first_name', 'last_name', 'email']
|
|
|
|
# -----
|
|
# Checkout forms
|
|
# -----
|
|
|
|
class CheckoutForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Checkout
|
|
fields = ['name', 'valid_from', 'valid_to', 'balance', 'is_protected']
|
|
widgets = {
|
|
'valid_from': DateTimeWidget(),
|
|
'valid_to' : DateTimeWidget(),
|
|
}
|
|
|
|
class CheckoutRestrictForm(CheckoutForm):
|
|
class Meta(CheckoutForm.Meta):
|
|
fields = ['name', 'valid_from', 'valid_to']
|