-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathadmin.py
executable file
·101 lines (82 loc) · 3.17 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from django.contrib import admin
from django.db.models.query import QuerySet
from django.http import HttpRequest, HttpResponseRedirect
from django.urls import path
from libraries.tasks import release_tasks
from . import models
from .tasks import (
import_versions,
import_most_recent_beta_release,
import_development_versions,
)
class VersionFileInline(admin.StackedInline):
model = models.VersionFile
autocomplete_fields = ("version",)
verbose_name = "VersionFile"
verbose_name_plural = "VersionFiles"
extra = 0
@admin.register(models.Version)
class VersionAdmin(admin.ModelAdmin):
list_display = ["name", "release_date", "active", "full_release", "beta"]
list_filter = ["active", "full_release", "beta"]
ordering = ["-release_date", "-name"]
search_fields = ["name", "description"]
date_hierarchy = "release_date"
inlines = [VersionFileInline]
filter_horizontal = ["financial_committee_members"]
change_list_template = "admin/version_change_list.html"
def get_urls(self):
urls = super().get_urls()
my_urls = [
path(
"new_versions/",
self.admin_site.admin_view(self.import_new_releases),
name="import_new_releases",
),
path(
"release_tasks/",
self.admin_site.admin_view(self.release_tasks),
name="release_tasks",
),
]
return my_urls + urls
def release_tasks(self, request):
release_tasks.delay(user_id=request.user.id, generate_report=True)
self.message_user(
request,
"release_tasks has started, you will receive an email when the task finishes.", # noqa: E501
)
return HttpResponseRedirect("../")
def import_new_releases(self, request):
import_versions.delay(new_versions_only=True)
import_most_recent_beta_release.delay(delete_old=True)
# Import the master and develop branches
import_development_versions.delay()
self.message_user(
request,
"""
New releases are being imported. If you don't see any new releases,
please refresh this page or check the logs.
""",
)
return HttpResponseRedirect("../")
class ResultInline(admin.StackedInline):
model = models.ReviewResult
autocomplete_fields = ("review",)
verbose_name = "Result"
verbose_name_plural = "Results"
extra = 0
@admin.register(models.Review)
class ReviewAdmin(admin.ModelAdmin):
list_display = ["submission", "review_dates", "get_results"]
search_fields = ["submission"]
inlines = [ResultInline]
def get_results(self, obj):
return " | ".join(obj.results.values_list("short_description", flat=True))
def get_queryset(self, request: HttpRequest) -> QuerySet:
return super().get_queryset(request).prefetch_related("results")
@admin.register(models.ReviewResult)
class ReviewResultAdmin(admin.ModelAdmin):
list_display = ["review", "short_description"]
def get_queryset(self, request: HttpRequest) -> QuerySet:
return super().get_queryset(request).select_related("review")