-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The URL of a forum is built using its lti_id. Displaying the field lti_id of a forum enables an administrator to have access to this useful information.
- Loading branch information
Showing
3 changed files
with
53 additions
and
2 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
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,6 +1,29 @@ | ||
""" | ||
Import the admin classes from the django-machina's forum application | ||
""" | ||
import copy | ||
|
||
# pylint: disable=unused-wildcard-import,wildcard-import | ||
from machina.apps.forum.admin import * # noqa isort:skip | ||
from django.contrib import admin | ||
from machina.apps.forum.admin import ForumAdmin as BaseForumAdmin | ||
from machina.core.db.models import get_model | ||
|
||
Forum = get_model("forum", "Forum") | ||
|
||
admin.site.unregister(Forum) | ||
|
||
|
||
class ForumAdmin(BaseForumAdmin): | ||
"""The Forum model admin.""" | ||
|
||
readonly_fields = ("lti_id",) | ||
search_fields = ("name", "lti_id") | ||
|
||
def get_fieldsets(self, request, obj=None): | ||
"""Override fieldset to add the field lti_id""" | ||
fieldsets = copy.deepcopy(super().get_fieldsets(request, obj)) | ||
fieldsets[0][1]["fields"] = (*fieldsets[0][1]["fields"], "lti_id") | ||
|
||
return fieldsets | ||
|
||
|
||
admin.site.register(Forum, ForumAdmin) |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Test suite for the Forum admin""" | ||
from django.test import TestCase | ||
from machina.core.db.models import get_model | ||
|
||
from ashley.factories import ForumFactory, LTIContextFactory, UserFactory | ||
|
||
LTIContext = get_model("ashley", "LTIContext") | ||
Forum = get_model("forum", "Forum") | ||
|
||
|
||
class TestForumAdmin(TestCase): | ||
"""Test for the Forum admin""" | ||
|
||
def test_show_lti(self): | ||
"""Control lti_id field is display""" | ||
user = UserFactory(is_superuser=True, is_staff=True) | ||
self.client.force_login(user) | ||
|
||
lti_context = LTIContextFactory(lti_consumer=user.lti_consumer) | ||
forum = ForumFactory() | ||
forum.lti_contexts.add(lti_context) | ||
url = f"/admin/forum/forum/{forum.id}/change/" | ||
response = self.client.get(url) | ||
|
||
self.assertContains( | ||
response, f'<div class="readonly">{forum.lti_id}</div>', html=True | ||
) |