diff --git a/README.rst b/README.rst index c237ff2a7712785f741d30a9b76c6cdf229d45fb..e96658f17865759f17f9d061bf91ff9f91f034fd 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 f1677d3cf0fd0a01e8debb484bd3a525de478d59..0000000000000000000000000000000000000000 --- 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 e98a2682192970ae919ae63f80588f31ec028ac1..0000000000000000000000000000000000000000 --- 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 6f694d0e91ed94edc52140c055971709e17b7442..0000000000000000000000000000000000000000 --- 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 75d3cd92500b8e71a6550fdebb979956140dadfd..0000000000000000000000000000000000000000 --- 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 f8d40936cabc3ab66c49bf7c856e57dc38602a96..0000000000000000000000000000000000000000 --- 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 6ecb3a396f4d897d82baac060ae8fe44e904e619..0000000000000000000000000000000000000000 --- 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 aec1e40e289184e59fa9f7cb2a072967a7a6fa70..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..c56447f4a8042610f7f1a310db7b3f25d26f1e4a --- /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 0000000000000000000000000000000000000000..98ac6723126b5eecefe06db48f336bb27abab8b2 --- /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 0000000000000000000000000000000000000000..8342e933224cc55f3b1006907007f185959dce72 --- /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 30b5cfb44000e34fd3caf1296a1dd1b7e202b2df..e4587daaf49a319a602a0658cd9ffc7232957def 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 70% rename from aleksis/apps/mensa/menus.py rename to aleksis/apps/resint/menus.py index d24dd8a9770a7bc6b46faf2fc0e41f64085ba64c..799d4a6784998373612145be688f8645509053dc 100644 --- a/aleksis/apps/mensa/menus.py +++ b/aleksis/apps/resint/menus.py @@ -3,23 +3,23 @@ from django.utils.translation import ugettext_lazy as _ MENUS = { "NAV_MENU_CORE": [ { - "name": _("Menu"), + "name": _("Poster"), "url": "#", - "icon": "restaurant_menu", + "icon": "open_in_browser", "root": True, "validators": [ "menu_generator.validators.is_authenticated", ], "submenu": [ { - "name": _("Current menu"), - "url": "menu_show_current", + "name": _("Current poster"), + "url": "poster_show_current", "icon": "picture_as_pdf", "validators": ["menu_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"], }, diff --git a/aleksis/apps/mensa/migrations/0001_initial.py b/aleksis/apps/resint/migrations/0001_initial.py similarity index 61% rename from aleksis/apps/mensa/migrations/0001_initial.py rename to aleksis/apps/resint/migrations/0001_initial.py index e12bbe06d43eb149dc923bb10966c5106bbbd098..58c47437aa94116ed6b542c580624c2617242ae5 100644 --- a/aleksis/apps/mensa/migrations/0001_initial.py +++ b/aleksis/apps/resint/migrations/0001_initial.py @@ -1,9 +1,9 @@ -# Generated by Django 3.0.2 on 2020-01-18 13:05 +# Generated by Django 3.0.4 on 2020-03-29 16:02 +import aleksis.apps.resint.models +import django.contrib.postgres.fields.jsonb from django.db import migrations, models -import aleksis.apps.mensa.models - class Migration(migrations.Migration): @@ -14,16 +14,17 @@ 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')), + ('extended_data', django.contrib.postgres.fields.jsonb.JSONField(default=dict, editable=False)), ('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 70671ba85666f30ceeeb1b13acc6d1956f7e9d4c..53dca0d8f550ceec0a04c4d5a62203c294aa2374 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 0000000000000000000000000000000000000000..ed40ecdd3440579f339929d0617da61c4308380f --- /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 0000000000000000000000000000000000000000..90dc986206617ede153f486e3717871b3920652d --- /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 9179ff7446b5ce8fcb4935e902ee171b4b4c075c..ca07c32682967d1e4c40367358b04ccd8084380d 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 0000000000000000000000000000000000000000..2830be5752035e33d9b7f6ee3d6deb43aef6280b --- /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 f845cdcb5be9c7a36a0f39db5e9dbd6eb1d66012..d5fea916e300b59b47cb223f05390ab69f451d60 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 9fdf822b275c9f7c53e789d77eb06ddeae84f617..2d12c40ea321e73f30abdec669d524e0e9bd3a07 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.0a1" 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",