mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +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)
|
super(FactureForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['paiement'].empty_label = \
|
self.fields['paiement'].empty_label = \
|
||||||
_("Select a payment method")
|
_("Select a payment method")
|
||||||
self.fields['paiement'].queryset = Paiement.objects.filter(
|
self.fields['paiement'].queryset = Paiement.find_allowed_payments(user)
|
||||||
pk__in=map(lambda x: x.pk, Paiement.find_allowed_payments(user))
|
|
||||||
)
|
|
||||||
if not creation:
|
if not creation:
|
||||||
self.fields['user'].label = _("Member")
|
self.fields['user'].label = _("Member")
|
||||||
self.fields['user'].empty_label = \
|
self.fields['user'].empty_label = \
|
||||||
|
@ -106,9 +104,7 @@ class SelectUserArticleForm(FormRevMixin, Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
user = kwargs.pop('user')
|
user = kwargs.pop('user')
|
||||||
super(SelectUserArticleForm, self).__init__(*args, **kwargs)
|
super(SelectUserArticleForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['article'].queryset = Article.objects.filter(
|
self.fields['article'].queryset = Article.find_allowed_articles(user)
|
||||||
pk__in=map(lambda x: x.pk, Article.find_allowed_articles(user))
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class SelectClubArticleForm(Form):
|
class SelectClubArticleForm(Form):
|
||||||
|
@ -129,12 +125,9 @@ class SelectClubArticleForm(Form):
|
||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, user, *args, **kwargs):
|
||||||
user = kwargs.pop('user')
|
|
||||||
super(SelectClubArticleForm, self).__init__(*args, **kwargs)
|
super(SelectClubArticleForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['article'].queryset = Article.objects.filter(
|
self.fields['article'].queryset = Article.find_allowed_articles(user)
|
||||||
pk__in=map(lambda x: x.pk, Article.find_allowed_articles(user))
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# TODO : change Facture to Invoice
|
# TODO : change Facture to Invoice
|
||||||
|
@ -284,15 +277,12 @@ class RechargeForm(FormRevMixin, Form):
|
||||||
label=_l("Payment method")
|
label=_l("Payment method")
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, user=None, **kwargs):
|
||||||
self.user = kwargs.pop('user')
|
self.user = user
|
||||||
super(RechargeForm, self).__init__(*args, **kwargs)
|
super(RechargeForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['payment'].empty_label = \
|
self.fields['payment'].empty_label = \
|
||||||
_("Select a payment method")
|
_("Select a payment method")
|
||||||
self.fields['payment'].queryset = Paiement.objects.filter(
|
self.fields['payment'].queryset = Paiement.find_allowed_payments(user)
|
||||||
pk__in=map(lambda x: x.pk,
|
|
||||||
Paiement.find_allowed_payments(self.user))
|
|
||||||
)
|
|
||||||
|
|
||||||
def clean_value(self):
|
def clean_value(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -567,7 +567,13 @@ class Article(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_allowed_articles(cls, user):
|
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):
|
class Banque(RevMixin, AclMixin, models.Model):
|
||||||
|
@ -726,7 +732,13 @@ class Paiement(RevMixin, AclMixin, models.Model):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def find_allowed_payments(cls, user):
|
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):
|
class Cotisation(RevMixin, AclMixin, models.Model):
|
||||||
|
|
Loading…
Reference in a new issue