Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Link to timetable fixed #142

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ UPDATE `staff_person` SET `tutor_for_id` = '1' WHERE `staff_person`.`is_tutor` =
```

Afterwards you will have to check the conditions of StaffFilterGroups manually as all references to Groups are lost.

## Before applying migration website/0007\_auto\_20170212\_1633 ##

With this migration a OneToOneField was introduced to `website.models.Schedule`.
There is no sensible way to set a different useful default for each entity.
But this model holds effectively no data.
So before applying this migration delete all entities of `website.models.Schedule`.
27 changes: 27 additions & 0 deletions ophasebase/migrations/0005_auto_20170212_1633.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-12 15:33
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('ophasebase', '0004_auto_20170209_2025'),
]

operations = [
migrations.AddField(
model_name='ophasecategory',
name='details_template',
field=models.CharField(default='', max_length=50, verbose_name='Template für Stundenplan View'),
preserve_default=False,
),
migrations.AddField(
model_name='ophasecategory',
name='details_url',
field=models.CharField(default='', max_length=50, verbose_name='Link zum Stundenplan'),
preserve_default=False,
),
]
2 changes: 2 additions & 0 deletions ophasebase/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class Meta:
name = models.CharField(max_length=100, verbose_name=_('Name'))
description_template = models.CharField(max_length=50, verbose_name=_('Beschreibung in Template'))
lang = models.CharField(max_length=5, verbose_name=_('Sprachcode'), default="de")
details_template = models.CharField(max_length=50, verbose_name=_('Template für Stundenplan View'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace these two fields with a slug field containing an url name which could also be used as a template name. There should also be a method getSlug(), which uses the name of the categorie if the slug field is empty. This avoids actions requiered by the user when upgrading.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The slug would then be used to lookup the corresponding category in the website model (enforce unique).

details_url = models.CharField(max_length=50, verbose_name=_('Link zum Stundenplan'))
priority = models.PositiveIntegerField(verbose_name=_("Priorität"), help_text=_("Die Priorität bestimmt unter anderem die Reihenfolge der Anzeige auf der Webseite"))

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SettingsAdmin(admin.ModelAdmin):

@admin.register(Schedule)
class ScheduleAdmin(admin.ModelAdmin):
list_display = ['degree', 'stand']
list_display = ['category', 'stand']


@admin.register(OInforz)
Expand Down
27 changes: 27 additions & 0 deletions website/migrations/0007_auto_20170212_1633.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-02-12 15:33
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('ophasebase', '0005_auto_20170212_1633'),
('website', '0006_oinforz'),
]

operations = [
migrations.RemoveField(
model_name='schedule',
name='degree',
),
migrations.AddField(
model_name='schedule',
name='category',
field=models.OneToOneField(default=1, on_delete=django.db.models.deletion.CASCADE, to='ophasebase.OphaseCategory', verbose_name='Ophasen Kategorie'),
preserve_default=False,
),
]
14 changes: 3 additions & 11 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,20 @@ class Meta:
verbose_name = _("Stundenplan")
verbose_name_plural = _("Stundenpläne")

DEGREE_CHOICES = (
('BSC', _('Bachelor')),
('MSC', _('Master Deutsch')),
('DSS', _('Distributed Software Systems')),
('JBA', _('Joint-Bachelor of Arts')),
('EDU', _('Lehramt Bachelor of Education')),
)

def fixedname_upload_to(instance, filename):
"""returns the path and name where the image should upload to"""
path = 'website/schedule/'
name = instance.degree.lower()
name = instance.category.name.lower()
x, file_extension = os.path.splitext(filename)
return '{}{}{}'.format(path, name, file_extension)

degree = models.CharField(max_length=3, choices=DEGREE_CHOICES, verbose_name=_('Abschluss'), unique=True)
category = models.OneToOneField('ophasebase.OphaseCategory', verbose_name=_('Ophasen Kategorie'))
image = models.ImageField(verbose_name=_('Stundenplan Bild'),
upload_to=fixedname_upload_to, storage=OverwriteStorage())
stand = models.DateField(verbose_name=_('Stand des Stundenplans'))

def __str__(self):
return '{} {}'.format(self.get_degree_display(), _date(self.stand, 'SHORT_DATE_FORMAT'))
return '{} {}'.format(self.category, _date(self.stand, 'SHORT_DATE_FORMAT'))


# Register a signal receiver so the image is deleted when the model is deleted
Expand Down
2 changes: 1 addition & 1 deletion website/templates/website/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2>{{ active_category.category.name }}</h2>
<span class="fa fa-calendar"></span>
<p>
{{ active_category.get_human_short_duration }}<br />
<a href="{% url 'website:bachelor' %}">
<a href="details/{{ active_category.category.details_url }}">
{% trans "zum Stundenplan" %}
</a>
</p>
Expand Down
17 changes: 12 additions & 5 deletions website/urls.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
from django.conf.urls import url
from django.views.generic.base import RedirectView

from . import views


app_name = 'website'
urlpatterns = [
url(r'^$', views.HomepageView.as_view(), name='homepage'),
url(r'^bachelor/$', views.ScheduleView.as_view(), kwargs={'degree': 'BSC'}, name='bachelor'),
url(r'^master-de/$', views.ScheduleView.as_view(), kwargs={'degree': 'MSC'}, name='master-de'),
url(r'^master-dss/$', views.ScheduleView.as_view(), kwargs={'degree': 'DSS'}, name='master-dss'),
url(r'^jba/$', views.ScheduleView.as_view(), kwargs={'degree': 'JBA'}, name='jba'),
url(r'^edu/$', views.ScheduleView.as_view(), kwargs={'degree': 'EDU'}, name='edu'),
url(r'^details/(?P<category>[^/]+)/$', views.DetailsView.as_view(), name='details'),
url(r'^helfen/$', views.HelfenView.as_view(), name='helfen'),
url(r'^oinforz/$', views.OInforzView.as_view(), name='oinforz'),
]

#Redirect old links
urlpatterns += [
url(r'^' + category + r'/$',
RedirectView.as_view(pattern_name='website:details',
permanent=False),
kwargs = {'category' : category},
name = category)
for category in ['bachelor', 'master-de', 'master-dss', 'jba', 'edu']
]
29 changes: 14 additions & 15 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from .models import Schedule, Settings as WebsiteSettings, OInforz

from ophasebase.models import OphaseCategory, OphaseActiveCategory


class HomepageView(TemplateView):
template_name = "website/homepage.html"
Expand Down Expand Up @@ -52,28 +54,25 @@ def get_context_data(self, **kwargs):
return context


class ScheduleView(WebsiteView):
class DetailsView(WebsiteView):
"""Extends the django TemplateView by adding the Ophase.current() object
to the context data as current_ophase"""

def dispatch(self, request, *args, **kwargs):
self.category = get_object_or_404(OphaseCategory, details_url=kwargs['category'])
return super(WebsiteView, self).dispatch(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['schedule'] = get_object_or_404(Schedule, degree=self.kwargs['degree'])
context['schedule'] = get_object_or_404(Schedule,
category = self.category)
context['ophase_duration'] = OphaseActiveCategory.objects\
.get(ophase=Ophase.current(), category = self.category)\
.get_human_duration()
return context

def get_template_names(self):
degree = self.kwargs['degree']

if degree == 'BSC':
return 'website/bachelor.html'
elif degree == 'MSC':
return 'website/master-de.html'
elif degree == 'DSS':
return 'website/master-dss.html'
elif degree == 'JBA':
return 'website/jba.html'
elif degree == 'EDU':
return 'website/lehramt.html'
return self.category.details_template


class HelfenView(WebsiteView):
Expand All @@ -86,4 +85,4 @@ class OInforzView(WebsiteView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['oinforze'] = OInforz.objects.all()
return context
return context