Skip to content

Commit

Permalink
Merge pull request #121 from Inter-Actief/120-availability-comments
Browse files Browse the repository at this point in the history
Bartender availability comments
  • Loading branch information
Michael-Janssen-dev authored Oct 11, 2024
2 parents 2d420e9 + 4e301df commit 6d3feb0
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 48 deletions.
7 changes: 7 additions & 0 deletions alexia/apps/general/templatetags/get_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django import template

register = template.Library()

@register.filter
def get_item(key, dictionary):
return dictionary.get(key)
22 changes: 22 additions & 0 deletions alexia/apps/scheduling/migrations/0022_auto_20241001_1357.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 2.2.28 on 2024-10-01 14:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scheduling', '0021_auto_20240926_1621'),
]

operations = [
migrations.AlterModelOptions(
name='availability',
options={'ordering': ['position'], 'verbose_name': 'availability type', 'verbose_name_plural': 'availability types'},
),
migrations.AddField(
model_name='bartenderavailability',
name='comment',
field=models.TextField(blank=True, default='', max_length=100, verbose_name='comment'),
),
]
1 change: 1 addition & 0 deletions alexia/apps/scheduling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class BartenderAvailability(models.Model):
verbose_name=_('availability'),
on_delete=models.CASCADE,
)
comment = models.TextField(_('comment'), blank=True, default='', max_length=100)

class Meta:
verbose_name = _('bartender availability')
Expand Down
1 change: 1 addition & 0 deletions alexia/apps/scheduling/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@
# AJAT (Asynchroon Javascript en Tekst... wie gebruikt er nog in
# hemelsnaam XML!?)
url(r'^ajax/bartender_availability/$', views.set_bartender_availability),
url(r'^ajax/bartender_availability/comment/$', views.set_bartender_availability_comment),
]
36 changes: 30 additions & 6 deletions alexia/apps/scheduling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.db.models import Prefetch, Q
from django.http import HttpResponse, JsonResponse
from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy, reverse
from django.utils import timezone
Expand Down Expand Up @@ -108,7 +108,9 @@ def event_list_view(request):
availabilities = list(request.organization.availabilities.exclude(nature=Availability.ASSIGNED))
# Net als onze BartenderAvailabilities
bartender_availabilities = BartenderAvailability.objects.filter(
user_id=request.user.pk).values('event_id', 'availability_id')
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())

Expand Down Expand Up @@ -193,11 +195,11 @@ def get_tenders(self, events):
tenders = []
for tender in tenders_list:
tender_availabilities = [
next((a.availability for a in e.bartender_availabilities.all() if a.user == tender.user), None)
next((a for a in e.bartender_availabilities.all() if a.user == tender.user), None)
for e in events
]
tender_events = [
{'event': event, 'availability': availability}
{'event': event, 'bartender_availability': availability}
for event, availability in zip(events, tender_availabilities)
]
tended = [
Expand Down Expand Up @@ -235,13 +237,13 @@ def get_tender_list(self):
tender_list = []
for tender in tenders:
try:
availability = bas[tender.user].availability
availability = bas[tender.user]
except KeyError:
availability = None

tender_list.append({
'tender': tender,
'availability': availability,
'bartender_availability': availability,
'last_tended': tender.last_tended()
})
return {'tender_list': tender_list}
Expand Down Expand Up @@ -328,6 +330,28 @@ def get_success_url(self):
return super(EventDelete, self).get_success_url()


@login_required
def set_bartender_availability_comment(request):
event = get_object_or_404(Event, pk=request.POST.get('event_id'))

if (request.organization not in event.participants.all()) or \
not request.user.profile.is_tender(request.organization):
raise PermissionDenied

if not (request.method == 'POST' and request.is_ajax()):
return HttpResponseBadRequest("NOTOK")

comment = request.POST.get('comment')
if len(comment) > 100:
return HttpResponseBadRequest("TOOLONG")
availability = get_object_or_404(BartenderAvailability, event=event, user=request.user)
availability.comment = comment
availability.save()


return render(request, 'scheduling/partials/availability_comment.html', {'e': event, 'ba': availability})


@login_required
def set_bartender_availability(request):
event = get_object_or_404(Event, pk=request.POST.get('event_id'))
Expand Down
1 change: 1 addition & 0 deletions alexia/conf/settings/local.py.default
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RADIUS_IDENTIFIER = ''
EMAIL_HOST = 'localhost'
EMAIL_SUBJECT_PREFIX = '[Alexia] '
EMAIL_FROM = 'Alexia <alexia@localhost>'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Log mail messages to console instead of SMTP server!
DEFAULT_FROM_EMAIL = EMAIL_FROM
SERVER_EMAIL = EMAIL_FROM

Expand Down
4 changes: 4 additions & 0 deletions assets/css/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ body {
padding-bottom: 0;
}

.label.label-has-ba-comment {
border: 2px dotted black;
}

.input-static {
padding-top: 7px;
}
Expand Down
31 changes: 30 additions & 1 deletion assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ $.ajaxSetup({
}
});

function resetCommentPrompts() {
$('.bartender_availability_comment').click(function () {
let event_id = $(this).data('event-id');
let comment = prompt('Enter a comment');

if (comment == null || comment == '') {
return;
}

if (comment.length > 100) {
alert('Comment is too long. Maximum 100 characters allowed.');
return;
}

const $this = $(this);

$.post('/scheduling/ajax/bartender_availability/comment/', {
event_id,
comment
}, function (data) {
$this.replaceWith(data);
resetCommentPrompts();
}, "text");
});
}

$(function () {

$('.bartender_availability').change(function () {
Expand All @@ -52,10 +78,13 @@ $(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");
});

resetCommentPrompts();

$('.dateinput').datepicker({
autoclose: true,
format: dateformats[LOCALE],
Expand Down
Binary file modified locale/nl/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 6d3feb0

Please sign in to comment.