Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
161ce720
Commit
161ce720
authored
Jul 13, 2018
by
Hugo LEVY-FALK
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimisation des requêtes pour obtenir les paiements et articles disponibles.
parent
78b950c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
cotisations/forms.py
cotisations/forms.py
+7
-17
cotisations/models.py
cotisations/models.py
+14
-2
No files found.
cotisations/forms.py
View file @
161ce720
...
...
@@ -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
):
"""
...
...
cotisations/models.py
View file @
161ce720
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment