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 %}
{% else %}
{% endif %}
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 == 'payment':
return Field(widget=PaymentWidget,
return field
def changeform_view(self, request, object_id=None, form_url='',
......@@ -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']
return [ for field in self.model._meta.get_fields()
if field.editable]
if field.editable and not == 'payment']
def name(obj):
......@@ -155,6 +165,7 @@ class RenewalAdmin(RegistrationAdmin):
......@@ -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
Supports Markdown
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