From ef15d3ac460bfbc4b2246c0fbf31765f1b0a72c0 Mon Sep 17 00:00:00 2001 From: Michael Janssen Date: Sat, 5 Oct 2024 20:31:55 +0200 Subject: [PATCH] finalize bartender availability comment --- alexia/apps/general/templatetags/get_item.py | 7 ++++++ alexia/apps/scheduling/views.py | 4 +++- assets/js/application.js | 3 ++- templates/scheduling/event_list.html | 22 +++++-------------- .../partials/availability_comment.html | 6 ++--- 5 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 alexia/apps/general/templatetags/get_item.py diff --git a/alexia/apps/general/templatetags/get_item.py b/alexia/apps/general/templatetags/get_item.py new file mode 100644 index 0000000..ccfac04 --- /dev/null +++ b/alexia/apps/general/templatetags/get_item.py @@ -0,0 +1,7 @@ +from django import template + +register = template.Library() + +@register.filter +def get_item(key, dictionary): + return dictionary.get(key) diff --git a/alexia/apps/scheduling/views.py b/alexia/apps/scheduling/views.py index fa6d026..ffcace2 100644 --- a/alexia/apps/scheduling/views.py +++ b/alexia/apps/scheduling/views.py @@ -109,6 +109,8 @@ def event_list_view(request): # Net als onze BartenderAvailabilities bartender_availabilities = BartenderAvailability.objects.filter( user_id=request.user.pk).values('event_id', 'availability_id', 'comment') + + bartender_availabilities = {ba['event_id']: ba for ba in bartender_availabilities} return render(request, 'scheduling/event_list.html', locals()) @@ -340,7 +342,7 @@ def set_bartender_availability_comment(request): return HttpResponseBadRequest("NOTOK") comment = request.POST.get('comment') - if len(comment) > BartenderAvailability.comment.max_length: + if len(comment) > 100: return HttpResponseBadRequest("TOOLONG") availability = get_object_or_404(BartenderAvailability, event=event, user=request.user) availability.comment = comment diff --git a/assets/js/application.js b/assets/js/application.js index 77beafd..893f7b3 100644 --- a/assets/js/application.js +++ b/assets/js/application.js @@ -78,7 +78,8 @@ $(function () { event_id: event_id, availability_id: $(this).val() }, function (data) { - $('#assigned_bartenders_' + event_id).html(data).effect("highlight"); + $('#assigned_bartenders_' + event_id).html(data); + $('#bartender_availability_comment_' + event_id).css('visibility', 'visible'); }, "text"); }); diff --git a/templates/scheduling/event_list.html b/templates/scheduling/event_list.html index d253dbc..a1fd4f3 100644 --- a/templates/scheduling/event_list.html +++ b/templates/scheduling/event_list.html @@ -1,4 +1,5 @@ {% extends 'base_app.html' %} +{% load get_item %} {% block title %}{% trans 'Planning' %}{% endblock title %} @@ -105,30 +106,17 @@

{% if not e.is_closed and request.organization in e.participants.all %} {% if not e.organizer.assigns_tenders or not user in e.get_assigned_bartenders %} - {% for ba in bartender_availabilities %} - {% if ba.event_id == e.pk or forloop.last %} + {% with ba=e.pk|get_item:bartender_availabilities %}
- {% include "scheduling/partials/availability_comment.html" %} + {% include "scheduling/partials/availability_comment.html" %}
- {% endif %} - {% empty %} -
- {% include "scheduling/partials/availability_comment.html" %} - -
- {% endfor %} - + {% endwith %} {% endif %} {% endif %} diff --git a/templates/scheduling/partials/availability_comment.html b/templates/scheduling/partials/availability_comment.html index 6c40f53..ac40bfc 100644 --- a/templates/scheduling/partials/availability_comment.html +++ b/templates/scheduling/partials/availability_comment.html @@ -1,3 +1,3 @@ -
- -
\ No newline at end of file +
+ +
\ No newline at end of file