Skip to content
Snippets Groups Projects
Verified Commit 402fb8ab authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix some bugs

parent 3535a8ae
No related branches found
No related tags found
1 merge request!2Views
......@@ -4,6 +4,7 @@ from django_select2.forms import ModelSelect2Widget
from material import Layout, Row
from aleksis.core.mixins import ExtensibleForm
from aleksis.core.models import Group
from .models import Seat, SeatingPlan
......@@ -17,6 +18,16 @@ class SeatingPlanCreateForm(forms.ModelForm):
)
)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")
super().__init__(*args, **kwargs)
qs = Group.objects.all()
if not self.request.user.has_perm("stoelindeling.view_seatingplan"):
qs = qs.filter(owners=self.request.user.person)
self.fields["group"].queryset = qs
class Meta:
model = SeatingPlan
fields = ["group", "subject", "room"]
......
......@@ -20,8 +20,8 @@ class SeatQuerySet(QuerySet):
start_y = aggr["y__min"] or 0
end_x = aggr["x__max"] or 0
end_y = aggr["y__max"] or 0
width = max(10, end_x - start_x)
height = max(10, end_y - start_y)
width = max(3, end_x - start_x)
height = max(3, end_y - start_y)
end_x = start_x + width
end_y = start_y + height
......
......@@ -11,7 +11,9 @@ class SeatingPlan(ExtensibleModel):
"""Seating plan model."""
group = models.ForeignKey(Group, on_delete=models.CASCADE, verbose_name=_("Group"))
subject = models.ForeignKey(Subject, on_delete=models.CASCADE, verbose_name=_("Subject"))
subject = models.ForeignKey(
Subject, on_delete=models.CASCADE, verbose_name=_("Subject"), blank=True, null=True
)
room = models.ForeignKey(Room, on_delete=models.CASCADE, verbose_name=_("Room"))
def get_all_seats(self) -> SeatQuerySet:
......
{# -*- engine:django -*- #}
{% extends "core/base.html" %}
{% load i18n static %}
{% load i18n static rules %}
{% block browser_title %}{% blocktrans %}Seating plan{% endblocktrans %}{% endblock %}
......
......@@ -21,7 +21,7 @@ def get_allowed_seating_plans(user):
user, "stoelindeling.view_seatingplan", SeatingPlan
).values_list("pk", flat=True)
)
| Q(owner=user.person)
| Q(group__owners=user.person)
)
return qs
......
......@@ -49,6 +49,11 @@ class SeatingPlanCreateView(PermissionRequiredMixin, AdvancedCreateView):
success_url = reverse_lazy("seating_plans")
success_message = _("The seating plan has been created.")
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs["request"] = self.request
return kwargs
@method_decorator(never_cache, name="dispatch")
class SeatingPlanEditView(PermissionRequiredMixin, AdvancedEditView):
......@@ -58,7 +63,6 @@ class SeatingPlanEditView(PermissionRequiredMixin, AdvancedEditView):
form_class = SeatingPlanForm
permission_required = "stoelindeling.edit_seatingplan_rule"
template_name = "stoelindeling/seating_plan/edit.html"
success_url = reverse_lazy("seating_plans")
success_message = _("The seating plan has been saved.")
def get_context_data(self, **kwargs):
......@@ -108,7 +112,7 @@ class SeatingPlanEditView(PermissionRequiredMixin, AdvancedEditView):
Seat.objects.bulk_update(objects_to_update, ["x", "y", "seated"])
messages.success(self.request, _("The seating plan has been updated."))
return redirect("edit_seating_plan", self.object.pk)
return redirect("seating_plan", self.object.pk)
return super().form_invalid(form)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment