From 04ec72897269a4ddea6fd5dc38f2778a0861a808 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Mon, 21 Nov 2022 22:40:33 +0000 Subject: [PATCH] Reimplemented calendar mostly working Multi day alignment puzzle is pretty hard... --- RIGS/models.py | 6 +- RIGS/templates/calendar.html | 85 +++++++++++++------------ RIGS/utils.py | 34 ++++++---- RIGS/views/rigboard.py | 2 +- gulpfile.js | 2 - pipeline/source_assets/scss/screen.scss | 4 ++ 6 files changed, 75 insertions(+), 58 deletions(-) diff --git a/RIGS/models.py b/RIGS/models.py index 59533cb6..e6c85e08 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -401,10 +401,6 @@ class BaseEvent(models.Model, RevisionMixin): errdict['end_time'] = ['Unless you\'ve invented time travel, the event can\'t finish before it has started.'] return errdict - @property - def get_html_url(self): - return f'{self}' - def __str__(self): return f"{self.display_id}: {self.name}" @@ -503,7 +499,7 @@ class Event(BaseEvent): @property def authorised(self): - if self.internal: + if self.internal and hasattr(self, 'authorisation'): return self.authorisation.amount == self.total else: return bool(self.purchase_order) diff --git a/RIGS/templates/calendar.html b/RIGS/templates/calendar.html index 3e83ea6a..78474244 100644 --- a/RIGS/templates/calendar.html +++ b/RIGS/templates/calendar.html @@ -1,59 +1,66 @@ {% extends 'base_rigs.html' %} {% load static %} -{% block title %}Calendar{% endblock %} +{% block js %} + + +{% endblock %} {% block css %} {% endblock %} {% block content %} -
- Previous Month - Next Month +
+ Previous Month +
+ + + + +
+ + Next Month
+ +
{{ calendar }} +
{% endblock %} diff --git a/RIGS/utils.py b/RIGS/utils.py index 99ad2971..9d53d309 100644 --- a/RIGS/utils.py +++ b/RIGS/utils.py @@ -3,6 +3,24 @@ import calendar from calendar import HTMLCalendar from RIGS.models import BaseEvent, Event, Subhire +def get_html(events, day): + d = '' + for event in events: + # Open shared stuff + d += f'{event}' + elif day == event.end_date.day: + d += f'style="border-top-left-radius: 0; border-bottom-left-radius: 0;"> ' + else: + d += f'style="border-radius: 0;"> ' + else: + d += f'{event}' + # Close shared stuff + d += "" + return d + class Calendar(HTMLCalendar): def __init__(self, year=None, month=None): self.year = year @@ -12,16 +30,11 @@ class Calendar(HTMLCalendar): # formats a day as a td # filter events by day def formatday(self, day, events, subhires): - events_per_day = events.filter(start_date__day=day) - subhires_per_day = subhires.filter(start_date__day=day) - d = '' - for event in events_per_day: - d += f'{event.get_html_url}
' - for subhire in subhires_per_day: - d += f'{subhire.get_html_url}
' - + events_per_day = events.order_by("start_date").filter(start_date__day__lte=day, end_date__day__gte=day) + subhires_per_day = subhires.order_by("start_date").filter(start_date__day__lte=day, end_date__day__gte=day) + d = get_html(events_per_day, day) + get_html(subhires_per_day, day) if day != 0: - return f"{day}" + return f"{day}
{d}" return '' # formats a week as a tr @@ -37,8 +50,7 @@ class Calendar(HTMLCalendar): events = Event.objects.filter(start_date__year=self.year, start_date__month=self.month) subhires = Subhire.objects.filter(start_date__year=self.year, start_date__month=self.month) - cal = f'\n' - cal += f'{self.formatmonthname(self.year, self.month, withyear=withyear)}\n' + cal = f'
\n' cal += f'{self.formatweekheader()}\n' for week in self.monthdays2calendar(self.year, self.month): cal += f'{self.formatweek(week, events, subhires)}\n' diff --git a/RIGS/views/rigboard.py b/RIGS/views/rigboard.py index eb8066ba..9117b702 100644 --- a/RIGS/views/rigboard.py +++ b/RIGS/views/rigboard.py @@ -47,7 +47,6 @@ class WebCalendar(generic.ListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - # use today's date for the calendar d = utils.get_date(self.request.GET.get('month', None)) context['prev_month'] = utils.prev_month(d) @@ -59,6 +58,7 @@ class WebCalendar(generic.ListView): # Call the formatmonth method, which returns our calendar as a table html_cal = cal.formatmonth(withyear=True) context['calendar'] = mark_safe(html_cal) + context['page_title'] = d.strftime("%B %Y") return context diff --git a/gulpfile.js b/gulpfile.js index 9d770813..19e1c3ad 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,7 +24,6 @@ function fonts(done) { function styles(done) { const bs_select = ["bootstrap-select.css", "ajax-bootstrap-select.css"] return gulp.src(['pipeline/source_assets/scss/**/*.scss', - 'node_modules/fullcalendar/main.css', 'node_modules/bootstrap-select/dist/css/bootstrap-select.css', 'node_modules/ajax-bootstrap-select/dist/css/ajax-bootstrap-select.css', 'node_modules/easymde/dist/easymde.min.css' @@ -59,7 +58,6 @@ function scripts() { 'node_modules/html5sortable/dist/html5sortable.min.js', 'node_modules/clipboard/dist/clipboard.min.js', 'node_modules/moment/moment.js', - 'node_modules/fullcalendar/main.js', 'node_modules/bootstrap-select/dist/js/bootstrap-select.js', 'node_modules/ajax-bootstrap-select/dist/js/ajax-bootstrap-select.js', 'node_modules/easymde/dist/easymde.min.js', diff --git a/pipeline/source_assets/scss/screen.scss b/pipeline/source_assets/scss/screen.scss index 4202478e..b37d1883 100644 --- a/pipeline/source_assets/scss/screen.scss +++ b/pipeline/source_assets/scss/screen.scss @@ -281,3 +281,7 @@ html.embedded { .bootstrap-select, button.btn.dropdown-toggle.bs-placeholder.btn-light { padding-right: 1rem !important; } + +.badge-purple, .bg-purple { + background-color: #800080 !important; +}