|
| 1 | +"""Django Admin models for Arklet.""" |
| 2 | + |
1 | 3 | from django.contrib import admin
|
2 |
| -from django.core.paginator import Paginator |
3 |
| -from django.db import OperationalError, connection, transaction |
4 |
| -from django.utils.functional import cached_property |
5 | 4 |
|
6 | 5 | from ark.models import Ark, Key, Naan, Shoulder, User
|
7 | 6 |
|
8 | 7 |
|
9 |
| -class TimeLimitedPaginator(Paginator): |
10 |
| - """ |
11 |
| - Paginator that enforces a timeout on the count operation. |
12 |
| - If the operations times out, a fake bogus value is |
13 |
| - returned instead. |
14 |
| -
|
15 |
| - Lifted from: https://web.archive.org/web/20210422225156/https://hakibenita.com/optimizing-the-django-admin-paginator |
16 |
| - """ |
17 |
| - |
18 |
| - @cached_property |
19 |
| - def count(self): |
20 |
| - # We set the timeout in a db transaction to prevent it from |
21 |
| - # affecting other transactions. |
22 |
| - with transaction.atomic(), connection.cursor() as cursor: |
23 |
| - cursor.execute("SET LOCAL statement_timeout TO 1000;") |
24 |
| - try: |
25 |
| - return super().count |
26 |
| - except OperationalError: |
27 |
| - return 9999999999 |
28 |
| - |
29 |
| - |
30 | 8 | @admin.register(User)
|
31 | 9 | class UserAdmin(admin.ModelAdmin):
|
32 |
| - pass |
| 10 | + """Django Admin model for ARK admin users.""" |
33 | 11 |
|
34 | 12 |
|
35 | 13 | @admin.register(Naan)
|
36 | 14 | class NaanAdmin(admin.ModelAdmin):
|
| 15 | + """Django Admin model for Name Assignment Authority Number bearing organizations.""" |
| 16 | + |
37 | 17 | list_display = ["name", "naan"]
|
38 | 18 |
|
39 | 19 |
|
40 | 20 | @admin.register(Shoulder)
|
41 | 21 | class ShoulderAdmin(admin.ModelAdmin):
|
| 22 | + """Django Admin model for ARK shoulders.""" |
| 23 | + |
42 | 24 | list_display = ["shoulder", "name", "naan"]
|
43 | 25 |
|
44 | 26 |
|
45 | 27 | @admin.register(Ark)
|
46 | 28 | class ArkAdmin(admin.ModelAdmin):
|
| 29 | + """Django Admin model for ARKs. |
| 30 | +
|
| 31 | + In practice, stock Django Admin doesn't work well for large randomly sorted tables. |
| 32 | + This view will tend to take a long time to load as a full table count query is run. |
| 33 | + """ |
| 34 | + |
47 | 35 | list_display = ["ark", "url"]
|
48 | 36 | show_full_result_count = False
|
49 |
| - paginator = TimeLimitedPaginator |
50 | 37 |
|
51 | 38 |
|
52 | 39 | @admin.register(Key)
|
53 | 40 | class KeyAdmin(admin.ModelAdmin):
|
| 41 | + """Django Admin model for managing Arklet access keys. |
| 42 | +
|
| 43 | + These access keys are used to mint and bind ARKs via the Arklet API. |
| 44 | + """ |
| 45 | + |
54 | 46 | list_display = ["key", "naan", "active"]
|
0 commit comments