diff --git a/AKOnline/admin.py b/AKOnline/admin.py index 69f4bed71466a3d8fa84341a3c6fedf05ccb8428..811368858c4c7e4e8d85caa72048ea504c2fe6c8 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 16078585764016d5c291069a30b9f90022a89e16..6d73f96bf131847b1993a49bb8030ad45da0080b 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 bf33b9c4eb3366fb9ea61fe0f2d1867bfa96277f..379ad20b2f87ec917559e370c23cd2bcf4037884 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 dad360cb42df6b602a99d9366b514a0d5ee5d912..6740d3d51326009512f22bec15d71d4a59df5111 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 13f089a893fd77e49f223eba9c4bd9d58f4242bb..ecd82a22219c82370950e30c1645a1b4b0eb099c 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 0000000000000000000000000000000000000000..e9591b4f5895df25170c55b21588eaf290f909e1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[pycodestyle] +max-line-length = 120 +exclude = migrations,static +max-complexity = 11