-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic listing of course's assignments in the admin pages
- Loading branch information
Showing
10 changed files
with
106 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{% import "lms:templates/admin/macros.html.jinja2" as macros %} | ||
{% extends "lms:templates/admin/base.html.jinja2" %} | ||
{% block header %}Assignment {{ assignment.id }}{% endblock %} | ||
{% block content %} | ||
<div> | ||
<fieldset> | ||
<legend class="label has-text-centered">Assignment</legend> | ||
{{ macros.disabled_text_field("ID", assignment.id) }} | ||
{{ macros.disabled_text_field("Title", assignment.title) }} | ||
{{ macros.disabled_text_field("Document", assignment.document_url) }} | ||
{{ macros.created_updated_fields(assignment) }} | ||
</fieldset> | ||
</div> | ||
{% endblock %} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from pyramid.httpexceptions import HTTPNotFound | ||
from pyramid.view import view_config, view_defaults | ||
|
||
from lms.models import Assignment | ||
from lms.security import Permissions | ||
|
||
|
||
@view_defaults(request_method="GET", permission=Permissions.ADMIN) | ||
class AdminAssignmentViews: | ||
def __init__(self, request) -> None: | ||
self.request = request | ||
self.assignment_service = request.find_service(name="assignment") | ||
|
||
@view_config( | ||
route_name="admin.assignment", | ||
request_method="GET", | ||
renderer="lms:templates/admin/assignment/show.html.jinja2", | ||
permission=Permissions.STAFF, | ||
) | ||
def show(self): | ||
assignment_id = self.request.matchdict["id_"] | ||
assignment = self._get_or_404(assignment_id) | ||
|
||
return { | ||
"assignment": assignment, | ||
} | ||
|
||
def _get_or_404(self, id_) -> Assignment: | ||
if assignment := self.assignment_service.get_by_id(id_=id_): | ||
return assignment | ||
|
||
raise HTTPNotFound() |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from unittest.mock import sentinel | ||
|
||
import pytest | ||
from pyramid.httpexceptions import HTTPNotFound | ||
|
||
from lms.views.admin.assignment import AdminAssignmentViews | ||
|
||
|
||
class TestAdminAssignmentViews: | ||
def test_show(self, pyramid_request, assignment_service, views): | ||
pyramid_request.matchdict["id_"] = sentinel.id_ | ||
|
||
response = views.show() | ||
|
||
assignment_service.get_by_id.assert_called_once_with(id_=sentinel.id_) | ||
|
||
assert response == { | ||
"assignment": assignment_service.get_by_id.return_value, | ||
} | ||
|
||
def test_show_not_found(self, pyramid_request, assignment_service, views): | ||
pyramid_request.matchdict["id_"] = sentinel.id_ | ||
assignment_service.get_by_id.return_value = None | ||
|
||
with pytest.raises(HTTPNotFound): | ||
views.show() | ||
|
||
@pytest.fixture | ||
def views(self, pyramid_request): | ||
return AdminAssignmentViews(pyramid_request) |
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