Verified Commit 61067070 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Add direct link to payment from registrations model admins

parent 31d1b812
{% load i18n %}
<div class="readonly">
{% if widget.value %}
<a href="{{ url }}">
{% if processed %}
{% trans "Processed" %}
{% else %}
{% trans "Unprocessed" %}
{% endif %}
</a>
{% else %}
-
{% endif %}
</div>
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
"""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',)
}),
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment