Skip to content

Commit

Permalink
✨(admin) add certificate field into order admin change view
Browse files Browse the repository at this point in the history
If the order has a certificate, a link is displayed to go to the certificate
admin change view.
  • Loading branch information
jbpenrath committed Apr 1, 2022
1 parent 4174c40 commit bc08ca4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to

### Added

- Add certificate field into order admin change view
- Add custom actions into admin to generate certificates
- Add a management command to generate certificate for eligible orders
- Add `is_passed` cached property to enrollment model
Expand Down
15 changes: 14 additions & 1 deletion src/backend/joanie/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class OrderAdmin(DjangoObjectActions, admin.ModelAdmin):
"""Admin class for the Order model"""

list_display = ("uid", "owner", "product", "state")
readonly_fields = ("total", "invoice")
readonly_fields = ("total", "invoice", "certificate")
change_actions = (ACTION_NAME_GENERATE_CERTIFICATES,)
actions = (ACTION_NAME_CANCEL, ACTION_NAME_GENERATE_CERTIFICATES)

Expand Down Expand Up @@ -291,6 +291,19 @@ def invoice(self, obj): # pylint: disable=no-self-use
)
)

def certificate(self, obj): # pylint: disable=no-self-use
"""Retrieve the certificate related to the order."""
if obj.certificate is None:
return "-"

return format_html(
(
f"<a href='{reverse('admin:payment_invoice_change', args=(obj.certificate.id,), )}'>"
f"{str(obj.certificate)}"
"</a>"
)
)


@admin.register(models.Enrollment)
class EnrollmentAdmin(admin.ModelAdmin):
Expand Down
4 changes: 2 additions & 2 deletions src/backend/joanie/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ class Base(Configuration):
"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"},
}

JOANIE_ANONYMOUS_COURSE_SERIALIZER_CACHE_TTL = 3600 # 1 hour
JOANIE_ENROLLMENT_GRADE_CACHE_TTL = 600 # 10 minutes
JOANIE_ANONYMOUS_COURSE_SERIALIZER_CACHE_TTL = 0 # 1 hour
JOANIE_ENROLLMENT_GRADE_CACHE_TTL = 0 # 10 minutes

LANGUAGES = (
("en-us", _("English")),
Expand Down

0 comments on commit bc08ca4

Please sign in to comment.