diff --git a/AKSubmission/forms.py b/AKSubmission/forms.py index e24e0a41f41d4a3625a9b0c421ac0d959e5feeb0..55959be4be524a2d801ac8fd8c51925b48098101 100644 --- a/AKSubmission/forms.py +++ b/AKSubmission/forms.py @@ -151,7 +151,7 @@ class AKEditForm(AKForm): self.fields["tags_raw"].initial = "; ".join(str(tag) for tag in self.instance.tags.all()) -class AKWishForm(AKSubmissionForm): +class AKWishForm(AKForm): class Meta(AKForm.Meta): exclude = ['owners', 'link', 'protocol_link'] diff --git a/AKSubmission/templates/AKSubmission/ak_detail.html b/AKSubmission/templates/AKSubmission/ak_detail.html index 69324b6349e693c8c04fb7b098573f4ed4c5d02c..e5052faf507aeec00ee546ab0e02f14082c700b6 100644 --- a/AKSubmission/templates/AKSubmission/ak_detail.html +++ b/AKSubmission/templates/AKSubmission/ak_detail.html @@ -235,95 +235,96 @@ <p style="margin-top: 30px;margin-bottom: 30px;">{{ ak.description|linebreaks }}</p> - - <table class="table"> - <thead> - <tr> - {% if not ak.event.plan_hidden or user.is_staff %} - <th>{% trans "When?" %}</th> - {% endif %} - <th>{% trans "Duration" %}</th> - {% if not ak.event.plan_hidden or user.is_staff %} - <th>{% trans "Room" %}</th> - {% endif %} - <th></th> - </tr> - </thead> - <tbody> - {% for slot in ak.akslot_set.all %} + {% if not ak.wish %} + <table class="table"> + <thead> <tr> {% if not ak.event.plan_hidden or user.is_staff %} - <td>{{ slot.time_simplified }}</td> + <th>{% trans "When?" %}</th> {% endif %} - <td>{{ slot.duration_simplified }}</td> + <th>{% trans "Duration" %}</th> {% if not ak.event.plan_hidden or user.is_staff %} - <td> - {% if slot.room %} - {% if "AKPlan"|check_app_installed %} - <a href="{% url 'plan:plan_room' event_slug=ak.event.slug pk=slot.room.pk %}">{{ slot.room }}</a> + <th>{% trans "Room" %}</th> + {% endif %} + <th></th> + </tr> + </thead> + <tbody> + {% for slot in ak.akslot_set.all %} + <tr> + {% if not ak.event.plan_hidden or user.is_staff %} + <td>{{ slot.time_simplified }}</td> + {% endif %} + <td>{{ slot.duration_simplified }}</td> + {% if not ak.event.plan_hidden or user.is_staff %} + <td> + {% if slot.room %} + {% if "AKPlan"|check_app_installed %} + <a href="{% url 'plan:plan_room' event_slug=ak.event.slug pk=slot.room.pk %}">{{ slot.room }}</a> + {% else %} + {{ slot.room }} + {% endif %} {% else %} - {{ slot.room }} + - {% endif %} + </td> + {% endif %} + <td> + {% if not slot.start %} + <a href="{% url 'submit:akslot_edit' event_slug=ak.event.slug pk=slot.pk %}" + data-toggle="tooltip" title="{% trans 'Edit' %}" + class="btn btn-success">{% fa5_icon 'pencil-alt' 'fas' %}</a> + <a href="{% url 'submit:akslot_delete' event_slug=ak.event.slug pk=slot.pk %}" + data-toggle="tooltip" title="{% trans 'Delete' %}" + class="btn btn-danger">{% fa5_icon 'times' 'fas' %}</a> {% else %} - - + {% if "AKOnline"|check_app_installed and slot.room and slot.room.virtualroom and slot.room.virtualroom.url != '' %} + <a class="btn btn-success" href="{{ slot.room.virtualroom.url }}"> + {% fa5_icon 'external-link-alt' 'fas' %} {% trans "Go to virtual room" %} + </a> + {% endif %} {% endif %} - </td> - {% endif %} - <td> - {% if not slot.start %} - <a href="{% url 'submit:akslot_edit' event_slug=ak.event.slug pk=slot.pk %}" - data-toggle="tooltip" title="{% trans 'Edit' %}" - class="btn btn-success">{% fa5_icon 'pencil-alt' 'fas' %}</a> - <a href="{% url 'submit:akslot_delete' event_slug=ak.event.slug pk=slot.pk %}" - data-toggle="tooltip" title="{% trans 'Delete' %}" - class="btn btn-danger">{% fa5_icon 'times' 'fas' %}</a> - {% else %} - {% if "AKOnline"|check_app_installed and slot.room and slot.room.virtualroom and slot.room.virtualroom.url != '' %} - <a class="btn btn-success" href="{{ slot.room.virtualroom.url }}"> - {% fa5_icon 'external-link-alt' 'fas' %} {% trans "Go to virtual room" %} - </a> + {% if user.is_staff %} + <a href="{% url 'admin:AKModel_akslot_change' slot.pk %}" + data-toggle="tooltip" title="{% trans 'Schedule' %}" + class="btn btn-outline-success">{% fa5_icon 'stream' 'fas' %}</a> {% endif %} - {% endif %} - {% if user.is_staff %} - <a href="{% url 'admin:AKModel_akslot_change' slot.pk %}" - data-toggle="tooltip" title="{% trans 'Schedule' %}" - class="btn btn-outline-success">{% fa5_icon 'stream' 'fas' %}</a> - {% endif %} - </td> - </tr> - {% endfor %} - </tbody> - </table> + </td> + </tr> + {% endfor %} + </tbody> + </table> - {% if ak.event.active %} - <div class=""> - <a href="{% url 'submit:akslot_add' event_slug=ak.event.slug pk=ak.pk %}" - class="btn btn-success">{% fa5_icon 'plus' 'fas' %} {% trans "Add another slot" %}</a> - </div> - {% endif %} + {% if ak.event.active %} + <div class=""> + <a href="{% url 'submit:akslot_add' event_slug=ak.event.slug pk=ak.pk %}" + class="btn btn-success">{% fa5_icon 'plus' 'fas' %} {% trans "Add another slot" %}</a> + </div> + {% endif %} - {% if 'AKPlan'|check_app_installed %} - <div id='akSlotCalendar' style="margin-top: 50px;margin-bottom: 50px;"></div> - {% endif %} + {% if 'AKPlan'|check_app_installed %} + <div id='akSlotCalendar' style="margin-top: 50px;margin-bottom: 50px;"></div> + {% endif %} - <h4 style="margin-top: 30px;">{% trans "Possible Times" %}</h4> - <table class="table"> - <thead> - <tr> - <th>{% trans "Start" %}</th> - <th>{% trans "End" %}</th> - </tr> - </thead> - <tbody> - {% for a in availabilities %} + <h4 style="margin-top: 30px;">{% trans "Possible Times" %}</h4> + <table class="table"> + <thead> <tr> - <td>{{ a.start | timezone:event.timezone | date:"l H:i" }}</td> - <td>{{ a.end | timezone:event.timezone | date:"l H:i" }}</td> + <th>{% trans "Start" %}</th> + <th>{% trans "End" %}</th> </tr> - {% endfor %} - </tbody> - </table> + </thead> + <tbody> + {% for a in availabilities %} + <tr> + <td>{{ a.start | timezone:event.timezone | date:"l H:i" }}</td> + <td>{{ a.end | timezone:event.timezone | date:"l H:i" }}</td> + </tr> + {% endfor %} + </tbody> + </table> + {% endif %} {% endblock %} diff --git a/AKSubmission/views.py b/AKSubmission/views.py index 28e6b6d1838c5244e0d801f41f1789fe2f37b28e..15d0811d467f4055394cedd0e8de0584adfa972a 100644 --- a/AKSubmission/views.py +++ b/AKSubmission/views.py @@ -223,10 +223,11 @@ class AKAndAKWishSubmissionView(EventSlugMixin, EventInactiveRedirectMixin, Crea tag, was_created = AKTag.objects.get_or_create(name=tag_name) self.object.tags.add(tag) - # Generate slot(s) - for duration in form.cleaned_data["durations"]: - new_slot = AKSlot(ak=self.object, duration=duration, event=self.object.event) - new_slot.save() + # Generate slot(s) (but not for wishes) + if "durations" in form.cleaned_data: + for duration in form.cleaned_data["durations"]: + new_slot = AKSlot(ak=self.object, duration=duration, event=self.object.event) + new_slot.save() return super_form_valid @@ -269,6 +270,8 @@ class AKEditView(EventSlugMixin, EventInactiveRedirectMixin, UpdateView): return redirect(reverse_lazy('submit:submission_overview', kwargs={'event_slug': form.cleaned_data["event"].slug})) + previous_owner_count = self.object.owners.count() + super_form_valid = super().form_valid(form) # Detach existing tags @@ -279,6 +282,17 @@ class AKEditView(EventSlugMixin, EventInactiveRedirectMixin, UpdateView): tag, was_created = AKTag.objects.get_or_create(name=tag_name) self.object.tags.add(tag) + # Did this AK change from wish to AK or vice versa? + new_owner_count = self.object.owners.count() + # Now AK: + if previous_owner_count == 0 and new_owner_count > 0 and self.object.akslot_set.count() == 0: + # Create one slot with default length + AKSlot.objects.create(ak=self.object, duration=self.object.event.default_slot, event=self.object.event) + # Now wish: + elif previous_owner_count > 0 and new_owner_count == 0: + # Delete all unscheduled slots + self.object.akslot_set.filter(start__isnull=True).delete() + return super_form_valid