models: permet la désactivation des profils, des options et des choix d'option d'impression
fixes #1940
This commit is contained in:
parent
8c51a61fc6
commit
21c3e552cf
|
@ -6,13 +6,18 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from decimal import Decimal
|
||||
Zero = Decimal('0.00')
|
||||
|
||||
from model_utils.managers import QueryManager
|
||||
|
||||
class ProfileOptionManager(models.Manager):
|
||||
def get_query_set(self):
|
||||
return super(ProfileOptionManager, self).get_query_set().prefetch_related('profileoptionchoice_set')
|
||||
|
||||
class ProfileVisibleOptionManager(QueryManager, ProfileOptionManager):
|
||||
use_for_related_fields = False
|
||||
|
||||
class ProfileOption(models.Model):
|
||||
objects = ProfileOptionManager()
|
||||
visibles = ProfileVisibleOptionManager(visible=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'base'
|
||||
|
@ -45,6 +50,8 @@ class ProfileOptionChoiceManager(models.Manager):
|
|||
return super(ProfileOptionChoiceManager, self).get_query_set().select_related('option')
|
||||
|
||||
class ProfileOptionChoice(models.Model):
|
||||
objects = models.Manager() # default manager
|
||||
visibles = QueryManager(visible=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'base'
|
||||
|
@ -71,6 +78,7 @@ class ProfileManager(models.Manager):
|
|||
|
||||
class Profile(models.Model):
|
||||
objects = ProfileManager()
|
||||
visibles = QueryManager(visible=True)
|
||||
|
||||
class Meta:
|
||||
app_label = 'base'
|
||||
|
|
|
@ -180,7 +180,12 @@ class Request(models.Model):
|
|||
help_text=_(u"""Renseigner le diplôme ou l'UE concernée permettra un meilleur suivi de votre document."""))
|
||||
copies = models.PositiveIntegerField(verbose_name=_(u'Nombre de copies'), blank=True, default=1, validators=[validators.MinValueValidator(1)])
|
||||
status = models.ForeignKey(workflow.Status, verbose_name=_(u'Status'), on_delete=models.PROTECT)
|
||||
base_profile = models.ForeignKey('Profile', verbose_name=_('Profil de reprographie'), help_text = _(u"Choissez le profil de base, puis complétez si besoin vos choix dans les options ci-dessous."), blank=True, null=True, on_delete=models.PROTECT)
|
||||
base_profile = models.ForeignKey('Profile',
|
||||
verbose_name=_(u'Profil de reprographie'),
|
||||
help_text = _(u"Choissez le profil de base, puis complétez si "
|
||||
u"besoin vos choix dans les options ci-dessous."),
|
||||
blank=True, null=True, on_delete=models.PROTECT,
|
||||
limit_choices_to={'visible': True})
|
||||
choices = models.ManyToManyField('ProfileOptionChoice', verbose_name=_(u'Tous les choix de reprographie'), blank=True)
|
||||
details = models.TextField(verbose_name=_(u'Vos observations ou commentaires'), blank=True)
|
||||
delivery_date = models.DateField(verbose_name=_(u'Date de livraison souhaitée'),
|
||||
|
|
|
@ -194,7 +194,7 @@ class ReproDetailsForm(BaseModelForm):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(ReproDetailsForm, self).__init__(*args, **kwargs)
|
||||
l = ((u'%s' % p.id, p) for p in Profile.objects.all())
|
||||
l = ((u'%s' % p.id, p) for p in Profile.visibles.all())
|
||||
self.fields['base_profile'].choices = l
|
||||
|
||||
# crispy
|
||||
|
@ -214,11 +214,11 @@ class ReproDetailsForm(BaseModelForm):
|
|||
|
||||
self.optionfields = []
|
||||
# build "options" fields
|
||||
for option in ProfileOption.objects.filter(visible=True).prefetch_related('profileoptionchoice_set'):
|
||||
for option in ProfileOption.visibles.all():
|
||||
fieldname = 'profile_option_%s' % option.id
|
||||
self.optionfields.append(fieldname)
|
||||
choices = [(u'%s' % c.id, c.name) \
|
||||
for c in option.profileoptionchoice_set.all()]
|
||||
for c in option.profileoptionchoice_set.filter(visible=True).all()]
|
||||
if option.list_type == 'L': # Liste (choix unique)
|
||||
self.fields[fieldname] = forms.ChoiceField(
|
||||
label = u'%s' % option.name,
|
||||
|
@ -275,7 +275,7 @@ class ReproDetailsForm(BaseModelForm):
|
|||
def save(self, *args, **kwargs):
|
||||
self.instance.choices.clear()
|
||||
chosen = set()
|
||||
for option in ProfileOption.objects.filter(visible=True):
|
||||
for option in ProfileOption.visibles.all():
|
||||
fieldname = 'profile_option_%s' % option.id
|
||||
cleaned_data = self.cleaned_data
|
||||
value = cleaned_data.get(fieldname, None)
|
||||
|
@ -286,7 +286,7 @@ class ReproDetailsForm(BaseModelForm):
|
|||
chosen.add(value)
|
||||
chosen = filter(None, chosen)
|
||||
result = super(ReproDetailsForm, self).save(*args, **kwargs)
|
||||
self.instance.choices = ProfileOptionChoice.objects.filter(id__in=chosen)
|
||||
self.instance.choices = ProfileOptionChoice.visibles.filter(id__in=chosen)
|
||||
return result
|
||||
|
||||
|
||||
|
@ -295,7 +295,7 @@ class ReproDetailsForm(BaseModelForm):
|
|||
if not profile:
|
||||
base_profile = data.get('base_profile')
|
||||
if base_profile:
|
||||
profile = Profile.objects.get(id=base_profile)
|
||||
profile = Profile.visibles.get(id=base_profile)
|
||||
value = u'%s' % profile if profile else ''
|
||||
return (_(u'Profil de base'), value, not bool(value))
|
||||
|
||||
|
@ -319,7 +319,7 @@ class ReproDetailsForm(BaseModelForm):
|
|||
ret.append((choice.option.name, choice.name, False))
|
||||
else:
|
||||
option_choices = filter(None, [ self.data.get(field) for field in self.optionfields ])
|
||||
for choice in ProfileOptionChoice.objects.filter(id__in=option_choices).select_related():
|
||||
for choice in ProfileOptionChoice.visibles.filter(id__in=option_choices).select_related():
|
||||
if choice_ok(choice):
|
||||
ret.append((choice.option.name, choice.name, False))
|
||||
return ret
|
||||
|
|
|
@ -9,3 +9,4 @@ pypdf
|
|||
flup
|
||||
django-debug-toolbar
|
||||
gunicorn
|
||||
django-model-utils < 1.2.0
|
||||
|
|
Reference in New Issue