Skip to content
Snippets Groups Projects
Commit 1133ded4 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

Improve slot handling for wishes

This implements #144
Don't show slots, slot creation button, and availabilities for wishes on detail page
Don't create slots for wishes automatically (and don't ask for durations)
Automatically create one slot when wish changes to AK
Automatically remove all unscheduled slots when AK changes to wish
parent 35f54089
No related branches found
No related tags found
No related merge requests found
...@@ -151,7 +151,7 @@ class AKEditForm(AKForm): ...@@ -151,7 +151,7 @@ class AKEditForm(AKForm):
self.fields["tags_raw"].initial = "; ".join(str(tag) for tag in self.instance.tags.all()) 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): class Meta(AKForm.Meta):
exclude = ['owners', 'link', 'protocol_link'] exclude = ['owners', 'link', 'protocol_link']
......
...@@ -235,95 +235,96 @@ ...@@ -235,95 +235,96 @@
<p style="margin-top: 30px;margin-bottom: 30px;">{{ ak.description|linebreaks }}</p> <p style="margin-top: 30px;margin-bottom: 30px;">{{ ak.description|linebreaks }}</p>
{% if not ak.wish %}
<table class="table"> <table class="table">
<thead> <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 %}
<tr> <tr>
{% if not ak.event.plan_hidden or user.is_staff %} {% if not ak.event.plan_hidden or user.is_staff %}
<td>{{ slot.time_simplified }}</td> <th>{% trans "When?" %}</th>
{% endif %} {% endif %}
<td>{{ slot.duration_simplified }}</td> <th>{% trans "Duration" %}</th>
{% if not ak.event.plan_hidden or user.is_staff %} {% if not ak.event.plan_hidden or user.is_staff %}
<td> <th>{% trans "Room" %}</th>
{% if slot.room %} {% endif %}
{% if "AKPlan"|check_app_installed %} <th></th>
<a href="{% url 'plan:plan_room' event_slug=ak.event.slug pk=slot.room.pk %}">{{ slot.room }}</a> </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 %} {% else %}
{{ slot.room }} -
{% 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 %} {% 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 %} {% endif %}
</td> {% if user.is_staff %}
{% endif %} <a href="{% url 'admin:AKModel_akslot_change' slot.pk %}"
<td> data-toggle="tooltip" title="{% trans 'Schedule' %}"
{% if not slot.start %} class="btn btn-outline-success">{% fa5_icon 'stream' 'fas' %}</a>
<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 %}
{% endif %} </td>
{% if user.is_staff %} </tr>
<a href="{% url 'admin:AKModel_akslot_change' slot.pk %}" {% endfor %}
data-toggle="tooltip" title="{% trans 'Schedule' %}" </tbody>
class="btn btn-outline-success">{% fa5_icon 'stream' 'fas' %}</a> </table>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if ak.event.active %} {% if ak.event.active %}
<div class=""> <div class="">
<a href="{% url 'submit:akslot_add' event_slug=ak.event.slug pk=ak.pk %}" <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> class="btn btn-success">{% fa5_icon 'plus' 'fas' %} {% trans "Add another slot" %}</a>
</div> </div>
{% endif %} {% endif %}
{% if 'AKPlan'|check_app_installed %} {% if 'AKPlan'|check_app_installed %}
<div id='akSlotCalendar' style="margin-top: 50px;margin-bottom: 50px;"></div> <div id='akSlotCalendar' style="margin-top: 50px;margin-bottom: 50px;"></div>
{% endif %} {% endif %}
<h4 style="margin-top: 30px;">{% trans "Possible Times" %}</h4> <h4 style="margin-top: 30px;">{% trans "Possible Times" %}</h4>
<table class="table"> <table class="table">
<thead> <thead>
<tr>
<th>{% trans "Start" %}</th>
<th>{% trans "End" %}</th>
</tr>
</thead>
<tbody>
{% for a in availabilities %}
<tr> <tr>
<td>{{ a.start | timezone:event.timezone | date:"l H:i" }}</td> <th>{% trans "Start" %}</th>
<td>{{ a.end | timezone:event.timezone | date:"l H:i" }}</td> <th>{% trans "End" %}</th>
</tr> </tr>
{% endfor %} </thead>
</tbody> <tbody>
</table> {% 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 %} {% endblock %}
...@@ -223,10 +223,11 @@ class AKAndAKWishSubmissionView(EventSlugMixin, EventInactiveRedirectMixin, Crea ...@@ -223,10 +223,11 @@ class AKAndAKWishSubmissionView(EventSlugMixin, EventInactiveRedirectMixin, Crea
tag, was_created = AKTag.objects.get_or_create(name=tag_name) tag, was_created = AKTag.objects.get_or_create(name=tag_name)
self.object.tags.add(tag) self.object.tags.add(tag)
# Generate slot(s) # Generate slot(s) (but not for wishes)
for duration in form.cleaned_data["durations"]: if "durations" in form.cleaned_data:
new_slot = AKSlot(ak=self.object, duration=duration, event=self.object.event) for duration in form.cleaned_data["durations"]:
new_slot.save() new_slot = AKSlot(ak=self.object, duration=duration, event=self.object.event)
new_slot.save()
return super_form_valid return super_form_valid
...@@ -269,6 +270,8 @@ class AKEditView(EventSlugMixin, EventInactiveRedirectMixin, UpdateView): ...@@ -269,6 +270,8 @@ class AKEditView(EventSlugMixin, EventInactiveRedirectMixin, UpdateView):
return redirect(reverse_lazy('submit:submission_overview', return redirect(reverse_lazy('submit:submission_overview',
kwargs={'event_slug': form.cleaned_data["event"].slug})) kwargs={'event_slug': form.cleaned_data["event"].slug}))
previous_owner_count = self.object.owners.count()
super_form_valid = super().form_valid(form) super_form_valid = super().form_valid(form)
# Detach existing tags # Detach existing tags
...@@ -279,6 +282,17 @@ class AKEditView(EventSlugMixin, EventInactiveRedirectMixin, UpdateView): ...@@ -279,6 +282,17 @@ class AKEditView(EventSlugMixin, EventInactiveRedirectMixin, UpdateView):
tag, was_created = AKTag.objects.get_or_create(name=tag_name) tag, was_created = AKTag.objects.get_or_create(name=tag_name)
self.object.tags.add(tag) 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 return super_form_valid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment