wip-manager
This commit is contained in:
parent
69e8d97245
commit
58d2eb8582
|
@ -203,11 +203,6 @@ class NewEventForm(forms.ModelForm):
|
|||
'recurrence_end_date': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if self.instance.agenda.partial_bookings:
|
||||
del self.fields['places']
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.cleaned_data.get('frequency') == 'unique':
|
||||
|
|
|
@ -1370,6 +1370,8 @@ class AgendaDayView(AgendaDateView, DayArchiveView):
|
|||
def get_template_names(self):
|
||||
if self.agenda.kind == 'virtual':
|
||||
return ['chrono/manager_meetings_agenda_day_view.html']
|
||||
if self.agenda.partial_bookings:
|
||||
return ['chrono/manager_partial_bookings_day_view.html']
|
||||
return ['chrono/manager_%s_agenda_day_view.html' % self.agenda.kind]
|
||||
|
||||
def get_previous_day_url(self):
|
||||
|
@ -1487,6 +1489,30 @@ class AgendaDayView(AgendaDateView, DayArchiveView):
|
|||
current_date += interval
|
||||
first = False
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if self.agenda.partial_bookings:
|
||||
self.fill_partial_bookings_context(context)
|
||||
return context
|
||||
|
||||
def fill_partial_bookings_context(self, context):
|
||||
events = self.agenda.event_set.filter(start_datetime__date=self.date.date())
|
||||
# TODO avoir une heure en plus/moins
|
||||
min_time = min(x.start_datetime for x in events)
|
||||
max_time = max(x.start_datetime + datetime.timedelta(minutes=x.duration) for x in events)
|
||||
context['hours'] = [
|
||||
min_time + datetime.timedelta(hours=i) for i in range(max_time.hour - min_time.hour)
|
||||
]
|
||||
bookings = Booking.objects.filter(event__in=events)
|
||||
bookings_by_user = collections.defaultdict(list)
|
||||
|
||||
for booking in bookings:
|
||||
bookings_by_user[booking.user_external_id].append(booking)
|
||||
booking.css_left = 100 * (booking.start_datetime - min_time).seconds // 3600
|
||||
booking.css_width = 100 * (booking.end_datetime - booking.start_datetime).seconds // 3600
|
||||
|
||||
context['bookings_by_user'] = dict(bookings_by_user)
|
||||
|
||||
|
||||
agenda_day_view = AgendaDayView.as_view()
|
||||
|
||||
|
|
Loading…
Reference in New Issue