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

Fix up view for lesson substitution editing. Closes #12.

parent 2a367eb5
No related branches found
No related tags found
1 merge request!9WIP: Add way to edit substitution
...@@ -26,8 +26,8 @@ class LessonsTable(tables.Table): ...@@ -26,8 +26,8 @@ class LessonsTable(tables.Table):
lesson__teachers = tables.Column(accessor='lesson.teacher_names', verbose_name=_('Teachers')) lesson__teachers = tables.Column(accessor='lesson.teacher_names', verbose_name=_('Teachers'))
lesson__subject = tables.Column(accessor='lesson.subject') lesson__subject = tables.Column(accessor='lesson.subject')
room = tables.Column(accessor='room') room = tables.Column(accessor='room')
edit = tables.LinkColumn('edit_substitution_by_id', args=[A('id')]) edit_substitution = tables.LinkColumn('edit_substitution_by_id', args=[A('id')], text=_('Substitution'))
def __init__(self, week, *args, **kwargs): def __init__(self, week, *args, **kwargs):
self._week = week self.edit_substitution.args.append(week)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
...@@ -7,5 +7,5 @@ urlpatterns = [ ...@@ -7,5 +7,5 @@ urlpatterns = [
path('timetable', views.timetable, name='timetable'), path('timetable', views.timetable, name='timetable'),
path('lessons', views.lessons_day, name='lessons_day'), path('lessons', views.lessons_day, name='lessons_day'),
path('lessons/<when>', views.lessons_day, name='lessons_day_by_date'), path('lessons/<when>', views.lessons_day, name='lessons_day_by_date'),
path('substitutions/<id>/edit', views.edit_substitution, name='edit_substitution') path('lessons/<int:id_>/<int:week>/substition', views.edit_substitution, name='edit_substitution')
] ]
...@@ -14,8 +14,8 @@ from biscuit.core.decorators import admin_required ...@@ -14,8 +14,8 @@ from biscuit.core.decorators import admin_required
from biscuit.core.models import Group, Person from biscuit.core.models import Group, Person
from .forms import SelectForm, LessonSubstitutionForm from .forms import SelectForm, LessonSubstitutionForm
from .models import LessonPeriod, TimePeriod, Room from .models import LessonPeriod, TimePeriod, Room, LessonSubstitution
from .util import current_week, week_weekday_from_date from .util import current_week, week_weekday_from_date, week_days
from .tables import LessonsTable from .tables import LessonsTable
...@@ -115,12 +115,16 @@ def lessons_day(request: HttpRequest, when: Optional[str] = None) -> HttpRespons ...@@ -115,12 +115,16 @@ def lessons_day(request: HttpRequest, when: Optional[str] = None) -> HttpRespons
return render(request, 'chronos/lessons_day.html', context) return render(request, 'chronos/lessons_day.html', context)
@admin_required @admin_required
def edit_substitution(request: HttpRequest, id_: int) -> HttpResponse: def edit_substitution(request: HttpRequest, id_: int, week: int) -> HttpResponse:
context = {} context = {}
substitution = get_object_or_404(Substitution, id=id_) lesson_period = get_object_or_404(LessonPeriod, id_)
edit_substitution_form = LessonSubstitutionForm(request.POST or None, instance=substitution) lesson_substitution = LessonSubstitution.objects.filter(week=week, lesson_period=lesson_period).first()
if lesson_substitution:
edit_substitution_form = LessonSubstitutionForm(request.POST or None, instance=lesson_substitution)
else:
edit_substitution_form = LessonSubstitutionForm(request.POST or None, initial={'week': week, 'lesson_period': lesson_period})
context['substitution'] = substitution context['substitution'] = substitution
...@@ -129,7 +133,7 @@ def edit_substitution(request: HttpRequest, id_: int) -> HttpResponse: ...@@ -129,7 +133,7 @@ def edit_substitution(request: HttpRequest, id_: int) -> HttpResponse:
edit_substitution_form.save(commit=True) edit_substitution_form.save(commit=True)
messages.success(request, _('The substitution has been saved.')) messages.success(request, _('The substitution has been saved.'))
return redirect('edit_substitution_by_id', id_=substitution.id) return redirect('lessons_day_by_date', when=week_days(week)[lesson_period.period.weekday].strftime('%Y-%m-%d'))
context['edit_substitution_form'] = edit_substitution_form context['edit_substitution_form'] = edit_substitution_form
......
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