From 5e39fac84fa623290b63806e19ee0cd035fb6fcf Mon Sep 17 00:00:00 2001 From: HanseGucker <joniweth@gmx.de> Date: Wed, 10 Apr 2019 16:41:02 +0200 Subject: [PATCH] Init data models for timetable hints --- biscuit/apps/chronos/admin.py | 4 ++ .../apps/chronos/migrations/0001_initial.py | 38 +++++++++++++ .../apps/chronos/migrations/0002_hintclass.py | 19 +++++++ .../migrations/0003_auto_20190410_1634.py | 27 +++++++++ biscuit/apps/chronos/migrations/__init__.py | 0 biscuit/apps/chronos/models.py | 56 ++++++++++++++----- biscuit/apps/chronos/settings.py | 16 ++++++ biscuit/apps/chronos/views.py | 2 +- 8 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 biscuit/apps/chronos/migrations/0001_initial.py create mode 100644 biscuit/apps/chronos/migrations/0002_hintclass.py create mode 100644 biscuit/apps/chronos/migrations/0003_auto_20190410_1634.py create mode 100644 biscuit/apps/chronos/migrations/__init__.py create mode 100644 biscuit/apps/chronos/settings.py diff --git a/biscuit/apps/chronos/admin.py b/biscuit/apps/chronos/admin.py index 8c38f3f3..967ad9c7 100755 --- a/biscuit/apps/chronos/admin.py +++ b/biscuit/apps/chronos/admin.py @@ -1,3 +1,7 @@ from django.contrib import admin # Register your models here. +from timetable.models import Hint, HintClass + +admin.site.register(Hint) +admin.site.register(HintClass) diff --git a/biscuit/apps/chronos/migrations/0001_initial.py b/biscuit/apps/chronos/migrations/0001_initial.py new file mode 100644 index 00000000..d5858985 --- /dev/null +++ b/biscuit/apps/chronos/migrations/0001_initial.py @@ -0,0 +1,38 @@ +# Generated by Django 2.1.5 on 2019-04-10 12:30 + +import datetime +from django.db import migrations, models +import martor.models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + ('untisconnect', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Hint', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('from_date', models.DateField(default=datetime.date.today, verbose_name='Startdatum')), + ('to_date', models.DateField(default=datetime.date.today, verbose_name='Enddatum')), + ('text', martor.models.MartorField(verbose_name='Hinweistext')), + ], + options={ + 'verbose_name': 'Hinweis', + 'verbose_name_plural': 'Hinweise', + }, + ), + migrations.CreateModel( + name='Timetable', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + options={ + 'permissions': (('show_plan', 'Show plan'),), + }, + ), + ] diff --git a/biscuit/apps/chronos/migrations/0002_hintclass.py b/biscuit/apps/chronos/migrations/0002_hintclass.py new file mode 100644 index 00000000..7f5dd35e --- /dev/null +++ b/biscuit/apps/chronos/migrations/0002_hintclass.py @@ -0,0 +1,19 @@ +# Generated by Django 2.1.5 on 2019-04-10 12:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('timetable', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='HintClass', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('class_id', models.IntegerField()), + ], + ), + ] diff --git a/biscuit/apps/chronos/migrations/0003_auto_20190410_1634.py b/biscuit/apps/chronos/migrations/0003_auto_20190410_1634.py new file mode 100644 index 00000000..b2111e6d --- /dev/null +++ b/biscuit/apps/chronos/migrations/0003_auto_20190410_1634.py @@ -0,0 +1,27 @@ +# Generated by Django 2.1.5 on 2019-04-10 14:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('timetable', '0002_hintclass'), + ] + + operations = [ + migrations.AddField( + model_name='hint', + name='classes', + field=models.ManyToManyField(related_name='hints', to='timetable.HintClass'), + ), + migrations.AlterField( + model_name='hintclass', + name='class_id', + field=models.IntegerField( + choices=[(1, '5a'), (2, '5b'), (3, '5c'), (4, '5d'), (5, '6a'), (6, '6b'), (7, '6c'), (8, '6d'), + (9, '7a'), (10, '7b'), (11, '7c'), (12, '7d'), (13, '8a'), (14, '8b'), (15, '8c'), (16, '8d'), + (17, '9a'), (18, '9b'), (19, '9c'), (20, '9d'), (21, 'Ea'), (22, 'Eb'), (23, 'Ec'), (24, 'Ed'), + (25, 'Q1a'), (26, 'Q1b'), (27, 'Q1c'), (28, 'Q1d'), (29, 'Q2a'), (30, 'Q2b'), (31, 'Q2c'), + (32, 'Q2d')]), + ), + ] diff --git a/biscuit/apps/chronos/migrations/__init__.py b/biscuit/apps/chronos/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/biscuit/apps/chronos/models.py b/biscuit/apps/chronos/models.py index 6f186228..e332cc60 100755 --- a/biscuit/apps/chronos/models.py +++ b/biscuit/apps/chronos/models.py @@ -1,24 +1,52 @@ -from django import forms -import dbsettings +from datetime import date + from django.db import models +from django.db.models import ManyToManyField +from martor.models import MartorField -from untisconnect.api_helper import get_terms +from untisconnect.api import get_class_by_id, get_all_classes +from untisconnect.models import Class -choices = [] -terms = get_terms() -for term in terms: - choices.append((term.id, term.name)) +classes = get_all_classes() +class_choices = [(x.id, x.name) for x in classes] -class Timetable(models.Model): +class HintClass(models.Model): + class_id = models.IntegerField(choices=class_choices) + + def __str__(self): + try: + _class = get_class_by_id(self.class_id) + return _class.name + except Exception: + return "Unbekannte Klasse" + + +for x in classes: + HintClass.objects.get_or_create(class_id=x.id) + + +class Hint(models.Model): + # Time + from_date = models.DateField(default=date.today, verbose_name="Startdatum") + to_date = models.DateField(default=date.today, verbose_name="Enddatum") + + # Text + text = MartorField(verbose_name="Hinweistext") + + # Relations + classes = ManyToManyField(HintClass, related_name="hints") + class Meta: - permissions = ( - ('show_plan', 'Show plan'), - ) + verbose_name = "Hinweis" + verbose_name_plural = "Hinweise" -class UNTISSettings(dbsettings.Group): - term = dbsettings.IntegerValue(widget=forms.Select, choices=choices) -untis_settings = UNTISSettings() + +class Timetable(models.Model): + class Meta: + permissions = ( + ('show_plan', 'Show plan'), + ) diff --git a/biscuit/apps/chronos/settings.py b/biscuit/apps/chronos/settings.py new file mode 100644 index 00000000..fc4ffa73 --- /dev/null +++ b/biscuit/apps/chronos/settings.py @@ -0,0 +1,16 @@ +import dbsettings +from django import forms + +from untisconnect.api_helper import get_terms + +choices = [] +terms = get_terms() +for term in terms: + choices.append((term.id, term.name)) + + +class UNTISSettings(dbsettings.Group): + term = dbsettings.IntegerValue(widget=forms.Select, choices=choices) + + +untis_settings = UNTISSettings() diff --git a/biscuit/apps/chronos/views.py b/biscuit/apps/chronos/views.py index 83b97686..8f517660 100755 --- a/biscuit/apps/chronos/views.py +++ b/biscuit/apps/chronos/views.py @@ -17,7 +17,7 @@ from userinformation import UserInformation from schoolapps.settings import BASE_DIR - +from .models import Hint def get_all_context(): teachers = get_all_teachers() classes = get_all_classes() -- GitLab