Skip to content
GitLab
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
61067070
Verified
Commit
61067070
authored
Aug 28, 2018
by
Sébastiaan Versteeg
Browse files
Add direct link to payment from registrations model admins
parent
31d1b812
Changes
4
Hide whitespace changes
Inline
Side-by-side
website/payments/templates/payments/widget.html
0 → 100644
View file @
61067070
{% load i18n %}
<div
class=
"readonly"
>
{% if widget.value %}
<a
href=
"{{ url }}"
>
{% if processed %}
{% trans "Processed" %}
{% else %}
{% trans "Unprocessed" %}
{% endif %}
</a>
{% else %}
-
{% endif %}
</div>
website/payments/widgets.py
0 → 100644
View file @
61067070
from
django.forms
import
Widget
from
payments.models
import
Payment
class
PaymentWidget
(
Widget
):
template_name
=
'payments/widget.html'
def
value_from_datadict
(
self
,
data
,
files
,
name
):
return
super
().
value_from_datadict
(
data
,
files
,
name
)
def
get_context
(
self
,
name
,
value
,
attrs
):
context
=
super
().
get_context
(
name
,
value
,
attrs
)
if
value
:
payment
=
Payment
.
objects
.
get
(
pk
=
value
)
context
[
'url'
]
=
payment
.
get_admin_url
()
context
[
'processed'
]
=
payment
.
processed
return
context
website/registrations/admin.py
View file @
61067070
"""Registers admin interfaces for the registrations module"""
from
django.contrib
import
admin
,
messages
from
django.contrib.admin.utils
import
model_ngettext
from
django.forms
import
Field
from
django.utils.html
import
format_html
from
django.utils.translation
import
ugettext_lazy
as
_
from
payments.widgets
import
PaymentWidget
from
.
import
services
from
.models
import
Entry
,
Registration
,
Renewal
...
...
@@ -64,6 +66,14 @@ class RegistrationAdmin(admin.ModelAdmin):
)
actions
=
[
'accept_selected'
,
'reject_selected'
]
def
formfield_for_dbfield
(
self
,
db_field
,
request
,
**
kwargs
):
field
=
super
().
formfield_for_dbfield
(
db_field
,
request
,
**
kwargs
)
if
db_field
.
name
==
'payment'
:
return
Field
(
widget
=
PaymentWidget
,
initial
=
field
.
initial
,
required
=
False
)
return
field
def
changeform_view
(
self
,
request
,
object_id
=
None
,
form_url
=
''
,
extra_context
=
None
):
"""
...
...
@@ -93,10 +103,10 @@ class RegistrationAdmin(admin.ModelAdmin):
def
get_readonly_fields
(
self
,
request
,
obj
=
None
):
if
obj
is
None
or
not
(
obj
.
status
==
Entry
.
STATUS_REJECTED
or
obj
.
status
==
Entry
.
STATUS_ACCEPTED
):
return
[
'status'
,
'created_at'
,
'updated_at'
,
'payment'
]
return
[
'status'
,
'created_at'
,
'updated_at'
]
else
:
return
[
field
.
name
for
field
in
self
.
model
.
_meta
.
get_fields
()
if
field
.
editable
]
if
field
.
editable
and
not
field
.
name
==
'payment'
]
@
staticmethod
def
name
(
obj
):
...
...
@@ -155,6 +165,7 @@ class RenewalAdmin(RegistrationAdmin):
'length'
,
'membership_type'
,
'status'
,
'payment'
,
'remarks'
,
'member'
,)
}),
...
...
website/registrations/forms.py
View file @
61067070
...
...
@@ -4,6 +4,7 @@ from django.forms import TypedChoiceField
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
from
payments.widgets
import
PaymentWidget
from
utils.snippets
import
datetime_to_lectureyear
from
.models
import
Registration
,
Renewal
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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