mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 22:22:26 +00:00
Optimisation des requêtes pour obtenir les paiements et articles disponibles.
This commit is contained in:
parent
78b950c392
commit
161ce72042
2 changed files with 21 additions and 19 deletions
|
@ -60,9 +60,7 @@ class FactureForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
|
|||
super(FactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||
self.fields['paiement'].empty_label = \
|
||||
_("Select a payment method")
|
||||
self.fields['paiement'].queryset = Paiement.objects.filter(
|
||||
pk__in=map(lambda x: x.pk, Paiement.find_allowed_payments(user))
|
||||
)
|
||||
self.fields['paiement'].queryset = Paiement.find_allowed_payments(user)
|
||||
if not creation:
|
||||
self.fields['user'].label = _("Member")
|
||||
self.fields['user'].empty_label = \
|
||||
|
@ -106,9 +104,7 @@ class SelectUserArticleForm(FormRevMixin, Form):
|
|||
def __init__(self, *args, **kwargs):
|
||||
user = kwargs.pop('user')
|
||||
super(SelectUserArticleForm, self).__init__(*args, **kwargs)
|
||||
self.fields['article'].queryset = Article.objects.filter(
|
||||
pk__in=map(lambda x: x.pk, Article.find_allowed_articles(user))
|
||||
)
|
||||
self.fields['article'].queryset = Article.find_allowed_articles(user)
|
||||
|
||||
|
||||
class SelectClubArticleForm(Form):
|
||||
|
@ -129,12 +125,9 @@ class SelectClubArticleForm(Form):
|
|||
required=True
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
user = kwargs.pop('user')
|
||||
def __init__(self, user, *args, **kwargs):
|
||||
super(SelectClubArticleForm, self).__init__(*args, **kwargs)
|
||||
self.fields['article'].queryset = Article.objects.filter(
|
||||
pk__in=map(lambda x: x.pk, Article.find_allowed_articles(user))
|
||||
)
|
||||
self.fields['article'].queryset = Article.find_allowed_articles(user)
|
||||
|
||||
|
||||
# TODO : change Facture to Invoice
|
||||
|
@ -284,15 +277,12 @@ class RechargeForm(FormRevMixin, Form):
|
|||
label=_l("Payment method")
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop('user')
|
||||
def __init__(self, *args, user=None, **kwargs):
|
||||
self.user = user
|
||||
super(RechargeForm, self).__init__(*args, **kwargs)
|
||||
self.fields['payment'].empty_label = \
|
||||
_("Select a payment method")
|
||||
self.fields['payment'].queryset = Paiement.objects.filter(
|
||||
pk__in=map(lambda x: x.pk,
|
||||
Paiement.find_allowed_payments(self.user))
|
||||
)
|
||||
self.fields['payment'].queryset = Paiement.find_allowed_payments(user)
|
||||
|
||||
def clean_value(self):
|
||||
"""
|
||||
|
|
|
@ -567,7 +567,13 @@ class Article(RevMixin, AclMixin, models.Model):
|
|||
|
||||
@classmethod
|
||||
def find_allowed_articles(cls, user):
|
||||
return [p for p in cls.objects.all() if p.can_buy_article(user)[0]]
|
||||
"""Finds every allowed articles for an user.
|
||||
|
||||
:param user: The user requesting articles.
|
||||
"""
|
||||
if user.has_perm('cotisations.buy_every_article'):
|
||||
return cls.objects.all()
|
||||
return cls.objects.filter(available_for_everyone=True)
|
||||
|
||||
|
||||
class Banque(RevMixin, AclMixin, models.Model):
|
||||
|
@ -726,7 +732,13 @@ class Paiement(RevMixin, AclMixin, models.Model):
|
|||
|
||||
@classmethod
|
||||
def find_allowed_payments(cls, user):
|
||||
return [p for p in cls.objects.all() if p.can_use_payment(user)[0]]
|
||||
"""Finds every allowed payments for an user.
|
||||
|
||||
:param user: The user requesting payment methods.
|
||||
"""
|
||||
if user.has_perm('cotisations.use_every_payment'):
|
||||
return cls.objects.all()
|
||||
return cls.objects.filter(available_for_everyone=True)
|
||||
|
||||
|
||||
class Cotisation(RevMixin, AclMixin, models.Model):
|
||||
|
|
Loading…
Reference in a new issue