Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
7e96219f
Commit
7e96219f
authored
May 22, 2018
by
Thom Wiggers
📐
Browse files
Merge branch 'feature/documentation-payments' into 'master'
Add documentation for the payments module See merge request
!799
parents
cc428fbf
1120f1fe
Changes
6
Hide whitespace changes
Inline
Side-by-side
website/payments/admin.py
View file @
7e96219f
"""Registers admin interfaces for the payments module"""
from
django.contrib
import
admin
,
messages
from
django.contrib.admin.utils
import
model_ngettext
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -18,6 +19,8 @@ def _show_message(admin, request, n, message, error):
@
admin
.
register
(
Payment
)
class
PaymentAdmin
(
admin
.
ModelAdmin
):
"""Manage the payments"""
list_display
=
(
'created_at'
,
'amount'
,
'processed'
,
'processing_date'
,
'type'
)
list_filter
=
(
'processed'
,
'amount'
,)
...
...
@@ -30,6 +33,10 @@ class PaymentAdmin(admin.ModelAdmin):
def
changeform_view
(
self
,
request
,
object_id
=
None
,
form_url
=
''
,
extra_context
=
None
):
"""
Renders the change formview
Only allow when the payment has not been processed yet
"""
obj
=
None
if
(
object_id
is
not
None
and
request
.
user
.
has_perm
(
'payments.process_payments'
)):
...
...
@@ -40,6 +47,8 @@ class PaymentAdmin(admin.ModelAdmin):
request
,
object_id
,
form_url
,
{
'payment'
:
obj
})
def
get_actions
(
self
,
request
):
"""Get the actions for the payments"""
"""Hide the processing actions if the right permissions are missing"""
actions
=
super
().
get_actions
(
request
)
if
not
request
.
user
.
has_perm
(
'payments.process_payments'
):
del
(
actions
[
'process_cash_selected'
])
...
...
@@ -47,6 +56,7 @@ class PaymentAdmin(admin.ModelAdmin):
return
actions
def
process_cash_selected
(
self
,
request
,
queryset
):
"""Process the selected payment as cash"""
if
request
.
user
.
has_perm
(
'payments.process_payments'
):
updated_payments
=
services
.
process_payment
(
queryset
,
Payment
.
CASH
...
...
@@ -56,6 +66,7 @@ class PaymentAdmin(admin.ModelAdmin):
'Process selected payments (cash)'
)
def
process_card_selected
(
self
,
request
,
queryset
):
"""Process the selected payment as card"""
if
request
.
user
.
has_perm
(
'payments.process_payments'
):
updated_payments
=
services
.
process_payment
(
queryset
,
Payment
.
CARD
...
...
@@ -65,6 +76,7 @@ class PaymentAdmin(admin.ModelAdmin):
'Process selected payments (card)'
)
def
_process_feedback
(
self
,
request
,
updated_payments
):
"""Show a feedback message for the processing result"""
rows_updated
=
len
(
updated_payments
)
_show_message
(
self
,
request
,
rows_updated
,
...
...
website/payments/apps.py
View file @
7e96219f
"""Configuration for the payments package"""
from
django.apps
import
AppConfig
from
django.utils.translation
import
ugettext_lazy
as
_
class
PaymentsConfig
(
AppConfig
):
"""AppConfig for the payments package"""
name
=
'payments'
verbose_name
=
_
(
'Payments'
)
website/payments/models.py
View file @
7e96219f
"""The models defined by the payments package"""
import
uuid
from
django.contrib.contenttypes.models
import
ContentType
...
...
website/payments/services.py
View file @
7e96219f
"""The services defined by the payments package"""
from
.models
import
Payment
def
process_payment
(
queryset
,
pay_type
=
Payment
.
CARD
):
"""
Process the payment
Process the payment
:param queryset: Queryset of payments that should be processed
:type queryset: QuerySet[Payment]
:param pay_type: Type of the payment
:type pay_type: String
"""
:param queryset: Queryset of payments that should be processed
:type queryset: QuerySet[Payment]
:param pay_type: Type of the payment
:type pay_type: String
"""
queryset
=
queryset
.
filter
(
processed
=
False
)
data
=
[]
...
...
website/payments/urls.py
View file @
7e96219f
"""The routes defined by the payments package"""
from
django.urls
import
path
from
.views
import
PaymentAdminView
...
...
website/payments/views.py
View file @
7e96219f
"""Views provided by the payments package"""
from
django.contrib
import
messages
from
django.contrib.admin.utils
import
model_ngettext
from
django.contrib.admin.views.decorators
import
staff_member_required
...
...
@@ -15,6 +16,9 @@ from .models import Payment
@
method_decorator
(
permission_required
(
'payments.process_payments'
),
name
=
'dispatch'
,
)
class
PaymentAdminView
(
View
):
"""
View that processes a payment
"""
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
payment
=
Payment
.
objects
.
filter
(
pk
=
kwargs
[
'pk'
])
result
=
services
.
process_payment
(
...
...
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