Skip to content

Commit

Permalink
Expose basic roster information on the admin pages
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospri committed Nov 20, 2024
1 parent 13f0eb1 commit 9393b2f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 8 deletions.
9 changes: 9 additions & 0 deletions lms/templates/admin/assignment/show.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@
<legend class="label has-text-centered">Course</legend>
{{ macros.course_preview(request, assignment.course) }}
</fieldset>

<fieldset class="box mt-6">
<legend class="label has-text-centered">Roster</legend>
{% if roster %}
{{ macros.roster_table(request, roster) }}
{% else %}
<legend class="label has-text-centered">No roster information</legend>
{% endif %}
</fieldset>
</div>
{% endblock %}
9 changes: 9 additions & 0 deletions lms/templates/admin/course/show.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,16 @@
{% else %}
<legend class="label has-text-centered">No assignments</legend>
{% endif %}
</fieldset>

<fieldset class="box mt-6">
<legend class="label has-text-centered">Roster</legend>
{% if roster %}
{{ macros.roster_table(request, roster) }}
{% else %}
<legend class="label has-text-centered">No roster information</legend>
{% endif %}
</fieldset>

</div>
{% endblock %}
13 changes: 13 additions & 0 deletions lms/templates/admin/macros.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,20 @@
<table class="table is-fullwidth">
<thead>
<tr>
{% if route %}
<th></th>
{% endif %}
{% for field in fields %}<th>{{ field.label }}</th>{% endfor %}
</tr>
</thead>
<tbody>
{% for object in objects %}
<tr>
{% if route %}
<td>
<a class="button" href="{{ request.route_url(route, id_=object.id) }}">View</a>
</td>
{% endif %}
{% for field in fields %}<td>{{ auto_format(object[field.name], html=html) }}</td>{% endfor %}
</tr>
{% endfor %}
Expand Down Expand Up @@ -278,3 +282,12 @@
{"label": "Context ID", "name": "lms_id"},
]) }}
{% endmacro %}
{% macro roster_table(request, roster_users) %}
{{ object_list_table(request, None, roster_users,
fields=[
{"label": "Name", "name": "display_name"},
{"label": "H Userid", "name": "h_userid"},
{"label": "LTI user id", "name": "lti_user_id"},
]) }}
{% endmacro %}
7 changes: 4 additions & 3 deletions lms/views/admin/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from lms.events import AuditTrailEvent, ModelChange
from lms.models import Assignment, EventType
from lms.security import Permissions
from lms.services import RosterService


@view_defaults(request_method="GET", permission=Permissions.ADMIN)
class AdminAssignmentViews:
def __init__(self, request) -> None:
self.request = request
self.roster_service: RosterService = request.find_service(RosterService)
self.assignment_service = request.find_service(name="assignment")

@view_config(
Expand All @@ -22,9 +24,8 @@ def __init__(self, request) -> None:
)
def show(self):
assignment = self._get_or_404()
return {
"assignment": assignment,
}
roster = self.roster_service.get_assignment_roster(assignment)
return {"assignment": assignment, "roster": roster}

@view_config(
route_name="admin.assignment.dashboard",
Expand Down
6 changes: 4 additions & 2 deletions lms/views/admin/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from lms.events import AuditTrailEvent, ModelChange
from lms.models import Course, EventType
from lms.security import Permissions
from lms.services import InvalidPublicId, OrganizationService
from lms.services import InvalidPublicId, OrganizationService, RosterService
from lms.validation._base import PyramidRequestSchema
from lms.views.admin import flash_validation
from lms.views.admin._schemas import EmptyStringInt
Expand All @@ -33,6 +33,7 @@ def __init__(self, request) -> None:
self.organization_service: OrganizationService = request.find_service(
OrganizationService
)
self.roster_service: RosterService = request.find_service(RosterService)

@view_config(
route_name="admin.courses",
Expand All @@ -52,8 +53,9 @@ def courses(self): # pragma: no cover
def show(self):
course_id = self.request.matchdict["id_"]
course = self._get_course_or_404(course_id)
roster = self.roster_service.get_course_roster(course.lms_course)

return {"course": course}
return {"course": course, "roster": roster}

@view_config(
route_name="admin.courses.dashboard",
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/lms/views/admin/assignment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
from tests import factories


@pytest.mark.usefixtures("roster_service")
class TestAdminAssignmentViews:
def test_show(self, pyramid_request, assignment_service, views):
def test_show(self, pyramid_request, assignment_service, views, roster_service):
pyramid_request.matchdict["id_"] = sentinel.id

response = views.show()

assignment_service.get_by_id.assert_called_once_with(id_=sentinel.id)
roster_service.get_assignment_roster.assert_called_once_with(
assignment_service.get_by_id.return_value
)

assert response == {
"assignment": assignment_service.get_by_id.return_value,
"roster": roster_service.get_assignment_roster.return_value,
}

def test_show_not_found(self, pyramid_request, assignment_service, views):
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/lms/views/admin/course_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
from tests import factories


@pytest.mark.usefixtures("course_service", "organization_service")
@pytest.mark.usefixtures("course_service", "organization_service", "roster_service")
class TestAdminCourseViews:
def test_show(self, pyramid_request, course_service, views):
def test_show(self, pyramid_request, course_service, views, roster_service):
pyramid_request.matchdict["id_"] = sentinel.id_

response = views.show()

course_service.get_by_id.assert_called_once_with(id_=sentinel.id_)
roster_service.get_course_roster.assert_called_once_with(
course_service.get_by_id.return_value.lms_course
)

assert response == {
"course": course_service.get_by_id.return_value,
"roster": roster_service.get_course_roster.return_value,
}

def test_show_not_found(self, pyramid_request, course_service, views):
Expand Down

0 comments on commit 9393b2f

Please sign in to comment.