Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • konstantin/akplanning
  • matedealer/akplanning
  • kif/akplanning
  • mirco/akplanning
  • lordofthevoid/akplanning
  • voidptr/akplanning
  • xayomer/akplanning-fork
  • mollux/akplanning
  • neumantm/akplanning
  • mmarx/akplanning
  • nerf/akplanning
  • felix_bonn/akplanning
  • sebastian.uschmann/akplanning
13 results
Show changes
Commits on Source (184)
Showing
with 832 additions and 218 deletions
uwsgi==2.0.19.1 uwsgi==2.0.28
image: python:3.9 image: python:3.11
services: services:
- mysql:5.7 - mysql
variables: variables:
MYSQL_DATABASE: "test" MYSQL_DATABASE: "test"
...@@ -14,24 +14,26 @@ cache: ...@@ -14,24 +14,26 @@ cache:
paths: paths:
- ~/.cache/pip/ - ~/.cache/pip/
before_script: .before_script_template:
- python -V # Print out python version for debugging before_script:
- apt-get -qq update - python -V # Print out python version for debugging
- apt-get -qq install -y python3-virtualenv python3 python3-dev python3-pip gettext default-mysql-client default-libmysqlclient-dev - apt-get -qq update
- export DJANGO_SETTINGS_MODULE=AKPlanning.settings_ci - apt-get -qq install -y python3-virtualenv python3 python3-dev python3-pip gettext default-mysql-client default-libmysqlclient-dev
- ./Utils/setup.sh --prod - ./Utils/setup.sh --ci
- mysql --version - mkdir -p public/badges public/lint
- echo undefined > public/badges/$CI_JOB_NAME.score
check: - source venv/bin/activate
script: - pip install pylint-gitlab pylint-django
- ./Utils/check.sh --all - mysql --version
check-migrations: migrations:
extends: .before_script_template
script: script:
- source venv/bin/activate - source venv/bin/activate
- ./manage.py makemigrations --dry-run --check - ./manage.py makemigrations --dry-run --check
test: test:
extends: .before_script_template
script: script:
- source venv/bin/activate - source venv/bin/activate
- echo "GRANT ALL on *.* to '${MYSQL_USER}';"| mysql -u root --password="${MYSQL_ROOT_PASSWORD}" -h mysql - echo "GRANT ALL on *.* to '${MYSQL_USER}';"| mysql -u root --password="${MYSQL_ROOT_PASSWORD}" -h mysql
...@@ -48,3 +50,44 @@ test: ...@@ -48,3 +50,44 @@ test:
coverage_format: cobertura coverage_format: cobertura
path: coverage.xml path: coverage.xml
junit: unit.xml junit: unit.xml
lint:
extends: .before_script_template
stage: test
script:
- pylint --load-plugins pylint_django --django-settings-module=AKPlanning.settings_ci --rcfile pylintrc --exit-zero --output-format=text AK* | tee /tmp/pylint.txt
- sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' /tmp/pylint.txt > public/badges/$CI_JOB_NAME.score
- pylint --load-plugins pylint_django --django-settings-module=AKPlanning.settings_ci --rcfile pylintrc --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter AK* > codeclimate.json
- pylint --load-plugins pylint_django --django-settings-module=AKPlanning.settings_ci --rcfile pylintrc --exit-zero --output-format=pylint_gitlab.GitlabPagesHtmlReporter AK* > public/lint/index.html
after_script:
- |
echo "Linting score: $(cat public/badges/$CI_JOB_NAME.score)"
artifacts:
paths:
- public
reports:
codequality: codeclimate.json
when: always
doc:
extends: .before_script_template
stage: test
script:
- cd docs
- make html
- cd ..
artifacts:
paths:
- docs/_build/html
pages:
stage: deploy
image: alpine:latest
script:
- echo
artifacts:
paths:
- public
only:
refs:
- main
...@@ -4,6 +4,9 @@ from AKDashboard.models import DashboardButton ...@@ -4,6 +4,9 @@ from AKDashboard.models import DashboardButton
@admin.register(DashboardButton) @admin.register(DashboardButton)
class DashboardButtonAdmin(admin.ModelAdmin): class DashboardButtonAdmin(admin.ModelAdmin):
"""
Admin interface for dashboard buttons
"""
list_display = ['text', 'url', 'event'] list_display = ['text', 'url', 'event']
list_filter = ['event'] list_filter = ['event']
search_fields = ['text', 'url'] search_fields = ['text', 'url']
......
...@@ -2,4 +2,7 @@ from django.apps import AppConfig ...@@ -2,4 +2,7 @@ from django.apps import AppConfig
class AkdashboardConfig(AppConfig): class AkdashboardConfig(AppConfig):
"""
App configuration for dashboard (default)
"""
name = 'AKDashboard' name = 'AKDashboard'
...@@ -8,7 +8,7 @@ msgid "" ...@@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-05-15 20:03+0200\n" "POT-Creation-Date: 2025-01-01 17:28+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
...@@ -17,61 +17,66 @@ msgstr "" ...@@ -17,61 +17,66 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: AKDashboard/models.py:10 #: AKDashboard/models.py:21
msgid "Dashboard Button" msgid "Dashboard Button"
msgstr "Dashboard-Button" msgstr "Dashboard-Button"
#: AKDashboard/models.py:11 #: AKDashboard/models.py:22
msgid "Dashboard Buttons" msgid "Dashboard Buttons"
msgstr "Dashboard-Buttons" msgstr "Dashboard-Buttons"
#: AKDashboard/models.py:21 #: AKDashboard/models.py:32
msgid "Text" msgid "Text"
msgstr "Text" msgstr "Text"
#: AKDashboard/models.py:22 #: AKDashboard/models.py:33
msgid "Text that will be shown on the button" msgid "Text that will be shown on the button"
msgstr "Text, der auf dem Button angezeigt wird" msgstr "Text, der auf dem Button angezeigt wird"
#: AKDashboard/models.py:23 #: AKDashboard/models.py:34
msgid "Link URL" msgid "Link URL"
msgstr "Link-URL" msgstr "Link-URL"
#: AKDashboard/models.py:23 #: AKDashboard/models.py:34
msgid "URL this button links to" msgid "URL this button links to"
msgstr "URL auf die der Button verweist" msgstr "URL auf die der Button verweist"
#: AKDashboard/models.py:24 #: AKDashboard/models.py:35
msgid "Icon" msgid "Icon"
msgstr "Symbol" msgstr "Symbol"
#: AKDashboard/models.py:26 #: AKDashboard/models.py:37
msgid "Button Style" msgid "Button Style"
msgstr "Stil des Buttons" msgstr "Stil des Buttons"
#: AKDashboard/models.py:26 #: AKDashboard/models.py:37
msgid "Style (Color) of this button (bootstrap class)" msgid "Style (Color) of this button (bootstrap class)"
msgstr "Stiel (Farbe) des Buttons (Bootstrap-Klasse)" msgstr "Stiel (Farbe) des Buttons (Bootstrap-Klasse)"
#: AKDashboard/models.py:28 #: AKDashboard/models.py:39
msgid "Event" msgid "Event"
msgstr "Veranstaltung" msgstr "Veranstaltung"
#: AKDashboard/models.py:28 #: AKDashboard/models.py:39
msgid "Event this button belongs to" msgid "Event this button belongs to"
msgstr "Veranstaltung, zu der dieser Button gehört" msgstr "Veranstaltung, zu der dieser Button gehört"
#: AKDashboard/templates/AKDashboard/dashboard.html:17 #: AKDashboard/templates/AKDashboard/dashboard.html:18
#: AKDashboard/templates/AKDashboard/dashboard_event.html:29 #: AKDashboard/templates/AKDashboard/dashboard_event.html:29
#: AKDashboard/templates/AKDashboard/dashboard_row_old_event.html:53
msgid "Write to organizers of this event for questions and comments" msgid "Write to organizers of this event for questions and comments"
msgstr "" msgstr ""
"Kontaktiere die Organisator*innen des Events bei Fragen oder Kommentaren" "Kontaktiere die Organisator*innen des Events bei Fragen oder Kommentaren"
#: AKDashboard/templates/AKDashboard/dashboard.html:24 #: AKDashboard/templates/AKDashboard/dashboard.html:24
msgid "Old events"
msgstr "Frühere Veranstaltungen"
#: AKDashboard/templates/AKDashboard/dashboard.html:34
msgid "Currently, there are no Events!" msgid "Currently, there are no Events!"
msgstr "Aktuell gibt es keine Events!" msgstr "Aktuell gibt es keine Events!"
#: AKDashboard/templates/AKDashboard/dashboard.html:27 #: AKDashboard/templates/AKDashboard/dashboard.html:37
msgid "Please contact an administrator if you want to use AKPlanning." msgid "Please contact an administrator if you want to use AKPlanning."
msgstr "" msgstr ""
"Bitte kontaktiere eine*n Administrator*in, falls du AKPlanning verwenden " "Bitte kontaktiere eine*n Administrator*in, falls du AKPlanning verwenden "
...@@ -81,46 +86,49 @@ msgstr "" ...@@ -81,46 +86,49 @@ msgstr ""
msgid "Recent" msgid "Recent"
msgstr "Kürzlich" msgstr "Kürzlich"
#: AKDashboard/templates/AKDashboard/dashboard_row.html:12 #: AKDashboard/templates/AKDashboard/dashboard_row.html:18
#: AKDashboard/templates/AKDashboard/dashboard_row_old_event.html:20
msgid "AK List" msgid "AK List"
msgstr "AK-Liste" msgstr "AK-Liste"
#: AKDashboard/templates/AKDashboard/dashboard_row.html:23 #: AKDashboard/templates/AKDashboard/dashboard_row.html:29
msgid "Current AKs" msgid "Current AKs"
msgstr "Aktuelle AKs" msgstr "Aktuelle AKs"
#: AKDashboard/templates/AKDashboard/dashboard_row.html:30 #: AKDashboard/templates/AKDashboard/dashboard_row.html:36
msgid "AK Wall" msgid "AK Wall"
msgstr "AK-Wall" msgstr "AK-Wall"
#: AKDashboard/templates/AKDashboard/dashboard_row.html:38 #: AKDashboard/templates/AKDashboard/dashboard_row.html:44
#: AKDashboard/templates/AKDashboard/dashboard_row_old_event.html:30
msgid "Schedule" msgid "Schedule"
msgstr "AK-Plan" msgstr "AK-Plan"
#: AKDashboard/templates/AKDashboard/dashboard_row.html:49 #: AKDashboard/templates/AKDashboard/dashboard_row.html:55
msgid "AK Submission" msgid "AK Submission"
msgstr "AK-Einreichung" msgstr "AK-Einreichung"
#: AKDashboard/templates/AKDashboard/dashboard_row.html:57 #: AKDashboard/templates/AKDashboard/dashboard_row.html:63
#: AKDashboard/templates/AKDashboard/dashboard_row_old_event.html:39
msgid "AK History" msgid "AK History"
msgstr "AK-Verlauf" msgstr "AK-Verlauf"
#: AKDashboard/views.py:42 #: AKDashboard/views.py:69
#, python-format #, python-format
msgid "New AK: %(ak)s." msgid "New AK: %(ak)s."
msgstr "Neuer AK: %(ak)s." msgstr "Neuer AK: %(ak)s."
#: AKDashboard/views.py:45 #: AKDashboard/views.py:72
#, python-format #, python-format
msgid "AK \"%(ak)s\" edited." msgid "AK \"%(ak)s\" edited."
msgstr "AK \"%(ak)s\" bearbeitet." msgstr "AK \"%(ak)s\" bearbeitet."
#: AKDashboard/views.py:48 #: AKDashboard/views.py:75
#, python-format #, python-format
msgid "AK \"%(ak)s\" deleted." msgid "AK \"%(ak)s\" deleted."
msgstr "AK \"%(ak)s\" gelöscht." msgstr "AK \"%(ak)s\" gelöscht."
#: AKDashboard/views.py:60 #: AKDashboard/views.py:90
#, python-format #, python-format
msgid "AK \"%(ak)s\" (re-)scheduled." msgid "AK \"%(ak)s\" (re-)scheduled."
msgstr "AK \"%(ak)s\" (um-)geplant." msgstr "AK \"%(ak)s\" (um-)geplant."
...@@ -6,6 +6,17 @@ from AKModel.models import Event ...@@ -6,6 +6,17 @@ from AKModel.models import Event
class DashboardButton(models.Model): class DashboardButton(models.Model):
"""
Model for a single dashboard button
Allows to specify
* a text (currently without possibility to translate),
* a color (based on predefined design colors)
* a url the button should point to (internal or external)
* an icon (from the collection of fontawesome)
Each button is associated with a single event and will be deleted when the event is deleted.
"""
class Meta: class Meta:
verbose_name = _("Dashboard Button") verbose_name = _("Dashboard Button")
verbose_name_plural = _("Dashboard Buttons") verbose_name_plural = _("Dashboard Buttons")
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
margin-bottom: 5em; margin-bottom: 5em;
} }
.dashboard-row-small {
margin-bottom: 3em;
}
.dashboard-row > .row { .dashboard-row > .row {
margin-left: 0; margin-left: 0;
padding-bottom: 1em; padding-bottom: 1em;
......
...@@ -9,16 +9,26 @@ ...@@ -9,16 +9,26 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% for event in events %} {% if total_event_count > 0 %}
<div class="dashboard-row"> {% for event in active_and_current_events %}
{% include "AKDashboard/dashboard_row.html" %} <div class="dashboard-row">
{% if event.contact_email %} {% include "AKDashboard/dashboard_row.html" %}
<p> {% if event.contact_email %}
<a href="mailto:{{ event.contact_email }}">{% fa6_icon "envelope" "fas" %} {% trans "Write to organizers of this event for questions and comments" %}</a> <p>
</p> <a href="mailto:{{ event.contact_email }}">{% fa6_icon "envelope" "fas" %} {% trans "Write to organizers of this event for questions and comments" %}</a>
{% endif %} </p>
</div> {% endif %}
{% empty %} </div>
{% endfor %}
{% if old_event_count > 0 %}
<h2 class="mb-3">{% trans "Old events" %}</h2>
{% for event in old_events %}
<div class="dashboard-row-small">
{% include "AKDashboard/dashboard_row_old_event.html" %}
</div>
{% endfor %}
{% endif %}
{% else %}
<div class="jumbotron"> <div class="jumbotron">
<h2 class="display-4"> <h2 class="display-4">
{% trans 'Currently, there are no Events!' %} {% trans 'Currently, there are no Events!' %}
...@@ -27,5 +37,5 @@ ...@@ -27,5 +37,5 @@
{% trans 'Please contact an administrator if you want to use AKPlanning.' %} {% trans 'Please contact an administrator if you want to use AKPlanning.' %}
</p> </p>
</div> </div>
{% endfor %} {% endif %}
{% endblock %} {% endblock %}
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
{% load fontawesome_6 %} {% load fontawesome_6 %}
<h2><a href="{% url 'dashboard:dashboard_event' slug=event.slug %}">{{ event.name }}</a></h2> <h2><a href="{% url 'dashboard:dashboard_event' slug=event.slug %}">{{ event.name }}</a></h2>
<h4 class="text-muted">
{% if event.place %}
<b>{{ event.place }} &middot;</b>
{% endif %}
{{ event | event_month_year }}
</h4>
<div class="mt-2"> <div class="mt-2">
{% if 'AKSubmission'|check_app_installed %} {% if 'AKSubmission'|check_app_installed %}
<a class="dashboard-box btn btn-primary" <a class="dashboard-box btn btn-primary"
......
{% load i18n %}
{% load tags_AKModel %}
{% load fontawesome_6 %}
<h3><a href="{% url 'dashboard:dashboard_event' slug=event.slug %}">{{ event.name }}</a>
<span class="text-muted">
&middot;
{% if event.place %}
{{ event.place }} &middot;
{% endif %}
{{ event | event_month_year }}
</span>
</h3>
<div class="mt-2">
{% if 'AKSubmission'|check_app_installed %}
<a class="btn btn-primary"
href="{% url 'submit:ak_list' event_slug=event.slug %}">
<div class="col-sm-12 col-md-3 col-lg-2 dashboard-button">
<span class="fa fa-list-ul"></span>
<span class='text'>{% trans 'AK List' %}</span>
</div>
</a>
{% endif %}
{% if 'AKPlan'|check_app_installed %}
{% if not event.plan_hidden or user.is_staff %}
<a class="btn btn-primary"
href="{% url 'plan:plan_overview' event_slug=event.slug %}">
<div class="col-sm-12 col-md-3 col-lg-2 dashboard-button">
<span class="fa fa-calendar-alt"></span>
<span class='text'>{% trans 'Schedule' %}</span>
</div>
</a>
{% endif %}
{% endif %}
<a class="btn btn-primary"
href="{% url 'dashboard:dashboard_event' slug=event.slug %}#history">
<div class="col-sm-12 col-md-3 col-lg-2 dashboard-button">
<span class="fa fa-history"></span>
<span class='text'>{% trans 'AK History' %}</span>
</div>
</a>
{% for button in event.dashboardbutton_set.all %}
<a class="btn btn-{{ button.get_color_display }}"
href="{{ button.url }}">
<div class="col-sm-12 col-md-3 col-lg-2 dashboard-button">
{% if button.icon %}<span class="fa">{{ button.icon.as_html }}</span>{% endif %}
<span class='text'>{{ button.text }}</span>
</div>
</a>
{% endfor %}
<a class="btn btn-info"
href=mailto:{{ event.contact_email }}"
title="{% trans 'Write to organizers of this event for questions and comments' %}">
{% fa6_icon "envelope" "fas" %}
</a>
</div>
import pytz import zoneinfo
from django.apps import apps from django.apps import apps
from django.test import TestCase, override_settings from django.test import override_settings, TestCase
from django.urls import reverse from django.urls import reverse
from django.utils.timezone import now from django.utils.timezone import now
from AKDashboard.models import DashboardButton from AKDashboard.models import DashboardButton
from AKModel.models import Event, AK, AKCategory from AKModel.models import AK, AKCategory, Event
from AKModel.tests import BasicViewTests from AKModel.tests import BasicViewTests
class DashboardTests(TestCase): class DashboardTests(TestCase):
"""
Specific Dashboard Tests
"""
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
"""
Initialize Test database
"""
super().setUpTestData() super().setUpTestData()
cls.event = Event.objects.create( cls.event = Event.objects.create(
name="Dashboard Test Event", name="Dashboard Test Event",
slug="dashboardtest", slug="dashboardtest",
timezone=pytz.utc, timezone=zoneinfo.ZoneInfo("Europe/Berlin"),
start=now(), start=now(),
end=now(), end=now(),
active=True, active=True,
plan_hidden=False, plan_hidden=False,
) )
cls.default_category = AKCategory.objects.create( cls.default_category = AKCategory.objects.create(
name="Test Category", name="Test Category",
event=cls.event, event=cls.event,
) )
def test_dashboard_view(self): def test_dashboard_view(self):
"""
Check that the main dashboard is reachable
(would also be covered by generic view testcase below)
"""
url = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug}) url = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug})
response = self.client.get(url) response = self.client.get(url)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_nonexistent_dashboard_view(self): def test_nonexistent_dashboard_view(self):
"""
Make sure there is no dashboard for an non-existing event
"""
url = reverse('dashboard:dashboard_event', kwargs={"slug": "nonexistent-event"}) url = reverse('dashboard:dashboard_event', kwargs={"slug": "nonexistent-event"})
response = self.client.get(url) response = self.client.get(url)
self.assertEqual(response.status_code, 404) self.assertEqual(response.status_code, 404)
@override_settings(DASHBOARD_SHOW_RECENT=True) @override_settings(DASHBOARD_SHOW_RECENT=True)
def test_history(self): def test_history(self):
"""
Test displaying of history
For the sake of that test, the setting to show recent events in dashboard is enforced to be true
regardless of the default configuration currently in place
"""
url = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug}) url = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug})
# History should be empty # History should be empty
response = self.client.get(url) response = self.client.get(url)
self.assertQuerysetEqual(response.context["recent_changes"], []) self.assertQuerySetEqual(response.context["recent_changes"], [])
AK.objects.create( AK.objects.create(
name="Test AK", name="Test AK",
category=self.default_category, category=self.default_category,
event=self.event, event=self.event,
) )
# History should now contain one AK (Test AK) # History should now contain one AK (Test AK)
...@@ -57,6 +78,11 @@ class DashboardTests(TestCase): ...@@ -57,6 +78,11 @@ class DashboardTests(TestCase):
self.assertEqual(response.context["recent_changes"][0]['text'], "New AK: Test AK.") self.assertEqual(response.context["recent_changes"][0]['text'], "New AK: Test AK.")
def test_public(self): def test_public(self):
"""
Test handling of public and private events
(only public events should be part of the standard dashboard,
but there should be an individual dashboard for both public and private events)
"""
url_dashboard_index = reverse('dashboard:dashboard') url_dashboard_index = reverse('dashboard:dashboard')
url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug}) url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug})
...@@ -66,7 +92,8 @@ class DashboardTests(TestCase): ...@@ -66,7 +92,8 @@ class DashboardTests(TestCase):
self.event.save() self.event.save()
response = self.client.get(url_dashboard_index) response = self.client.get(url_dashboard_index)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertFalse(self.event in response.context["events"]) self.assertFalse(self.event in response.context["active_and_current_events"])
self.assertFalse(self.event in response.context["old_events"])
response = self.client.get(url_event_dashboard) response = self.client.get(url_event_dashboard)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.context["event"], self.event) self.assertEqual(response.context["event"], self.event)
...@@ -76,9 +103,12 @@ class DashboardTests(TestCase): ...@@ -76,9 +103,12 @@ class DashboardTests(TestCase):
self.event.save() self.event.save()
response = self.client.get(url_dashboard_index) response = self.client.get(url_dashboard_index)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue(self.event in response.context["events"]) self.assertTrue(self.event in response.context["active_and_current_events"])
def test_active(self): def test_active(self):
"""
Test existence of buttons with regard to activity status of the given event
"""
url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug}) url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug})
if apps.is_installed('AKSubmission'): if apps.is_installed('AKSubmission'):
...@@ -95,6 +125,9 @@ class DashboardTests(TestCase): ...@@ -95,6 +125,9 @@ class DashboardTests(TestCase):
self.assertContains(response, "AK Submission") self.assertContains(response, "AK Submission")
def test_plan_hidden(self): def test_plan_hidden(self):
"""
Test visibility of plan buttons with regard to plan visibility status for a given event
"""
url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug}) url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug})
if apps.is_installed('AKPlan'): if apps.is_installed('AKPlan'):
...@@ -114,14 +147,17 @@ class DashboardTests(TestCase): ...@@ -114,14 +147,17 @@ class DashboardTests(TestCase):
self.assertContains(response, "AK Wall") self.assertContains(response, "AK Wall")
def test_dashboard_buttons(self): def test_dashboard_buttons(self):
"""
Make sure manually added buttons are displayed correctly
"""
url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug}) url_event_dashboard = reverse('dashboard:dashboard_event', kwargs={"slug": self.event.slug})
response = self.client.get(url_event_dashboard) response = self.client.get(url_event_dashboard)
self.assertNotContains(response, "Dashboard Button Test") self.assertNotContains(response, "Dashboard Button Test")
DashboardButton.objects.create( DashboardButton.objects.create(
text="Dashboard Button Test", text="Dashboard Button Test",
event=self.event event=self.event
) )
response = self.client.get(url_event_dashboard) response = self.client.get(url_event_dashboard)
...@@ -129,6 +165,9 @@ class DashboardTests(TestCase): ...@@ -129,6 +165,9 @@ class DashboardTests(TestCase):
class DashboardViewTests(BasicViewTests, TestCase): class DashboardViewTests(BasicViewTests, TestCase):
"""
Generic view tests, based on :class:`AKModel.BasicViewTests` as specified in this class in VIEWS
"""
fixtures = ['model.json', 'dashboard.json'] fixtures = ['model.json', 'dashboard.json']
APP_NAME = 'dashboard' APP_NAME = 'dashboard'
......
from django.apps import apps from django.apps import apps
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import TemplateView, DetailView from django.views.generic import TemplateView, DetailView
...@@ -10,6 +9,11 @@ from AKPlanning import settings ...@@ -10,6 +9,11 @@ from AKPlanning import settings
class DashboardView(TemplateView): class DashboardView(TemplateView):
"""
Index view of dashboard and therefore the main entry point for AKPlanning
Displays information and buttons for all public events
"""
template_name = 'AKDashboard/dashboard.html' template_name = 'AKDashboard/dashboard.html'
@method_decorator(ensure_csrf_cookie) @method_decorator(ensure_csrf_cookie)
...@@ -18,11 +22,30 @@ class DashboardView(TemplateView): ...@@ -18,11 +22,30 @@ class DashboardView(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['events'] = Event.objects.filter(public=True).prefetch_related('dashboardbutton_set') # Load events and split between active and current/featured events and those that should show smaller below
context["active_and_current_events"] = []
context["old_events"] = []
events = Event.objects.filter(public=True).order_by("-active", "-pk").prefetch_related('dashboardbutton_set')
for event in events:
if event.active or len(context["active_and_current_events"]) < settings.DASHBOARD_MAX_FEATURED_EVENTS:
context["active_and_current_events"].append(event)
else:
context["old_events"].append(event)
context["active_event_count"] = len(context["active_and_current_events"])
context["old_event_count"] = len(context["old_events"])
context["total_event_count"] = context["active_event_count"] + context["old_event_count"]
return context return context
class DashboardEventView(DetailView): class DashboardEventView(DetailView):
"""
Dashboard view for a single event
In addition to the basic information and the buttons,
an overview over recent events (new and changed AKs, moved AKSlots) for the given event is shown.
The event dashboard also exists for non-public events (one only needs to know the URL/slug of the event).
"""
template_name = 'AKDashboard/dashboard_event.html' template_name = 'AKDashboard/dashboard_event.html'
context_object_name = 'event' context_object_name = 'event'
model = Event model = Event
...@@ -32,11 +55,16 @@ class DashboardEventView(DetailView): ...@@ -32,11 +55,16 @@ class DashboardEventView(DetailView):
# Show feed of recent changes (if activated) # Show feed of recent changes (if activated)
if settings.DASHBOARD_SHOW_RECENT: if settings.DASHBOARD_SHOW_RECENT:
# Create a list of chronically sorted events (both AK and plan changes):
recent_changes = [] recent_changes = []
# Newest AKs # Newest AKs (if AKSubmission is used)
if apps.is_installed("AKSubmission"): if apps.is_installed("AKSubmission"):
submission_changes = AK.history.filter(event=context['event'])[:int(settings.DASHBOARD_RECENT_MAX)] # Get the latest x changes (if there are that many),
# where x corresponds to the entry threshold configured in the settings
# (such that the list will be completely filled even if there are no (newer) plan changes)
submission_changes = AK.history.filter(event=context['event'])[:int(settings.DASHBOARD_RECENT_MAX)] # pylint: disable=no-member, line-too-long
# Create textual representation including icons
for s in submission_changes: for s in submission_changes:
if s.history_type == '+': if s.history_type == '+':
text = _('New AK: %(ak)s.') % {'ak': s.name} text = _('New AK: %(ak)s.') % {'ak': s.name}
...@@ -48,18 +76,21 @@ class DashboardEventView(DetailView): ...@@ -48,18 +76,21 @@ class DashboardEventView(DetailView):
text = _('AK "%(ak)s" deleted.') % {'ak': s.name} text = _('AK "%(ak)s" deleted.') % {'ak': s.name}
icon = ('times', 'fas') icon = ('times', 'fas')
recent_changes.append({'icon': icon, 'text': text, 'link': s.instance.detail_url, 'timestamp': s.history_date}) # Store representation in change list (still unsorted)
recent_changes.append(
# Changes in plan {'icon': icon, 'text': text, 'link': s.instance.detail_url, 'timestamp': s.history_date}
if apps.is_installed("AKPlan"): )
if not context['event'].plan_hidden:
last_changed_slots = AKSlot.objects.select_related('ak').filter(event=context['event'], start__isnull=False).order_by('-updated')[ # Changes in plan (if AKPlan is used and plan is publicly visible)
:int(settings.DASHBOARD_RECENT_MAX)] if apps.is_installed("AKPlan") and not context['event'].plan_hidden:
for changed_slot in last_changed_slots: # Get the latest plan changes (again using a threshold, see above)
recent_changes.append({'icon': ('clock', 'far'), last_changed_slots = AKSlot.objects.select_related('ak').filter(event=context['event'], start__isnull=False).order_by('-updated')[:int(settings.DASHBOARD_RECENT_MAX)] #pylint: disable=line-too-long
'text': _('AK "%(ak)s" (re-)scheduled.') % {'ak': changed_slot.ak.name}, for changed_slot in last_changed_slots:
'link': changed_slot.ak.detail_url, # Create textual representation including icons and links and store in list (still unsorted)
'timestamp': changed_slot.updated}) recent_changes.append({'icon': ('clock', 'far'),
'text': _('AK "%(ak)s" (re-)scheduled.') % {'ak': changed_slot.ak.name},
'link': changed_slot.ak.detail_url,
'timestamp': changed_slot.updated})
# Sort by change date... # Sort by change date...
recent_changes.sort(key=lambda x: x['timestamp'], reverse=True) recent_changes.sort(key=lambda x: x['timestamp'], reverse=True)
......
This diff is collapsed.
...@@ -3,8 +3,15 @@ from django.contrib.admin.apps import AdminConfig ...@@ -3,8 +3,15 @@ from django.contrib.admin.apps import AdminConfig
class AkmodelConfig(AppConfig): class AkmodelConfig(AppConfig):
"""
App configuration (default, only specifies name of the app)
"""
name = 'AKModel' name = 'AKModel'
class AKAdminConfig(AdminConfig): class AKAdminConfig(AdminConfig):
"""
App configuration for admin
Loading a custom version here allows to add additional contex and further adapt the behavior of the admin interface
"""
default_site = 'AKModel.site.AKAdminSite' default_site = 'AKModel.site.AKAdminSite'
# This part of the code was adapted from pretalx (https://github.com/pretalx/pretalx) # This part of the code was adapted from pretalx (https://github.com/pretalx/pretalx)
# Copyright 2017-2019, Tobias Kunze # Copyright 2017-2019, Tobias Kunze
# Original Copyrights licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 # Original Copyrights licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
# Changes are marked in the code # Documentation was mainly added by us, other changes are marked in the code
import datetime import datetime
import json import json
...@@ -17,6 +17,10 @@ from AKModel.models import Event ...@@ -17,6 +17,10 @@ from AKModel.models import Event
class AvailabilitiesFormMixin(forms.Form): class AvailabilitiesFormMixin(forms.Form):
"""
Mixin for forms to add availabilities functionality to it
Will handle the rendering and population of an availabilities field
"""
availabilities = forms.CharField( availabilities = forms.CharField(
label=_('Availability'), label=_('Availability'),
help_text=_( help_text=_(
...@@ -28,6 +32,14 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -28,6 +32,14 @@ class AvailabilitiesFormMixin(forms.Form):
) )
def _serialize(self, event, instance): def _serialize(self, event, instance):
"""
Serialize relevant availabilities into a JSON format to populate the text field in the form
:param event: event the availabilities belong to (relevant for start and end times)
:param instance: the entity availabilities in this form should belong to (e.g., an AK, or a Room)
:return: JSON serializiation of the relevant availabilities
:rtype: str
"""
if instance: if instance:
availabilities = AvailabilitySerializer( availabilities = AvailabilitySerializer(
instance.availabilities.all(), many=True instance.availabilities.all(), many=True
...@@ -48,20 +60,28 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -48,20 +60,28 @@ class AvailabilitiesFormMixin(forms.Form):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# Load event information and populate availabilities text field
self.event = self.initial.get('event') self.event = self.initial.get('event')
if isinstance(self.event, int): if isinstance(self.event, int):
self.event = Event.objects.get(pk=self.event) self.event = Event.objects.get(pk=self.event)
initial = kwargs.pop('initial', dict()) initial = kwargs.pop('initial', {})
initial['availabilities'] = self._serialize(self.event, kwargs['instance']) initial['availabilities'] = self._serialize(self.event, kwargs['instance'])
if not isinstance(self, forms.BaseModelForm): if not isinstance(self, forms.BaseModelForm):
kwargs.pop('instance') kwargs.pop('instance')
kwargs['initial'] = initial kwargs['initial'] = initial
def _parse_availabilities_json(self, jsonavailabilities): def _parse_availabilities_json(self, jsonavailabilities):
"""
Turn raw JSON availabilities into a list of model instances
:param jsonavailabilities: raw json input
:return: a list of availability objects corresponding to the raw input
:rtype: List[Availability]
"""
try: try:
rawdata = json.loads(jsonavailabilities) rawdata = json.loads(jsonavailabilities)
except ValueError: except ValueError as exc:
raise forms.ValidationError("Submitted availabilities are not valid json.") raise forms.ValidationError("Submitted availabilities are not valid json.") from exc
if not isinstance(rawdata, dict): if not isinstance(rawdata, dict):
raise forms.ValidationError( raise forms.ValidationError(
"Submitted json does not comply with expected format, should be object." "Submitted json does not comply with expected format, should be object."
...@@ -74,17 +94,32 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -74,17 +94,32 @@ class AvailabilitiesFormMixin(forms.Form):
return availabilities return availabilities
def _parse_datetime(self, strdate): def _parse_datetime(self, strdate):
"""
Parse input date string
This will try to correct timezone information if needed
:param strdate: string representing a timestamp
:return: a timestamp object
"""
tz = self.event.timezone # adapt to our event model tz = self.event.timezone # adapt to our event model
obj = parse_datetime(strdate) obj = parse_datetime(strdate)
if not obj: if not obj:
raise TypeError raise TypeError
if obj.tzinfo is None: if obj.tzinfo is None:
obj = obj.astimezone(tz) # Adapt to new python timezone interface
obj = obj.replace(tzinfo=tz)
return obj return obj
def _validate_availability(self, rawavail): def _validate_availability(self, rawavail):
"""
Validate a raw availability instance input by making sure the relevant fields are present and can be parsed
The cleaned up values that are produced to test the validity of the input are stored in-place in the input
object for later usage in cleaning/parsing to availability objects
:param rawavail: object to validate/clean
"""
message = _("The submitted availability does not comply with the required format.") message = _("The submitted availability does not comply with the required format.")
if not isinstance(rawavail, dict): if not isinstance(rawavail, dict):
raise forms.ValidationError(message) raise forms.ValidationError(message)
...@@ -96,12 +131,11 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -96,12 +131,11 @@ class AvailabilitiesFormMixin(forms.Form):
try: try:
rawavail['start'] = self._parse_datetime(rawavail['start']) rawavail['start'] = self._parse_datetime(rawavail['start'])
rawavail['end'] = self._parse_datetime(rawavail['end']) rawavail['end'] = self._parse_datetime(rawavail['end'])
except (TypeError, ValueError): # Adapt: Better error handling
except (TypeError, ValueError) as exc:
raise forms.ValidationError( raise forms.ValidationError(
_("The submitted availability contains an invalid date.") _("The submitted availability contains an invalid date.")
) ) from exc
tz = self.event.timezone # adapt to our event model
timeframe_start = self.event.start # adapt to our event model timeframe_start = self.event.start # adapt to our event model
if rawavail['start'] < timeframe_start: if rawavail['start'] < timeframe_start:
...@@ -115,6 +149,10 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -115,6 +149,10 @@ class AvailabilitiesFormMixin(forms.Form):
rawavail['end'] = timeframe_end rawavail['end'] = timeframe_end
def clean_availabilities(self): def clean_availabilities(self):
"""
Turn raw availabilities into real availability objects
:return:
"""
data = self.cleaned_data.get('availabilities') data = self.cleaned_data.get('availabilities')
required = ( required = (
'availabilities' in self.fields and self.fields['availabilities'].required 'availabilities' in self.fields and self.fields['availabilities'].required
...@@ -135,7 +173,8 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -135,7 +173,8 @@ class AvailabilitiesFormMixin(forms.Form):
return availabilities return availabilities
def _set_foreignkeys(self, instance, availabilities): def _set_foreignkeys(self, instance, availabilities):
"""Set the reference to `instance` in each given availability. """
Set the reference to `instance` in each given availability.
For example, set the availabilitiy.room_id to instance.id, in For example, set the availabilitiy.room_id to instance.id, in
case instance of type Room. case instance of type Room.
""" """
...@@ -145,10 +184,20 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -145,10 +184,20 @@ class AvailabilitiesFormMixin(forms.Form):
setattr(avail, reference_name, instance.id) setattr(avail, reference_name, instance.id)
def _replace_availabilities(self, instance, availabilities: [Availability]): def _replace_availabilities(self, instance, availabilities: [Availability]):
"""
Replace the existing list of availabilities belonging to an entity with a new, updated one
This will trigger a post_save signal for usage in constraint violation checking
:param instance: entity the availabilities belong to
:param availabilities: list of new availabilities
"""
with transaction.atomic(): with transaction.atomic():
# TODO: do not recreate objects unnecessarily, give the client the IDs, so we can track modifications and leave unchanged objects alone # TODO: do not recreate objects unnecessarily, give the client the IDs, so we can track modifications and
# leave unchanged objects alone
instance.availabilities.all().delete() instance.availabilities.all().delete()
Availability.objects.bulk_create(availabilities) Availability.objects.bulk_create(availabilities)
# Adaption:
# Trigger post save signal manually to make sure constraints are updated accordingly # Trigger post save signal manually to make sure constraints are updated accordingly
# Doing this one time is sufficient, since this will nevertheless update all availability constraint # Doing this one time is sufficient, since this will nevertheless update all availability constraint
# violations of the corresponding AK # violations of the corresponding AK
...@@ -156,6 +205,9 @@ class AvailabilitiesFormMixin(forms.Form): ...@@ -156,6 +205,9 @@ class AvailabilitiesFormMixin(forms.Form):
post_save.send(Availability, instance=availabilities[0], created=True) post_save.send(Availability, instance=availabilities[0], created=True)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
"""
Override the saving method of the (model) form
"""
instance = super().save(*args, **kwargs) instance = super().save(*args, **kwargs)
availabilities = self.cleaned_data.get('availabilities') availabilities = self.cleaned_data.get('availabilities')
......
...@@ -23,6 +23,9 @@ zero_time = datetime.time(0, 0) ...@@ -23,6 +23,9 @@ zero_time = datetime.time(0, 0)
# add meta class # add meta class
# enable availabilities for AKs and AKCategories # enable availabilities for AKs and AKCategories
# add verbose names and help texts to model attributes # add verbose names and help texts to model attributes
# adapt or extemd documentation
class Availability(models.Model): class Availability(models.Model):
"""The Availability class models when people or rooms are available for. """The Availability class models when people or rooms are available for.
...@@ -31,6 +34,8 @@ class Availability(models.Model): ...@@ -31,6 +34,8 @@ class Availability(models.Model):
span multiple days, but due to our choice of input widget, it will span multiple days, but due to our choice of input widget, it will
usually only span a single day at most. usually only span a single day at most.
""" """
# pylint: disable=broad-exception-raised
event = models.ForeignKey( event = models.ForeignKey(
to=Event, to=Event,
related_name='availabilities', related_name='availabilities',
...@@ -96,10 +101,10 @@ class Availability(models.Model): ...@@ -96,10 +101,10 @@ class Availability(models.Model):
are the same. are the same.
""" """
return all( return all(
[ (
getattr(self, attribute, None) == getattr(other, attribute, None) getattr(self, attribute, None) == getattr(other, attribute, None)
for attribute in ['event', 'person', 'room', 'ak', 'ak_category', 'start', 'end'] for attribute in ['event', 'person', 'room', 'ak', 'ak_category', 'start', 'end']
] )
) )
@cached_property @cached_property
...@@ -233,10 +238,28 @@ class Availability(models.Model): ...@@ -233,10 +238,28 @@ class Availability(models.Model):
@property @property
def simplified(self): def simplified(self):
return f'{self.start.astimezone(self.event.timezone).strftime("%a %H:%M")}-{self.end.astimezone(self.event.timezone).strftime("%a %H:%M")}' """
Get a simplified (only Weekday, hour and minute) string representation of an availability
:return: simplified string version
:rtype: str
"""
return (f'{self.start.astimezone(self.event.timezone).strftime("%a %H:%M")}-'
f'{self.end.astimezone(self.event.timezone).strftime("%a %H:%M")}')
@classmethod @classmethod
def with_event_length(cls, event, person=None, room=None, ak=None, ak_category=None): def with_event_length(cls, event, person=None, room=None, ak=None, ak_category=None):
"""
Create an availability covering exactly the time between event start and event end.
Can e.g., be used to create default availabilities.
:param event: relevant event
:param person: person, if availability should be connected to a person
:param room: room, if availability should be connected to a room
:param ak: ak, if availability should be connected to a ak
:param ak_category: ak_category, if availability should be connected to a ak_category
:return: availability associated to the entity oder entities selected
:rtype: Availability
"""
timeframe_start = event.start # adapt to our event model timeframe_start = event.start # adapt to our event model
# add 1 day, not 24 hours, https://stackoverflow.com/a/25427822/2486196 # add 1 day, not 24 hours, https://stackoverflow.com/a/25427822/2486196
timeframe_end = event.end # adapt to our event model timeframe_end = event.end # adapt to our event model
......
# This part of the code was adapted from pretalx (https://github.com/pretalx/pretalx) # This part of the code was adapted from pretalx (https://github.com/pretalx/pretalx)
# Copyright 2017-2019, Tobias Kunze # Copyright 2017-2019, Tobias Kunze
# Original Copyrights licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 # Original Copyrights licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0
# Changes are marked in the code # Documentation was mainly added by us, other changes are marked in the code
from django.utils import timezone from django.utils import timezone
from rest_framework.fields import SerializerMethodField from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
...@@ -10,19 +10,35 @@ from AKModel.availability.models import Availability ...@@ -10,19 +10,35 @@ from AKModel.availability.models import Availability
class AvailabilitySerializer(ModelSerializer): class AvailabilitySerializer(ModelSerializer):
"""
REST Framework Serializer for Availability
"""
allDay = SerializerMethodField() allDay = SerializerMethodField()
start = SerializerMethodField() start = SerializerMethodField()
end = SerializerMethodField() end = SerializerMethodField()
def get_allDay(self, obj): def get_allDay(self, obj): # pylint: disable=invalid-name
"""
Bridge between naming conventions of python and fullcalendar by providing the all_day field as allDay, too
"""
return obj.all_day return obj.all_day
# Use already localized strings in serialized field
# (default would be UTC, but that would require heavy timezone calculation on client side)
def get_start(self, obj): def get_start(self, obj):
"""
Get start timestamp
Use already localized strings in serialized field
(default would be UTC, but that would require heavy timezone calculation on client side)
"""
return timezone.localtime(obj.start, obj.event.timezone).strftime("%Y-%m-%dT%H:%M:%S") return timezone.localtime(obj.start, obj.event.timezone).strftime("%Y-%m-%dT%H:%M:%S")
def get_end(self, obj): def get_end(self, obj):
"""
Get end timestamp
Use already localized strings in serialized field
(default would be UTC, but that would require heavy timezone calculation on client side)
"""
return timezone.localtime(obj.end, obj.event.timezone).strftime("%Y-%m-%dT%H:%M:%S") return timezone.localtime(obj.end, obj.event.timezone).strftime("%Y-%m-%dT%H:%M:%S")
class Meta: class Meta:
......
# environment.py """
Environment definitions
Needed for tex compilation
"""
import re import re
from django_tex.environment import environment from django_tex.environment import environment
# Used to filter all very special UTF-8 chars that are probably not contained in the LaTeX fonts # Used to filter all very special UTF-8 chars that are probably not contained in the LaTeX fonts
# and would hence cause compilation errors # and would hence cause compilation errors
utf8_replace_pattern = re.compile(u'[^\u0000-\u206F]', re.UNICODE) utf8_replace_pattern = re.compile('[^\u0000-\u206F]', re.UNICODE)
def latex_escape_utf8(value): def latex_escape_utf8(value):
...@@ -17,12 +20,14 @@ def latex_escape_utf8(value): ...@@ -17,12 +20,14 @@ def latex_escape_utf8(value):
:return: escaped string :return: escaped string
:rtype: str :rtype: str
""" """
return utf8_replace_pattern.sub('', value).replace('&', '\&').replace('_', '\_').replace('#', '\#').replace('$', return (utf8_replace_pattern.sub('', value).replace('&', r'\&').replace('_', r'\_').replace('#', r'\#').
'\$').replace( replace('$', r'\$').replace('%', r'\%').replace('{', r'\{').replace('}', r'\}'))
'%', '\%').replace('{', '\{').replace('}', '\}')
def improved_tex_environment(**options): def improved_tex_environment(**options):
"""
Encapsulate our improved latex environment for usage
"""
env = environment(**options) env = environment(**options)
env.filters.update({ env.filters.update({
'latex_escape_utf8': latex_escape_utf8, 'latex_escape_utf8': latex_escape_utf8,
......
...@@ -193,6 +193,14 @@ ...@@ -193,6 +193,14 @@
"event": 2 "event": 2
} }
}, },
{
"model": "AKModel.aktype",
"pk": 1,
"fields": {
"name": "Input",
"event": 2
}
},
{ {
"model": "AKModel.historicalak", "model": "AKModel.historicalak",
"pk": 1, "pk": 1,
...@@ -206,7 +214,6 @@ ...@@ -206,7 +214,6 @@
"reso": false, "reso": false,
"present": true, "present": true,
"notes": "", "notes": "",
"interest": -1,
"category": 4, "category": 4,
"track": null, "track": null,
"event": 2, "event": 2,
...@@ -229,7 +236,6 @@ ...@@ -229,7 +236,6 @@
"reso": false, "reso": false,
"present": true, "present": true,
"notes": "", "notes": "",
"interest": -1,
"category": 4, "category": 4,
"track": null, "track": null,
"event": 2, "event": 2,
...@@ -252,7 +258,6 @@ ...@@ -252,7 +258,6 @@
"reso": false, "reso": false,
"present": null, "present": null,
"notes": "", "notes": "",
"interest": -1,
"category": 5, "category": 5,
"track": null, "track": null,
"event": 2, "event": 2,
...@@ -275,7 +280,6 @@ ...@@ -275,7 +280,6 @@
"reso": false, "reso": false,
"present": null, "present": null,
"notes": "", "notes": "",
"interest": -1,
"category": 5, "category": 5,
"track": null, "track": null,
"event": 2, "event": 2,
...@@ -298,7 +302,6 @@ ...@@ -298,7 +302,6 @@
"reso": false, "reso": false,
"present": null, "present": null,
"notes": "We need to find a volunteer first...", "notes": "We need to find a volunteer first...",
"interest": -1,
"category": 3, "category": 3,
"track": null, "track": null,
"event": 2, "event": 2,
...@@ -321,7 +324,6 @@ ...@@ -321,7 +324,6 @@
"reso": false, "reso": false,
"present": null, "present": null,
"notes": "We need to find a volunteer first...", "notes": "We need to find a volunteer first...",
"interest": -1,
"category": 3, "category": 3,
"track": null, "track": null,
"event": 2, "event": 2,
...@@ -344,7 +346,6 @@ ...@@ -344,7 +346,6 @@
"reso": false, "reso": false,
"present": null, "present": null,
"notes": "", "notes": "",
"interest": -1,
"category": 5, "category": 5,
"track": 1, "track": 1,
"event": 2, "event": 2,
......
"""
Central and admin forms
"""
import csv import csv
import io import io
from bootstrap_datepicker_plus.widgets import DateTimePickerInput
from django import forms from django import forms
from django.forms.utils import ErrorList from django.forms.utils import ErrorList
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from AKModel.availability.forms import AvailabilitiesFormMixin from AKModel.availability.forms import AvailabilitiesFormMixin
from AKModel.models import Event, AKCategory, AKRequirement, Room from AKModel.models import Event, AKCategory, AKRequirement, Room, AKType
class DateTimeInput(forms.DateInput):
"""
Simple widget for datetime input fields using the HTML5 datetime-local input type
"""
input_type = 'datetime-local'
class NewEventWizardStartForm(forms.ModelForm): class NewEventWizardStartForm(forms.ModelForm):
"""
Initial view of new event wizard
This form is a model form for Event, but only with a subset of the required fields.
It is therefore not possible to really create an event using this form, but only to enter
information, in particular the timezone, that is needed to correctly handle/parse the user
inputs for further required fields like start and end of the event.
The form will be used for this partial input, the input of the remaining required fields
will then be handled by :class:`NewEventWizardSettingsForm` (see below).
"""
class Meta: class Meta:
model = Event model = Event
fields = ['name', 'slug', 'timezone', 'plan_hidden'] fields = ['name', 'slug', 'timezone', 'plan_hidden']
...@@ -18,26 +39,40 @@ class NewEventWizardStartForm(forms.ModelForm): ...@@ -18,26 +39,40 @@ class NewEventWizardStartForm(forms.ModelForm):
'plan_hidden': forms.HiddenInput(), 'plan_hidden': forms.HiddenInput(),
} }
# Special hidden field for wizard state handling
is_init = forms.BooleanField(initial=True, widget=forms.HiddenInput) is_init = forms.BooleanField(initial=True, widget=forms.HiddenInput)
class NewEventWizardSettingsForm(forms.ModelForm): class NewEventWizardSettingsForm(forms.ModelForm):
"""
Form for second view of the event creation wizard.
Will handle the input of the remaining required as well as some optional fields.
See also :class:`NewEventWizardStartForm`.
"""
class Meta: class Meta:
model = Event model = Event
exclude = [] fields = "__all__"
exclude = ['plan_published_at']
widgets = { widgets = {
'name': forms.HiddenInput(), 'name': forms.HiddenInput(),
'slug': forms.HiddenInput(), 'slug': forms.HiddenInput(),
'timezone': forms.HiddenInput(), 'timezone': forms.HiddenInput(),
'active': forms.HiddenInput(), 'active': forms.HiddenInput(),
'start': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}), 'start': DateTimeInput(),
'end': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}), 'end': DateTimeInput(),
'reso_deadline': DateTimePickerInput(options={"format": "YYYY-MM-DD HH:mm"}), 'interest_start': DateTimeInput(),
'interest_end': DateTimeInput(),
'reso_deadline': DateTimeInput(),
'plan_hidden': forms.HiddenInput(), 'plan_hidden': forms.HiddenInput(),
} }
class NewEventWizardPrepareImportForm(forms.Form): class NewEventWizardPrepareImportForm(forms.Form):
"""
Wizard form for choosing an event to import/copy elements (requirements, categories, etc) from.
Is used to restrict the list of elements to choose from in the next step (see :class:`NewEventWizardImportForm`).
"""
import_event = forms.ModelChoiceField( import_event = forms.ModelChoiceField(
queryset=Event.objects.all(), queryset=Event.objects.all(),
label=_("Copy ak requirements and ak categories of existing event"), label=_("Copy ak requirements and ak categories of existing event"),
...@@ -46,6 +81,12 @@ class NewEventWizardPrepareImportForm(forms.Form): ...@@ -46,6 +81,12 @@ class NewEventWizardPrepareImportForm(forms.Form):
class NewEventWizardImportForm(forms.Form): class NewEventWizardImportForm(forms.Form):
"""
Wizard form for excaclty choosing which elemments to copy/import for the newly created event.
Possible elements are categories, requirements, and dashboard buttons if AKDashboard is active.
The lists are restricted to elements from the event selected in the previous step
(see :class:`NewEventWizardPrepareImportForm`).
"""
import_categories = forms.ModelMultipleChoiceField( import_categories = forms.ModelMultipleChoiceField(
queryset=AKCategory.objects.all(), queryset=AKCategory.objects.all(),
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
...@@ -60,6 +101,14 @@ class NewEventWizardImportForm(forms.Form): ...@@ -60,6 +101,14 @@ class NewEventWizardImportForm(forms.Form):
required=False, required=False,
) )
import_types = forms.ModelMultipleChoiceField(
queryset=AKType.objects.all(),
widget=forms.CheckboxSelectMultiple,
label=_("Copy types"),
required=False,
)
# pylint: disable=too-many-arguments
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList, def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=ErrorList,
label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None,
renderer=None): renderer=None):
...@@ -69,11 +118,15 @@ class NewEventWizardImportForm(forms.Form): ...@@ -69,11 +118,15 @@ class NewEventWizardImportForm(forms.Form):
event=self.initial["import_event"]) event=self.initial["import_event"])
self.fields["import_requirements"].queryset = self.fields["import_requirements"].queryset.filter( self.fields["import_requirements"].queryset = self.fields["import_requirements"].queryset.filter(
event=self.initial["import_event"]) event=self.initial["import_event"])
self.fields["import_types"].queryset = self.fields["import_types"].queryset.filter(
event=self.initial["import_event"])
# pylint: disable=import-outside-toplevel
# Local imports used to prevent cyclic imports and to only import when AKDashboard is available
from django.apps import apps from django.apps import apps
if apps.is_installed("AKDashboard"): if apps.is_installed("AKDashboard"):
# If AKDashboard is active, allow to copy dashboard buttons, too
from AKDashboard.models import DashboardButton from AKDashboard.models import DashboardButton
self.fields["import_buttons"] = forms.ModelMultipleChoiceField( self.fields["import_buttons"] = forms.ModelMultipleChoiceField(
queryset=DashboardButton.objects.filter(event=self.initial["import_event"]), queryset=DashboardButton.objects.filter(event=self.initial["import_event"]),
widget=forms.CheckboxSelectMultiple, widget=forms.CheckboxSelectMultiple,
...@@ -83,20 +136,37 @@ class NewEventWizardImportForm(forms.Form): ...@@ -83,20 +136,37 @@ class NewEventWizardImportForm(forms.Form):
class NewEventWizardActivateForm(forms.ModelForm): class NewEventWizardActivateForm(forms.ModelForm):
"""
Wizard form to activate the newly created event
"""
class Meta: class Meta:
fields = ["active"] fields = ["active"]
model = Event model = Event
class AdminIntermediateForm(forms.Form): class AdminIntermediateForm(forms.Form):
pass """
Base form for admin intermediate views (forms used there should inherit from this,
by default, the form is empty since it is only needed for the confirmation button)
"""
class AdminIntermediateActionForm(AdminIntermediateForm): class AdminIntermediateActionForm(AdminIntermediateForm):
"""
Form for Admin Action Confirmation views -- has a pks field needed to handle the serialization/deserialization of
the IDs of the entities the user selected for the admin action to be performed on
"""
pks = forms.CharField(widget=forms.HiddenInput) pks = forms.CharField(widget=forms.HiddenInput)
class SlideExportForm(AdminIntermediateForm): class SlideExportForm(AdminIntermediateForm):
"""
Form to control the slides generated from the AK list of an event
The user can select how many upcoming AKs are displayed at the footer to inform people that it is their turn soon,
whether the AK list should be restricted to those AKs that where marked for presentation, and whether ther should
be a symbol and empty space to take notes on for wishes
"""
num_next = forms.IntegerField( num_next = forms.IntegerField(
min_value=0, min_value=0,
max_value=6, max_value=6,
...@@ -121,6 +191,9 @@ class SlideExportForm(AdminIntermediateForm): ...@@ -121,6 +191,9 @@ class SlideExportForm(AdminIntermediateForm):
class DefaultSlotEditorForm(AdminIntermediateForm): class DefaultSlotEditorForm(AdminIntermediateForm):
"""
Form for default slot editor
"""
availabilities = forms.CharField( availabilities = forms.CharField(
label=_('Default Slots'), label=_('Default Slots'),
help_text=_( help_text=_(
...@@ -133,6 +206,12 @@ class DefaultSlotEditorForm(AdminIntermediateForm): ...@@ -133,6 +206,12 @@ class DefaultSlotEditorForm(AdminIntermediateForm):
class RoomBatchCreationForm(AdminIntermediateForm): class RoomBatchCreationForm(AdminIntermediateForm):
"""
Form for room batch creation
Allows to input a list of room details and choose whether default availabilities should be generated for these
rooms. Will check that the input follows a CSV format with at least a name column present.
"""
rooms = forms.CharField( rooms = forms.CharField(
label=_('New rooms'), label=_('New rooms'),
help_text=_('Enter room details in CSV format. Required colum is "name", optional colums are "location", ' help_text=_('Enter room details in CSV format. Required colum is "name", optional colums are "location", '
...@@ -147,6 +226,13 @@ class RoomBatchCreationForm(AdminIntermediateForm): ...@@ -147,6 +226,13 @@ class RoomBatchCreationForm(AdminIntermediateForm):
) )
def clean_rooms(self): def clean_rooms(self):
"""
Validate and transform the input for the rooms textfield
Treat the input as CSV and turn it into a dict containing the relevant information.
:return: a dict containing the raw room information
:rtype: dict[str, str]
"""
rooms_raw_text = self.cleaned_data["rooms"] rooms_raw_text = self.cleaned_data["rooms"]
rooms_raw_dict = csv.DictReader(io.StringIO(rooms_raw_text), delimiter=";") rooms_raw_dict = csv.DictReader(io.StringIO(rooms_raw_text), delimiter=";")
...@@ -157,6 +243,10 @@ class RoomBatchCreationForm(AdminIntermediateForm): ...@@ -157,6 +243,10 @@ class RoomBatchCreationForm(AdminIntermediateForm):
class RoomForm(forms.ModelForm): class RoomForm(forms.ModelForm):
"""
Room (creation) form (basic), will be extended for handling of availabilities
(see :class:`RoomFormWithAvailabilities`) and also for creating hybrid rooms in AKOnline (if active)
"""
class Meta: class Meta:
model = Room model = Room
fields = ['name', fields = ['name',
...@@ -167,6 +257,9 @@ class RoomForm(forms.ModelForm): ...@@ -167,6 +257,9 @@ class RoomForm(forms.ModelForm):
class RoomFormWithAvailabilities(AvailabilitiesFormMixin, RoomForm): class RoomFormWithAvailabilities(AvailabilitiesFormMixin, RoomForm):
"""
Room (update) form including handling of availabilities, extends :class:`RoomForm`
"""
class Meta: class Meta:
model = Room model = Room
fields = ['name', fields = ['name',
...@@ -182,7 +275,7 @@ class RoomFormWithAvailabilities(AvailabilitiesFormMixin, RoomForm): ...@@ -182,7 +275,7 @@ class RoomFormWithAvailabilities(AvailabilitiesFormMixin, RoomForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# Init availability mixin # Init availability mixin
kwargs['initial'] = dict() kwargs['initial'] = {}
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.initial = {**self.initial, **kwargs['initial']} self.initial = {**self.initial, **kwargs['initial']}
# Filter possible values for m2m when event is specified # Filter possible values for m2m when event is specified
......