Skip to content

Commit a744023

Browse files
TheStrgamerddabblesigridgeGunvor4
authored
Usage requirements refactor (#749)
* Added CoursePermission and CourseType * Implemented cource permission class * migrated data * Updated views and admin to use new permission * fixed bug with auth requirement * added coursepermission to admin * Updated course page * Updated form ui for courses * Made 3dpr permission automatic * updated url tests * update machine tests * updated reservation test * updated machine and reservation tests * code cleanup * Added translations * Fixed api bug * Removed print * fixed line endings hopefully * Fixed naming in migrations * Fixed usage hint and translation typo * fixed some codeclimate cleanup * removed some whitespace * Added changes to unreleased in changelog * Made some fixes according to review comments * Removed unused if statement * Added if statement to prevent when a user has no registered course * updated more code according to feedback * removed whitespace * i removed one too many whitespace lines, whoops * fixed bug where course list used old get_permission_names method * removed atomic flag * merged migrations * Switched to using enum instead of "3DPR" and similar strings --------- Co-authored-by: Anders <6058745+ddabble@users.noreply.github.com> Co-authored-by: Sigrid <55406589+sigtheidiot@users.noreply.github.com> Co-authored-by: Gunvor4 <114504373+Gunvor4@users.noreply.github.com>
1 parent 36e489e commit a744023

File tree

15 files changed

+338
-225
lines changed

15 files changed

+338
-225
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A summary of changes made to the codebase, grouped per deployment.
66

77
### New features
88

9-
-
9+
- Made it easier to add new permissions for any machine type, so that each permission can be granted when registering a completed course
1010

1111
### Improvements
1212

src/checkin/views.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from card.views import RFIDView
1616
from util.view_utils import PreventGetRequestsMixin
1717
from .models import Profile, RegisterProfile, Skill, SuggestSkill, UserSkill
18+
from make_queue.models.course import CoursePermission
1819

1920

2021
class AdminCheckInView(RFIDView):
@@ -107,9 +108,7 @@ def get_context_data(self, **kwargs):
107108
profile, _created = Profile.objects.get_or_create(user=user)
108109

109110
completed_3d_printer = hasattr(user, 'printer_3d_course')
110-
completed_raise3d = completed_3d_printer and user.printer_3d_course.raise3d_course
111-
completed_sla = completed_3d_printer and user.printer_3d_course.sla_course
112-
111+
special_courses = CoursePermission.objects.exclude(short_name__in=[CoursePermission.DefaultPerms.TAKEN_3D_PRINTER_COURSE, CoursePermission.DefaultPerms.IS_AUTHENTICATED])
113112
completed_course_message_structs = [
114113
CompletedCourseMessageStruct(
115114
completed=completed_3d_printer,
@@ -119,22 +118,18 @@ def get_context_data(self, **kwargs):
119118
"To use a 3D printer, make a reservation in the calendar of one of the 3D printers on the “Reservations” page."
120119
) if completed_3d_printer else None,
121120
),
122-
CompletedCourseMessageStruct(
123-
completed=completed_raise3d,
124-
message=(_("You have completed the Raise3D printer course") if completed_raise3d
125-
else _("You have not taken the Raise3D printer course")),
126-
usage_hint=_(
127-
"To use a Raise3D printer, make a reservation in the calendar of one of the Raise3D printers on the “Reservations” page."
128-
) if completed_raise3d else None,
129-
),
130-
CompletedCourseMessageStruct(
131-
completed=completed_sla,
132-
message=(_("You have completed the SLA 3D printer course") if completed_sla
133-
else _("You have not taken the SLA 3D printer course")),
134-
usage_hint=_(
135-
"To use an SLA 3D printer, make a reservation in the calendar of one of the SLA 3D printers on the “Reservations” page."
136-
) if completed_sla else None,
137-
),
121+
*(
122+
CompletedCourseMessageStruct(
123+
completed=user.printer_3d_course.course_permissions.filter(short_name=c.short_name).exists(),
124+
message=_("You have completed the {} course").format(c.name)
125+
if user.printer_3d_course.course_permissions.filter(short_name=c.short_name).exists()
126+
else _("You have not taken the {} course").format(c.name),
127+
usage_hint=_(
128+
"To use a {}, make a reservation in the calendar of one of the {}s on the “Reservations” page."
129+
).format(c.name, c.name) if user.printer_3d_course.course_permissions.filter(short_name=c.short_name).exists() else None,
130+
)
131+
for c in special_courses if hasattr(user, 'printer_3d_course')
132+
)
138133
]
139134

140135
""" Commented out because it's currently not in use; see the template code in `profile_detail_internal.html`
-885 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)