From 73d6179189834e5649f0748a6ee899a8731aca50 Mon Sep 17 00:00:00 2001 From: Frank Poetzsch-Heffter <p-h@katharineum.de> Date: Sun, 29 Mar 2020 17:38:26 +0200 Subject: [PATCH] Rename mensa to resint and menu to poster --- README.rst | 8 ++-- aleksis/apps/mensa/__init__.py | 8 ---- aleksis/apps/mensa/admin.py | 5 --- aleksis/apps/mensa/apps.py | 6 --- .../0002_extensible_model_as_default.py | 19 -------- aleksis/apps/mensa/settings.py | 13 ------ aleksis/apps/mensa/templates/mensa/index.html | 37 --------------- aleksis/apps/mensa/urls.py | 11 ----- aleksis/apps/resint/__init__.py | 8 ++++ aleksis/apps/resint/admin.py | 5 +++ aleksis/apps/resint/apps.py | 6 +++ aleksis/apps/{mensa => resint}/default.odt | Bin aleksis/apps/{mensa => resint}/default.pdf | Bin aleksis/apps/{mensa => resint}/forms.py | 6 +-- aleksis/apps/{mensa => resint}/menus.py | 18 ++++---- .../migrations/0001_initial.py | 10 ++--- .../{mensa => resint}/migrations/__init__.py | 0 aleksis/apps/{mensa => resint}/models.py | 12 ++--- aleksis/apps/resint/settings.py | 13 ++++++ .../apps/resint/templates/resint/index.html | 37 +++++++++++++++ .../templates/resint}/upload.html | 6 +-- aleksis/apps/resint/urls.py | 11 +++++ aleksis/apps/{mensa => resint}/views.py | 42 +++++++++--------- pyproject.toml | 8 ++-- 24 files changed, 135 insertions(+), 154 deletions(-) delete mode 100644 aleksis/apps/mensa/__init__.py delete mode 100644 aleksis/apps/mensa/admin.py delete mode 100644 aleksis/apps/mensa/apps.py delete mode 100644 aleksis/apps/mensa/migrations/0002_extensible_model_as_default.py delete mode 100644 aleksis/apps/mensa/settings.py delete mode 100644 aleksis/apps/mensa/templates/mensa/index.html delete mode 100644 aleksis/apps/mensa/urls.py create mode 100644 aleksis/apps/resint/__init__.py create mode 100644 aleksis/apps/resint/admin.py create mode 100644 aleksis/apps/resint/apps.py rename aleksis/apps/{mensa => resint}/default.odt (100%) rename aleksis/apps/{mensa => resint}/default.pdf (100%) rename aleksis/apps/{mensa => resint}/forms.py (90%) rename aleksis/apps/{mensa => resint}/menus.py (53%) rename aleksis/apps/{mensa => resint}/migrations/0001_initial.py (76%) rename aleksis/apps/{mensa => resint}/migrations/__init__.py (100%) rename aleksis/apps/{mensa => resint}/models.py (59%) create mode 100644 aleksis/apps/resint/settings.py create mode 100644 aleksis/apps/resint/templates/resint/index.html rename aleksis/apps/{mensa/templates/mensa => resint/templates/resint}/upload.html (62%) create mode 100644 aleksis/apps/resint/urls.py rename aleksis/apps/{mensa => resint}/views.py (57%) diff --git a/README.rst b/README.rst index c237ff2..e96658f 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ -AlekSIS (School Information System) — App Mēnsa (cantina menu) -============================================================== +AlekSIS (School Information System) — App Resint (Public poster) +================================================================ AlekSIS ------- @@ -9,8 +9,8 @@ This is an application for use with the `AlekSIS`_ platform. Features -------- -The Mēnsa app provides an interface for uploading PDF menus attached by a calendar week in which this menu is valid. -The app provides a public URL `current.pdf` which always returns the current menu PDF and adds an menu item linked to +The Resint app provides an interface for uploading PDF posters attached by a calendar week in which this poster is valid. +The app provides a public URL `current.pdf` which always returns the current poster PDF and adds an poster item linked to the same URL. Licence diff --git a/aleksis/apps/mensa/__init__.py b/aleksis/apps/mensa/__init__.py deleted file mode 100644 index f1677d3..0000000 --- a/aleksis/apps/mensa/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -import pkg_resources - -try: - __version__ = pkg_resources.get_distribution("AlekSIS-App-Mensa").version -except Exception: - __version__ = "unknown" - -default_app_config = "aleksis.apps.mensa.apps.MensaConfig" diff --git a/aleksis/apps/mensa/admin.py b/aleksis/apps/mensa/admin.py deleted file mode 100644 index e98a268..0000000 --- a/aleksis/apps/mensa/admin.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.contrib import admin - -from .models import Menu - -admin.site.register(Menu) diff --git a/aleksis/apps/mensa/apps.py b/aleksis/apps/mensa/apps.py deleted file mode 100644 index 6f694d0..0000000 --- a/aleksis/apps/mensa/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from aleksis.core.util.apps import AppConfig - - -class MensaConfig(AppConfig): - name = "aleksis.apps.mensa" - verbose_name = "AlekSIS – Mēnsa (cantina menu)" diff --git a/aleksis/apps/mensa/migrations/0002_extensible_model_as_default.py b/aleksis/apps/mensa/migrations/0002_extensible_model_as_default.py deleted file mode 100644 index 75d3cd9..0000000 --- a/aleksis/apps/mensa/migrations/0002_extensible_model_as_default.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.0.3 on 2020-02-25 15:40 - -import django.contrib.postgres.fields.jsonb -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('mensa', '0001_initial'), - ] - - operations = [ - migrations.AddField( - model_name='menu', - name='extended_data', - field=django.contrib.postgres.fields.jsonb.JSONField(default=dict, editable=False), - ), - ] diff --git a/aleksis/apps/mensa/settings.py b/aleksis/apps/mensa/settings.py deleted file mode 100644 index f8d4093..0000000 --- a/aleksis/apps/mensa/settings.py +++ /dev/null @@ -1,13 +0,0 @@ -import os -from datetime import time - -from django.utils.translation import gettext_lazy as _ - -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) -CONSTANCE_CONFIG = { - "MENSA_NEW_WEEK_DAY": (4, _("Weekday at which the plan of the next week is to be shown"), "weekday_field"), - "MENSA_NEW_WEEK_TIME": (time(14, 00), _("Time at which the plan of the next week is to be shown"), time) -} -CONSTANCE_CONFIG_FIELDSETS = { - "Mensa settings": ("MENSA_NEW_WEEK_DAY", "MENSA_NEW_WEEK_TIME"), -} diff --git a/aleksis/apps/mensa/templates/mensa/index.html b/aleksis/apps/mensa/templates/mensa/index.html deleted file mode 100644 index 6ecb3a3..0000000 --- a/aleksis/apps/mensa/templates/mensa/index.html +++ /dev/null @@ -1,37 +0,0 @@ -{% extends "core/base.html" %} -{% load msg_box static i18n %} - -{% block content %} - <a class="waves-effect waves-light btn green" href="{% url "menu_upload" %}"><i class="material-icons left">add</i> - {% trans "Upload new menu" %} - </a> - <a class="waves-effect waves-light btn orange" href="{% url "menu_show_current" %}"><i class="material-icons left">picture_as_pdf</i> - {% trans "Show current menu" %} - </a> - - <h5>{% trans "All uploaded menus" %}</h5> - - <ul class="collection"> - {% for menu in menus %} - <li class="collection-item "> - <span class="title">{{ menu }}</span> - <p> - <a class="btn-flat waves-effect waves-green" href="{% get_media_prefix %}{{ menu.pdf }}" target="_blank"> - <i class="material-icons left">picture_as_pdf</i> {% trans "Show" %} - </a> - <a class="btn-flat delete-menu waves-effect waves-red" href="{% url "menu_delete" menu.id %}"> - <i class="material-icons left">delete</i> {% trans "Delete" %} - </a> - </p> - </li> - {% endfor %} - </ul> - - <script type="text/javascript"> - $(".delete-menu").click(function (e) { - if (!confirm("Wirklich löschen?")) { - e.preventDefault(); - } - }) - </script> -{% endblock %} diff --git a/aleksis/apps/mensa/urls.py b/aleksis/apps/mensa/urls.py deleted file mode 100644 index aec1e40..0000000 --- a/aleksis/apps/mensa/urls.py +++ /dev/null @@ -1,11 +0,0 @@ -from django.urls import path - -from . import views - -urlpatterns = [ - path('', views.index, name="menu_index"), - path('upload/', views.upload, name="menu_upload"), - path('delete/<int:id>', views.delete, name="menu_delete"), - path('current.pdf', views.show_current, name="menu_show_current"), - path('<str:msg>', views.index, name="menu_index_msg"), -] diff --git a/aleksis/apps/resint/__init__.py b/aleksis/apps/resint/__init__.py new file mode 100644 index 0000000..c56447f --- /dev/null +++ b/aleksis/apps/resint/__init__.py @@ -0,0 +1,8 @@ +import pkg_resources + +try: + __version__ = pkg_resources.get_distribution("AlekSIS-App-Resint").version +except Exception: + __version__ = "unknown" + +default_app_config = "aleksis.apps.resint.apps.ResintConfig" diff --git a/aleksis/apps/resint/admin.py b/aleksis/apps/resint/admin.py new file mode 100644 index 0000000..98ac672 --- /dev/null +++ b/aleksis/apps/resint/admin.py @@ -0,0 +1,5 @@ +from django.contrib import admin + +from .models import Poster + +admin.site.register(Poster) diff --git a/aleksis/apps/resint/apps.py b/aleksis/apps/resint/apps.py new file mode 100644 index 0000000..8342e93 --- /dev/null +++ b/aleksis/apps/resint/apps.py @@ -0,0 +1,6 @@ +from aleksis.core.util.apps import AppConfig + + +class ResintConfig(AppConfig): + name = "aleksis.apps.resint" + verbose_name = "AlekSIS – Resint (Public poster)" diff --git a/aleksis/apps/mensa/default.odt b/aleksis/apps/resint/default.odt similarity index 100% rename from aleksis/apps/mensa/default.odt rename to aleksis/apps/resint/default.odt diff --git a/aleksis/apps/mensa/default.pdf b/aleksis/apps/resint/default.pdf similarity index 100% rename from aleksis/apps/mensa/default.pdf rename to aleksis/apps/resint/default.pdf diff --git a/aleksis/apps/mensa/forms.py b/aleksis/apps/resint/forms.py similarity index 90% rename from aleksis/apps/mensa/forms.py rename to aleksis/apps/resint/forms.py index 30b5cfb..e4587da 100644 --- a/aleksis/apps/mensa/forms.py +++ b/aleksis/apps/resint/forms.py @@ -4,7 +4,7 @@ from django.utils import timezone from material import Layout, Row -from .models import Menu +from .models import Poster current_year = timezone.datetime.now().year options_for_year = [(current_year, current_year), (current_year + 1, current_year + 1)] @@ -12,7 +12,7 @@ options_for_year = [(current_year, current_year), (current_year + 1, current_yea calendar_weeks = [(cw, str(cw)) for cw in range(1, 53)] -class MenuUploadForm(forms.ModelForm): +class PosterUploadForm(forms.ModelForm): calendar_week = forms.ChoiceField(choices=calendar_weeks, initial=timezone.datetime.now().isocalendar()[1]) year = forms.ChoiceField( initial=timezone.datetime.now().year, choices=options_for_year @@ -27,5 +27,5 @@ class MenuUploadForm(forms.ModelForm): ) class Meta: - model = Menu + model = Poster fields = ("calendar_week", "year", "pdf") diff --git a/aleksis/apps/mensa/menus.py b/aleksis/apps/resint/menus.py similarity index 53% rename from aleksis/apps/mensa/menus.py rename to aleksis/apps/resint/menus.py index d24dd8a..e2aa43f 100644 --- a/aleksis/apps/mensa/menus.py +++ b/aleksis/apps/resint/menus.py @@ -1,11 +1,11 @@ from django.utils.translation import ugettext_lazy as _ -MENUS = { - "NAV_MENU_CORE": [ +POSTERS = { + "NAV_POSTER_CORE": [ { - "name": _("Menu"), + "name": _("Poster"), "url": "#", - "icon": "restaurant_menu", + "icon": "open_in_browser", "root": True, "validators": [ "menu_generator.validators.is_authenticated", @@ -13,15 +13,15 @@ MENUS = { "submenu": [ { "name": _("Current menu"), - "url": "menu_show_current", + "url": "poster_show_current", "icon": "picture_as_pdf", - "validators": ["menu_generator.validators.is_authenticated"], + "validators": ["poster_generator.validators.is_authenticated"], }, { - "name": _("Upload menu"), - "url": "menu_index", + "name": _("Upload poster"), + "url": "poster_index", "icon": "file_upload", - "validators": ["menu_generator.validators.is_authenticated"], + "validators": ["poster_generator.validators.is_authenticated"], }, ], } diff --git a/aleksis/apps/mensa/migrations/0001_initial.py b/aleksis/apps/resint/migrations/0001_initial.py similarity index 76% rename from aleksis/apps/mensa/migrations/0001_initial.py rename to aleksis/apps/resint/migrations/0001_initial.py index e12bbe0..c03f6fe 100644 --- a/aleksis/apps/mensa/migrations/0001_initial.py +++ b/aleksis/apps/resint/migrations/0001_initial.py @@ -2,7 +2,7 @@ from django.db import migrations, models -import aleksis.apps.mensa.models +import aleksis.apps.resint.models class Migration(migrations.Migration): @@ -14,16 +14,16 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='Menu', + name='Poster', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('calendar_week', models.IntegerField(verbose_name='CW')), ('year', models.IntegerField(verbose_name='Year')), - ('pdf', models.FileField(upload_to=aleksis.apps.mensa.models.path_and_rename_menu, verbose_name='PDF')), + ('pdf', models.FileField(upload_to=aleksis.apps.resint.models.path_and_rename_poster, verbose_name='PDF')), ], options={ - 'verbose_name': 'Menu', - 'verbose_name_plural': 'Menus', + 'verbose_name': 'Poster', + 'verbose_name_plural': 'Posters', 'unique_together': {('calendar_week', 'year')}, }, ), diff --git a/aleksis/apps/mensa/migrations/__init__.py b/aleksis/apps/resint/migrations/__init__.py similarity index 100% rename from aleksis/apps/mensa/migrations/__init__.py rename to aleksis/apps/resint/migrations/__init__.py diff --git a/aleksis/apps/mensa/models.py b/aleksis/apps/resint/models.py similarity index 59% rename from aleksis/apps/mensa/models.py rename to aleksis/apps/resint/models.py index 70671ba..53dca0d 100644 --- a/aleksis/apps/mensa/models.py +++ b/aleksis/apps/resint/models.py @@ -5,19 +5,19 @@ from aleksis.core.mixins import ExtensibleModel from aleksis.core.util.core_helpers import path_and_rename -def path_and_rename_menu(instance, filename: str) -> str: - return path_and_rename(instance, filename, upload_to="menu") +def path_and_rename_poster(instance, filename: str) -> str: + return path_and_rename(instance, filename, upload_to="poster") -class Menu(ExtensibleModel): +class Poster(ExtensibleModel): calendar_week = models.IntegerField(verbose_name=_("CW")) year = models.IntegerField(verbose_name=_("Year")) - pdf = models.FileField(upload_to=path_and_rename_menu, verbose_name=_("PDF")) + pdf = models.FileField(upload_to=path_and_rename_poster, verbose_name=_("PDF")) class Meta: unique_together = ("calendar_week", "year") - verbose_name = _("Menu") - verbose_name_plural = _("Menus") + verbose_name = _("Poster") + verbose_name_plural = _("Posters") def __str__(self): return "{} {}/{}".format(_("CW"), self.calendar_week, self.year) diff --git a/aleksis/apps/resint/settings.py b/aleksis/apps/resint/settings.py new file mode 100644 index 0000000..ed40ecd --- /dev/null +++ b/aleksis/apps/resint/settings.py @@ -0,0 +1,13 @@ +import os +from datetime import time + +from django.utils.translation import gettext_lazy as _ + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +CONSTANCE_CONFIG = { + "RESINT_NEW_WEEK_DAY": (4, _("Weekday at which the poster of the next week is to be shown"), "weekday_field"), + "RESINT_NEW_WEEK_TIME": (time(14, 00), _("Time at which the poster of the next week is to be shown"), time) +} +CONSTANCE_CONFIG_FIELDSETS = { + "Resint settings": ("RESINT_NEW_WEEK_DAY", "RESINT_NEW_WEEK_TIME"), +} diff --git a/aleksis/apps/resint/templates/resint/index.html b/aleksis/apps/resint/templates/resint/index.html new file mode 100644 index 0000000..90dc986 --- /dev/null +++ b/aleksis/apps/resint/templates/resint/index.html @@ -0,0 +1,37 @@ +{% extends "core/base.html" %} +{% load msg_box static i18n %} + +{% block content %} + <a class="waves-effect waves-light btn green" href="{% url "poster_upload" %}"><i class="material-icons left">add</i> + {% trans "Upload new poster" %} + </a> + <a class="waves-effect waves-light btn orange" href="{% url "poster_show_current" %}"><i class="material-icons left">picture_as_pdf</i> + {% trans "Show current poster" %} + </a> + + <h5>{% trans "All uploaded posters" %}</h5> + + <ul class="collection"> + {% for poster in posters %} + <li class="collection-item "> + <span class="title">{{ poster }}</span> + <p> + <a class="btn-flat waves-effect waves-green" href="{% get_media_prefix %}{{ poster.pdf }}" target="_blank"> + <i class="material-icons left">picture_as_pdf</i> {% trans "Show" %} + </a> + <a class="btn-flat delete-poster waves-effect waves-red" href="{% url "poster_delete" poster.id %}"> + <i class="material-icons left">delete</i> {% trans "Delete" %} + </a> + </p> + </li> + {% endfor %} + </ul> + + <script type="text/javascript"> + $(".delete-poster").click(function (e) { + if (!confirm("Wirklich löschen?")) { + e.preventDefault(); + } + }) + </script> +{% endblock %} diff --git a/aleksis/apps/mensa/templates/mensa/upload.html b/aleksis/apps/resint/templates/resint/upload.html similarity index 62% rename from aleksis/apps/mensa/templates/mensa/upload.html rename to aleksis/apps/resint/templates/resint/upload.html index 9179ff7..ca07c32 100644 --- a/aleksis/apps/mensa/templates/mensa/upload.html +++ b/aleksis/apps/resint/templates/resint/upload.html @@ -1,7 +1,7 @@ {% extends "core/base.html" %} {% load msg_box i18n material_form %} -{% block page_title %}{% trans "Upload menu" %}{% endblock %} +{% block page_title %}{% trans "Upload poster" %}{% endblock %} {% block content %} <form method="post" enctype="multipart/form-data"> @@ -11,11 +11,11 @@ <button class="waves-effect waves-light btn green" type="submit"> <i class="material-icons left">cloud_upload</i> - {% trans "Upload and publish menu" %} + {% trans "Upload and publish poster" %} </button> </form> <p> - <a href="{% url 'menu_index' %}" class="waves-effect waves-teal btn-flat">{% trans "Back to overview" %}</a> + <a href="{% url 'poster_index' %}" class="waves-effect waves-teal btn-flat">{% trans "Back to overview" %}</a> </p> {% endblock %} diff --git a/aleksis/apps/resint/urls.py b/aleksis/apps/resint/urls.py new file mode 100644 index 0000000..2830be5 --- /dev/null +++ b/aleksis/apps/resint/urls.py @@ -0,0 +1,11 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name="poster_index"), + path('upload/', views.upload, name="poster_upload"), + path('delete/<int:id>', views.delete, name="poster_delete"), + path('current.pdf', views.show_current, name="poster_show_current"), + path('<str:msg>', views.index, name="poster_index_msg"), +] diff --git a/aleksis/apps/mensa/views.py b/aleksis/apps/resint/views.py similarity index 57% rename from aleksis/apps/mensa/views.py rename to aleksis/apps/resint/views.py index f845cdc..d5fea91 100644 --- a/aleksis/apps/mensa/views.py +++ b/aleksis/apps/resint/views.py @@ -12,43 +12,43 @@ from constance import config from aleksis.core.util import messages -from .forms import MenuUploadForm -from .models import Menu +from .forms import PosterUploadForm +from .models import Poster from .settings import BASE_DIR @login_required -@permission_required("mensa.add_menu") +@permission_required("resint.add_poster") def upload(request): if request.method == 'POST': - form = MenuUploadForm(request.POST, request.FILES) + form = PosterUploadForm(request.POST, request.FILES) if form.is_valid(): form.save() - messages.success(request, _("The menu was uploaded successfully.")) - return redirect('menu_index') + messages.success(request, _("The poster was uploaded successfully.")) + return redirect('poster_index') else: - form = MenuUploadForm() - return render(request, 'mensa/upload.html', { + form = PosterUploadForm() + return render(request, 'resint/upload.html', { 'form': form }) @login_required -@permission_required("mensa.add_menu") +@permission_required("resint.add_poster") def delete(request, id): - menu = get_object_or_404(Menu, pk=id) - menu.delete() + poster = get_object_or_404(Poster, pk=id) + poster.delete() - messages.success(request, _("The menu was deleted successfully.")) - return redirect("menu_index") + messages.success(request, _("The poster was deleted successfully.")) + return redirect("poster_index") @login_required -@permission_required("menu.add_menu") +@permission_required("poster.add_poster") def index(request): - menus = Menu.objects.all().order_by("calendar_week", "year") - return render(request, 'mensa/index.html', {"menus": menus}) + posters = Poster.objects.all().order_by("calendar_week", "year") + return render(request, 'resint/index.html', {"posters": posters}) def return_pdf(filename): @@ -70,18 +70,18 @@ def show_current(request): cw = CalendarWeek.from_date(current_date) # Create datetime with the friday of the week and the toggle time - friday = cw[int(config.MENSA_NEW_WEEK_DAY)] - friday = timezone.datetime.combine(friday, config.MENSA_NEW_WEEK_TIME) + friday = cw[int(config.RESINT_NEW_WEEK_DAY)] + friday = timezone.datetime.combine(friday, config.RESINT_NEW_WEEK_TIME) - # Check whether to show the plan of the next week or the current week + # Check whether to show the poster of the next week or the current week if current_date > friday: cw += 1 # Look for matching PDF in DB try: - obj = Menu.objects.get(year=cw.year, calendar_week=cw.week) + obj = Poster.objects.get(year=cw.year, calendar_week=cw.week) return return_pdf(os.path.join(settings.MEDIA_ROOT, str(obj.pdf))) # Or show the default PDF - except Menu.DoesNotExist: + except Poster.DoesNotExist: return return_default_pdf() diff --git a/pyproject.toml b/pyproject.toml index 9fdf822..443c3db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,16 @@ [tool.poetry] -name = "AlekSIS-App-Mensa" -version = "1.0a4dev0" +name = "AlekSIS-App-Resint" +version = "2.02a" packages = [ { include = "aleksis" } ] readme = "README.rst" -description = "AlekSIS (School Information System) — App Mēnsa (cantina menu)" +description = "AlekSIS (School Information System) — App Resint (Public poster)" authors = ["Julian Leucker <leuckeju@katharineum.de>", "Jonathan Weth <wethjo@katharineum.de>"] license = "EUPL-1.2" homepage = "https://aleksis.edugit.io/" -repository = "https://edugit.org/AlekSIS/AlekSIS-App-mensa" +repository = "https://edugit.org/AlekSIS/AlekSIS-App-resint" documentation = "https://aleksis.edugit.io/AlekSIS/docs/html/" classifiers = [ "Environment :: Web Environment", -- GitLab