From f6ff4bfd9fb20dcac8885fb7c7a56f88c4719a78 Mon Sep 17 00:00:00 2001 From: Hangzhi Yu <hangzhi@protonmail.com> Date: Wed, 3 Apr 2024 17:28:09 +0200 Subject: [PATCH] Reformat --- .../components/coursebook/Coursebook.vue | 4 +- .../coursebook/CoursebookDateSelect.vue | 7 +- .../documentation/Documentation.vue | 25 +++++-- .../documentation/DocumentationModal.vue | 6 +- .../documentation/DocumentationStatus.vue | 21 +++++- .../documentation/LessonInformation.vue | 9 ++- .../documentation/LessonSummary.vue | 48 +++++++++--- .../documentation/documentationPartMixin.js | 74 +++++++++---------- aleksis/apps/alsijil/models.py | 6 +- aleksis/apps/alsijil/preferences.py | 13 +++- aleksis/apps/alsijil/rules.py | 8 +- aleksis/apps/alsijil/schema/documentation.py | 2 +- aleksis/apps/alsijil/util/predicates.py | 23 +++--- 13 files changed, 157 insertions(+), 89 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue index 3287360be..d8562b800 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue @@ -45,7 +45,9 @@ :key="'day-' + day[0]" > <v-list-item-content :id="'documentation_' + day[0].toISODate()"> - <v-subheader class="text-h6">{{ $d(day[0], "dateWithWeekday") }}</v-subheader> + <v-subheader class="text-h6">{{ + $d(day[0], "dateWithWeekday") + }}</v-subheader> <v-list max-width="100%" class="pt-0 mt-n1"> <v-list-item v-for="doc in day.slice(1)" diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/CoursebookDateSelect.vue b/aleksis/apps/alsijil/frontend/components/coursebook/CoursebookDateSelect.vue index 486f2d234..933bcb29b 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/CoursebookDateSelect.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/CoursebookDateSelect.vue @@ -49,12 +49,7 @@ export default { </script> <template> - <v-footer - app - inset - padless - id="date-select-footer" - > + <v-footer app inset padless id="date-select-footer"> <v-card tile class="full-width"> <v-card-title id="content"> <div class="d-flex align-center justify-center full-width"> diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue index 0f767b923..5bbc21c0d 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/Documentation.vue @@ -1,12 +1,15 @@ <template> - <v-card :class="{'my-1 full-width': true, 'd-flex flex-column': !compact }"> + <v-card :class="{ 'my-1 full-width': true, 'd-flex flex-column': !compact }"> <v-card-title v-if="!compact"> <lesson-information v-bind="documentationPartProps" /> </v-card-title> <v-card-text class="full-width main-body" - :class="{ 'vertical': !compact || $vuetify.breakpoint.mobile, 'pa-2': compact }" + :class="{ + vertical: !compact || $vuetify.breakpoint.mobile, + 'pa-2': compact, + }" > <lesson-information v-if="compact" v-bind="documentationPartProps" /> <lesson-summary @@ -24,9 +27,21 @@ <v-divider /> <v-card-actions v-if="!compact"> <v-spacer /> - <cancel-button v-if="documentation.canEdit" @click="$emit('close')" :disabled="loading" /> - <save-button v-if="documentation.canEdit" @click="save" :loading="loading" /> - <cancel-button v-if="!documentation.canEdit" i18n-key="actions.close" @click="$emit('close')"/> + <cancel-button + v-if="documentation.canEdit" + @click="$emit('close')" + :disabled="loading" + /> + <save-button + v-if="documentation.canEdit" + @click="save" + :loading="loading" + /> + <cancel-button + v-if="!documentation.canEdit" + i18n-key="actions.close" + @click="$emit('close')" + /> </v-card-actions> </v-card> </template> diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationModal.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationModal.vue index 08f5b0ea0..460f39f97 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationModal.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationModal.vue @@ -4,11 +4,7 @@ <mobile-fullscreen-dialog v-model="popup" max-width="500px"> <template #activator="activator"> <!-- list view -> activate dialog --> - <documentation - compact - v-bind="$attrs" - :dialog-activator="activator" - /> + <documentation compact v-bind="$attrs" :dialog-activator="activator" /> </template> <!-- dialog view -> deactivate dialog --> <!-- cancel | save (through lesson-summary) --> diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationStatus.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationStatus.vue index 5622b3413..deb5dda39 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationStatus.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/DocumentationStatus.vue @@ -1,7 +1,13 @@ <template> <v-tooltip bottom> <template v-slot:activator="{ on, attrs }"> - <v-icon :color="currentStatus?.color" class="mr-md-4" v-on="on" v-bind="attrs">{{ currentStatus?.icon }}</v-icon> + <v-icon + :color="currentStatus?.color" + class="mr-md-4" + v-on="on" + v-bind="attrs" + >{{ currentStatus?.icon }}</v-icon + > </template> <span>{{ currentStatus?.text }}</span> </v-tooltip> @@ -77,7 +83,10 @@ export default { } else { if (DateTime.now() > this.documentationDateTimeEnd) { this.currentStatusName = "missing"; - } else if (DateTime.now() > this.documentationDateTimeStart && DateTime.now() < this.documentationDateTimeEnd) { + } else if ( + DateTime.now() > this.documentationDateTimeStart && + DateTime.now() < this.documentationDateTimeEnd + ) { this.currentStatusName = "running"; } else { if (this.documentation?.lessonEvent.amends) { @@ -95,10 +104,14 @@ export default { }, mounted() { this.updateStatus(); - this.statusTimeout = setTimeout(this.updateStatus, this.documentationDateTimeStart.diff(DateTime.now(), "seconds").toObject().seconds); + this.statusTimeout = setTimeout( + this.updateStatus, + this.documentationDateTimeStart.diff(DateTime.now(), "seconds").toObject() + .seconds, + ); }, beforeDestroy() { clearTimeout(this.statusTimeout); }, -} +}; </script> diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue index 3bcc0e682..2632703da 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonInformation.vue @@ -20,7 +20,12 @@ import PersonChip from "aleksis.core/components/person/PersonChip.vue"; <span :class="{ 'text-right': !largeGrid }"> {{ documentation.course?.name }} </span> - <div :class="{ 'd-flex align-center flex-wrap gap': true, 'justify-center': largeGrid }"> + <div + :class="{ + 'd-flex align-center flex-wrap gap': true, + 'justify-center': largeGrid, + }" + > <person-chip v-for="teacher in documentation.teachers" :person="teacher" @@ -58,7 +63,7 @@ export default { computed: { largeGrid() { return this.compact && !this.$vuetify.breakpoint.mobile; - } + }, }, }; </script> diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue index 168c7796d..52e921f33 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/LessonSummary.vue @@ -6,7 +6,10 @@ v-if="compact" > <v-text-field - :class="{ 'flex-grow-1 min-width': true, 'full-width': $vuetify.breakpoint.mobile }" + :class="{ + 'flex-grow-1 min-width': true, + 'full-width': $vuetify.breakpoint.mobile, + }" hide-details outlined :label="$t('alsijil.coursebook.summary.topic')" @@ -16,14 +19,21 @@ @keydown.enter="saveAndBlur" :loading="loading" :readonly="!documentation.canEdit" - > + > <template #append> <v-scroll-x-transition> - <v-icon v-if="appendIcon" :color="appendIconColor">{{ appendIcon }}</v-icon> + <v-icon v-if="appendIcon" :color="appendIconColor">{{ + appendIcon + }}</v-icon> </v-scroll-x-transition> </template> </v-text-field> - <div :class="{ 'flex-grow-1 max-width': true, 'full-width': $vuetify.breakpoint.mobile }"> + <div + :class="{ + 'flex-grow-1 max-width': true, + 'full-width': $vuetify.breakpoint.mobile, + }" + > <v-card v-bind="dialogActivator.attrs" v-on="dialogActivator.on" @@ -110,20 +120,32 @@ export default { ); // merged with the incoming partial documentation // set ID of documentation currently being edited as oldID so that key in coursebook doesn't change - cached[index] = { ...this.documentation, ...object, oldId: this.documentation.id }; + cached[index] = { + ...this.documentation, + ...object, + oldId: this.documentation.id, + }; } return cached; }; }, handleAppendIconSuccess() { this.appendIcon = "$success"; - setTimeout(() => {this.appendIcon = ""}, 3000); + setTimeout(() => { + this.appendIcon = ""; + }, 3000); }, save() { - if (this.topic !== null || this.homework !== null || this.groupNote !== null) { + if ( + this.topic !== null || + this.homework !== null || + this.groupNote !== null + ) { const topic = this.topic !== null ? { topic: this.topic } : {}; - const homework = this.homework !== null ? { homework: this.homework } : {}; - const groupNote = this.groupNote !== null ? { groupNote: this.groupNote } : {}; + const homework = + this.homework !== null ? { homework: this.homework } : {}; + const groupNote = + this.groupNote !== null ? { groupNote: this.groupNote } : {}; this.createOrPatch([ { @@ -175,8 +197,10 @@ export default { return this.$vuetify.breakpoint.mobile ? "100%" : "20ch"; }, appendIconColor() { - return {"$success": "success", "$error": "error"}[this.appendIcon] || "primary"; - } + return ( + { $success: "success", $error: "error" }[this.appendIcon] || "primary" + ); + }, }, mounted() { this.$on("save", this.handleAppendIconSuccess); @@ -190,7 +214,7 @@ export default { } .max-width { - max-width: v-bind(maxWidth) + max-width: v-bind(maxWidth); } .gap { diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationPartMixin.js b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationPartMixin.js index 099878f82..165f1d2fd 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationPartMixin.js +++ b/aleksis/apps/alsijil/frontend/components/coursebook/documentation/documentationPartMixin.js @@ -2,43 +2,43 @@ * Mixin to provide common fields for all components specific to a singular documentation inside the coursebook */ export default { - props: { - /** - * The documentation in question - */ - documentation: { - type: Object, - required: true, - }, - /** - * Whether the documentation is currently in the compact mode (meaning coursebook row) - */ - compact: { - type: Boolean, - required: false, - default: false, - }, - /** - * Activator attributes and event listeners to open documentation dialog in different places - */ - dialogActivator: { - type: Object, - required: false, - default: () => ({ attrs: {}, on: {} }), - }, + props: { + /** + * The documentation in question + */ + documentation: { + type: Object, + required: true, }, + /** + * Whether the documentation is currently in the compact mode (meaning coursebook row) + */ + compact: { + type: Boolean, + required: false, + default: false, + }, + /** + * Activator attributes and event listeners to open documentation dialog in different places + */ + dialogActivator: { + type: Object, + required: false, + default: () => ({ attrs: {}, on: {} }), + }, + }, - computed: { - /** - * All necessary props bundled together to easily pass to child components - * @returns {{compact: Boolean, documentation: Object, dialogActivator: Object<{attrs: Object, on: Object}>}} - */ - documentationPartProps() { - return { - documentation: this.documentation, - compact: this.compact, - dialogActivator: this.dialogActivator, - } - } - } + computed: { + /** + * All necessary props bundled together to easily pass to child components + * @returns {{compact: Boolean, documentation: Object, dialogActivator: Object<{attrs: Object, on: Object}>}} + */ + documentationPartProps() { + return { + documentation: this.documentation, + compact: this.compact, + dialogActivator: this.dialogActivator, + }; + }, + }, }; diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 163e837cb..789086cc1 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -481,7 +481,11 @@ class Documentation(CalendarEvent): ) teachers = models.ManyToManyField( - "core.Person", related_name="documentations_as_teacher", blank=True, null=True, verbose_name=_("Teachers") + "core.Person", + related_name="documentations_as_teacher", + blank=True, + null=True, + verbose_name=_("Teachers"), ) topic = models.CharField(verbose_name=_("Lesson Topic"), max_length=255, blank=True) diff --git a/aleksis/apps/alsijil/preferences.py b/aleksis/apps/alsijil/preferences.py index df34d9a96..b00d9277e 100644 --- a/aleksis/apps/alsijil/preferences.py +++ b/aleksis/apps/alsijil/preferences.py @@ -168,7 +168,16 @@ class AllowEditFutureDocumentations(ChoicePreference): default = "current_day" choices = ( ("all", _("Allow editing of all future documentations")), - ("current_day", _("Allow editing of all documentations up to and including those on the current day")), - ("current_time", _("Allow editing of all documentations up to and including those on the current date and time")), + ( + "current_day", + _("Allow editing of all documentations up to and including those on the current day"), + ), + ( + "current_time", + _( + "Allow editing of all documentations up to and " + "including those on the current date and time" + ), + ), ) verbose_name = _("Set time range for which documentations may be edited") diff --git a/aleksis/apps/alsijil/rules.py b/aleksis/apps/alsijil/rules.py index 9137528a8..f48bf498d 100644 --- a/aleksis/apps/alsijil/rules.py +++ b/aleksis/apps/alsijil/rules.py @@ -401,8 +401,10 @@ add_perm( "alsijil.add_documentation_for_lesson_event_rule", add_documentation_for_lesson_event_predicate ) -edit_documentation_predicate = has_person & ( - has_global_perm("alsijil.change_documentation") | can_edit_documentation -) & is_in_allowed_time_range +edit_documentation_predicate = ( + has_person + & (has_global_perm("alsijil.change_documentation") | can_edit_documentation) + & is_in_allowed_time_range +) add_perm("alsijil.edit_documentation_rule", edit_documentation_predicate) add_perm("alsijil.delete_documentation_rule", edit_documentation_predicate) diff --git a/aleksis/apps/alsijil/schema/documentation.py b/aleksis/apps/alsijil/schema/documentation.py index b5168df07..d115b03eb 100644 --- a/aleksis/apps/alsijil/schema/documentation.py +++ b/aleksis/apps/alsijil/schema/documentation.py @@ -55,7 +55,7 @@ class DocumentationType(PermissionsTypeMixin, DjangoFilterMixin, DjangoObjectTyp @staticmethod def resolve_teachers(root: Documentation, info, **kwargs): if not str(root.pk).startswith("DUMMY") and hasattr(root, "teachers"): - return root.teachers + return root.teachers return root.lesson_event.teachers @classmethod diff --git a/aleksis/apps/alsijil/util/predicates.py b/aleksis/apps/alsijil/util/predicates.py index 2620904be..b1d9c45e5 100644 --- a/aleksis/apps/alsijil/util/predicates.py +++ b/aleksis/apps/alsijil/util/predicates.py @@ -392,9 +392,7 @@ def can_view_documentation(user: User, obj: Documentation): | is_lesson_event_group_owner(user, obj.lesson_event) ) if obj.course: - return ( - is_course_teacher(user, obj.course) - ) + return is_course_teacher(user, obj.course) return False @@ -414,11 +412,16 @@ def can_edit_documentation(user: User, obj: Documentation): @predicate def is_in_allowed_time_range(user: User, obj: Documentation): """Predicate which checks if the documentation is in the allowed time range for editing.""" - if obj: - if get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all": - return True - elif get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_day" and obj.datetime_start.date() <= localdate(): - return True - elif get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_time" and obj.datetime_start <= localtime(): - return True + if obj and ( + get_site_preferences()["alsijil__allow_edit_future_documentations"] == "all" + or ( + get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_day" + and obj.datetime_start.date() <= localdate() + ) + or ( + get_site_preferences()["alsijil__allow_edit_future_documentations"] == "current_time" + and obj.datetime_start <= localtime() + ) + ): + return True return False -- GitLab