forked from pennlabs/penn-courses
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,53 @@ | ||
from django.contrib import admin | ||
from django.conf.urls import url | ||
from django.urls import reverse | ||
from django.contrib import admin | ||
from django.template.response import TemplateResponse | ||
from django.urls import reverse | ||
from django.utils.html import format_html | ||
|
||
from degree.models import Degree, DegreePlan, DoubleCountRestriction, Rule, SatisfactionStatus | ||
|
||
|
||
# Register your models here. | ||
@admin.register(Rule) | ||
class RuleAdmin(admin.ModelAdmin): | ||
search_fields = ["title", "id"] | ||
list_display = ["title", "id", "parent"] | ||
list_select_related = ["parent"] | ||
|
||
|
||
admin.site.register(DegreePlan) | ||
admin.site.register(SatisfactionStatus) | ||
|
||
|
||
@admin.register(DoubleCountRestriction) | ||
class DoubleCountRestrictionAdmin(admin.ModelAdmin): | ||
autocomplete_fields = ["rule", "other_rule"] | ||
|
||
|
||
@admin.register(Degree) | ||
class DegreeAdmin(admin.ModelAdmin): | ||
autocomplete_fields = ["rules"] | ||
list_display = ["program", "degree", "major", "concentration", "year", "view_degree_editor"] | ||
|
||
def view_degree_editor(self, obj): | ||
return format_html( | ||
'<a href="{url}?id={id}">View in Degree Editor</a>', | ||
id=obj.id, | ||
url=reverse('admin:degree-editor') | ||
'<a href="{url}?id={id}">View in Degree Editor</a>', | ||
id=obj.id, | ||
url=reverse("admin:degree-editor"), | ||
) | ||
|
||
def get_urls(self): | ||
# get the default urls | ||
urls = super().get_urls() | ||
custom_urls = [ | ||
url(r'^degree-editor/$', self.admin_site.admin_view(self.degree_editor), name='degree-editor') | ||
url( | ||
r"^degree-editor/$", | ||
self.admin_site.admin_view(self.degree_editor), | ||
name="degree-editor", | ||
) | ||
] | ||
return custom_urls + urls | ||
|
||
def degree_editor(self, request): | ||
context = dict( | ||
self.admin_site.each_context(request) | ||
) | ||
return TemplateResponse(request, "degree-editor.html", context) | ||
context = dict(self.admin_site.each_context(request)) | ||
return TemplateResponse(request, "degree-editor.html", context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters