Skip to content
Snippets Groups Projects
Commit eb67257e authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch '1-rename-mensa-to-resint' into 'master'

Only rename app title, data model is unchanged

See merge request AlekSIS/Onboarding/AlekSIS-App-Resint!2
parents 10c85abf 2e2eb9c1
No related branches found
No related tags found
1 merge request!2Only rename app title, data model is unchanged
Showing
with 135 additions and 90 deletions
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
......
from aleksis.core.util.apps import AppConfig
class MensaConfig(AppConfig):
name = "aleksis.apps.mensa"
verbose_name = "AlekSIS – Mēnsa (cantina menu)"
# 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),
),
]
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"),
]
import pkg_resources
try:
__version__ = pkg_resources.get_distribution("AlekSIS-App-Mensa").version
__version__ = pkg_resources.get_distribution("AlekSIS-App-Resint").version
except Exception:
__version__ = "unknown"
default_app_config = "aleksis.apps.mensa.apps.MensaConfig"
default_app_config = "aleksis.apps.resint.apps.ResintConfig"
from django.contrib import admin
from .models import Menu
from .models import Poster
admin.site.register(Menu)
admin.site.register(Poster)
from aleksis.core.util.apps import AppConfig
class ResintConfig(AppConfig):
name = "aleksis.apps.resint"
verbose_name = "AlekSIS – Resint (Public poster)"
File moved
File moved
......@@ -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")
......@@ -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"],
},
......
# 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')},
},
),
......
......@@ -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)
......@@ -5,9 +5,9 @@ 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)
"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 = {
"Mensa settings": ("MENSA_NEW_WEEK_DAY", "MENSA_NEW_WEEK_TIME"),
"Resint settings": ("RESINT_NEW_WEEK_DAY", "RESINT_NEW_WEEK_TIME"),
}
......@@ -2,24 +2,24 @@
{% 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 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 "menu_show_current" %}"><i class="material-icons left">picture_as_pdf</i>
{% trans "Show current menu" %}
<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 menus" %}</h5>
<h5>{% trans "All uploaded posters" %}</h5>
<ul class="collection">
{% for menu in menus %}
{% for poster in posters %}
<li class="collection-item ">
<span class="title">{{ menu }}</span>
<span class="title">{{ poster }}</span>
<p>
<a class="btn-flat waves-effect waves-green" href="{% get_media_prefix %}{{ menu.pdf }}" target="_blank">
<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-menu waves-effect waves-red" href="{% url "menu_delete" menu.id %}">
<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>
......@@ -28,7 +28,7 @@
</ul>
<script type="text/javascript">
$(".delete-menu").click(function (e) {
$(".delete-poster").click(function (e) {
if (!confirm("Wirklich löschen?")) {
e.preventDefault();
}
......
{% 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 %}
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"),
]
......@@ -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()
[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",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment