From f1123336e4bee3340f12d9d21a81fcda1033e45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Sun, 11 Jun 2023 23:38:01 +0200 Subject: [PATCH] Improve documentation and resolve quality issues for AKOnline Add comments Adjust style to python3 conventions Remove unused imports --- AKOnline/admin.py | 3 +++ AKOnline/apps.py | 3 +++ AKOnline/forms.py | 21 ++++++++++++++++++--- AKOnline/models.py | 8 +++++++- AKOnline/views.py | 15 +++++++++++++-- setup.cfg | 4 ++++ 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 setup.cfg diff --git a/AKOnline/admin.py b/AKOnline/admin.py index 69f4bed7..81136885 100644 --- a/AKOnline/admin.py +++ b/AKOnline/admin.py @@ -5,6 +5,9 @@ from AKOnline.models import VirtualRoom @admin.register(VirtualRoom) class VirtualRoomAdmin(admin.ModelAdmin): + """ + Admin interface for virtual room model + """ model = VirtualRoom list_display = ['room', 'event', 'url'] list_filter = ['room__event'] diff --git a/AKOnline/apps.py b/AKOnline/apps.py index 16078585..6d73f96b 100644 --- a/AKOnline/apps.py +++ b/AKOnline/apps.py @@ -2,4 +2,7 @@ from django.apps import AppConfig class AkonlineConfig(AppConfig): + """ + App configuration (default -- only to set the app name) + """ name = 'AKOnline' diff --git a/AKOnline/forms.py b/AKOnline/forms.py index bf33b9c4..379ad20b 100644 --- a/AKOnline/forms.py +++ b/AKOnline/forms.py @@ -6,23 +6,38 @@ from AKOnline.models import VirtualRoom class VirtualRoomForm(ModelForm): + """ + Form to create a virtual room + + Should be used as part of a multi form (see :class:`RoomWithVirtualForm` below) + """ class Meta: model = VirtualRoom - exclude = ['room'] + # Show all fields except for room + exclude = ['room'] #pylint: disable=modelform-uses-exclude def __init__(self, *args, **kwargs): - super(VirtualRoomForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) + # Make the URL field optional to allow submitting the multi form without creating a virtual room self.fields['url'].required = False class RoomWithVirtualForm(MultiModelForm): + """ + Combined form to create rooms and optionally virtual rooms + + Multi-Form that combines a :class:`RoomForm` (from AKModel) and a :class:`VirtualRoomForm` (see above). + + The form will always create a room on valid input + and may additionally create a virtual room if the url field of the virtual room form part is set. + """ form_classes = { 'room': RoomForm, 'virtual': VirtualRoomForm } def save(self, commit=True): - objects = super(RoomWithVirtualForm, self).save(commit=False) + objects = super().save(commit=False) if commit: room = objects['room'] diff --git a/AKOnline/models.py b/AKOnline/models.py index dad360cb..6740d3d5 100644 --- a/AKOnline/models.py +++ b/AKOnline/models.py @@ -1,7 +1,7 @@ from django.db import models from django.utils.translation import gettext_lazy as _ -from AKModel.models import Event, Room +from AKModel.models import Room class VirtualRoom(models.Model): @@ -18,6 +18,12 @@ class VirtualRoom(models.Model): @property def event(self): + """ + Property: Event this virtual room belongs to. + + :return: Event this virtual room belongs to + :rtype: Event + """ return self.room.event def __str__(self): diff --git a/AKOnline/views.py b/AKOnline/views.py index 13f089a8..ecd82a22 100644 --- a/AKOnline/views.py +++ b/AKOnline/views.py @@ -9,20 +9,31 @@ from AKOnline.forms import RoomWithVirtualForm class RoomCreationWithVirtualView(RoomCreationView): + """ + View to create both rooms and optionally virtual rooms by filling one form + """ form_class = RoomWithVirtualForm template_name = 'admin/AKOnline/room_create_with_virtual.html' + room = None def form_valid(self, form): + # This will create the room and additionally a virtual room if the url field is not blank + # objects['room'] will always a room instance afterwards, objects['virtual'] may be empty objects = form.save() self.room = objects['room'] - messages.success(self.request, _("Created Room '%(room)s'" % {'room': objects['room']})) + # Create a (translated) success message containing information about the created room + messages.success(self.request, _("Created Room '%(room)s'" % {'room': objects['room']})) #pylint: disable=consider-using-f-string, line-too-long if objects['virtual'] is not None: - messages.success(self.request, _("Created related Virtual Room '%(vroom)s'" % {'vroom': objects['virtual']})) + # Create a (translated) success message containing information about the created virtual room + messages.success(self.request, _("Created related Virtual Room '%(vroom)s'" % {'vroom': objects['virtual']})) #pylint: disable=consider-using-f-string, line-too-long return HttpResponseRedirect(self.get_success_url()) @status_manager.register(name="event_virtual_rooms") class EventVirtualRoomsWidget(TemplateStatusWidget): + """ + Status page widget to contain information about all virtual rooms belonging to the given event + """ required_context_type = "event" title = _("Virtual Rooms") template_name = "admin/AKOnline/status/event_virtual_rooms.html" diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..e9591b4f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[pycodestyle] +max-line-length = 120 +exclude = migrations,static +max-complexity = 11 -- GitLab