From c016b2c0a3b2e7a46771601fc5b5bed90579691b Mon Sep 17 00:00:00 2001 From: HanseGucker <hansegucker@gmail.com> Date: Mon, 1 Jan 2018 16:38:08 +0100 Subject: [PATCH] Design AUB index | Add status to AUB model --- schoolapps/aub/admin.py | 3 ++- schoolapps/aub/migrations/0008_status.py | 20 +++++++++++++++ schoolapps/aub/migrations/0009_aub_status.py | 17 +++++++++++++ .../aub/migrations/0010_auto_20180101_1634.py | 19 ++++++++++++++ schoolapps/aub/models.py | 25 +++++++++++++++---- schoolapps/aub/templates/aub/index.html | 20 ++++++++++----- schoolapps/aub/views.py | 7 ++++-- 7 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 schoolapps/aub/migrations/0008_status.py create mode 100644 schoolapps/aub/migrations/0009_aub_status.py create mode 100644 schoolapps/aub/migrations/0010_auto_20180101_1634.py diff --git a/schoolapps/aub/admin.py b/schoolapps/aub/admin.py index 95b799a28..71d2503d7 100644 --- a/schoolapps/aub/admin.py +++ b/schoolapps/aub/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Aub +from .models import Aub, Status # Register your models here. admin.site.register(Aub) +admin.site.register(Status) diff --git a/schoolapps/aub/migrations/0008_status.py b/schoolapps/aub/migrations/0008_status.py new file mode 100644 index 000000000..048c5a42a --- /dev/null +++ b/schoolapps/aub/migrations/0008_status.py @@ -0,0 +1,20 @@ +# Generated by Django 2.0 on 2017-12-29 13:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('aub', '0007_auto_20171222_1738'), + ] + + operations = [ + migrations.CreateModel( + name='Status', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('style_classes', models.CharField(max_length=200)), + ], + ), + ] diff --git a/schoolapps/aub/migrations/0009_aub_status.py b/schoolapps/aub/migrations/0009_aub_status.py new file mode 100644 index 000000000..bfe04a1db --- /dev/null +++ b/schoolapps/aub/migrations/0009_aub_status.py @@ -0,0 +1,17 @@ +# Generated by Django 2.0 on 2018-01-01 15:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('aub', '0008_status'), + ] + + operations = [ + migrations.AddField( + model_name='aub', + name='status', + field=models.ForeignKey(default=2, on_delete=models.SET(2), related_name='aubs', to='aub.Status'), + ), + ] diff --git a/schoolapps/aub/migrations/0010_auto_20180101_1634.py b/schoolapps/aub/migrations/0010_auto_20180101_1634.py new file mode 100644 index 000000000..c6b991632 --- /dev/null +++ b/schoolapps/aub/migrations/0010_auto_20180101_1634.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0 on 2018-01-01 15:34 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('aub', '0009_aub_status'), + ] + + operations = [ + migrations.AlterField( + model_name='aub', + name='created_by', + field=models.ForeignKey(default=3, on_delete=models.SET(3), related_name='aubs', + to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/schoolapps/aub/models.py b/schoolapps/aub/models.py index bfb7b1035..2c6cf5206 100644 --- a/schoolapps/aub/models.py +++ b/schoolapps/aub/models.py @@ -16,7 +16,21 @@ lessons = ( def get_default_user(): - User.objects.get_or_create(username='nouser') + user, created = User.objects.get_or_create(username='nouser') + return user.id + + +class Status(models.Model): + name = models.CharField(max_length=100) + style_classes = models.CharField(max_length=200) + + def __str__(self): + return self.name + + +def get_default_status(): + status, created = Status.objects.get_or_create(name='In Bearbeitung', style_classes='orange') + return status.id class Aub(models.Model): @@ -26,7 +40,8 @@ class Aub(models.Model): # Information description = models.TextField() - + status = models.ForeignKey(Status, related_name='aubs', on_delete=models.SET(get_default_status()), + default=get_default_status()) # Meta created_by = models.ForeignKey(User, related_name='aubs', on_delete=models.SET(get_default_user()), default=get_default_user()) @@ -37,7 +52,7 @@ class Aub(models.Model): class Meta: permissions = ( - ('apply_for_aub', "Apply for a AUB"), - ('allow_aub', "Allow a AUB"), - ('check_aub', "Check a AUB") + ('apply_for_aub', 'Apply for a AUB'), + ('allow_aub', 'Allow a AUB'), + ('check_aub', 'Check a AUB') ) diff --git a/schoolapps/aub/templates/aub/index.html b/schoolapps/aub/templates/aub/index.html index f6b22fce0..7b70dc48d 100644 --- a/schoolapps/aub/templates/aub/index.html +++ b/schoolapps/aub/templates/aub/index.html @@ -1,11 +1,19 @@ {% include 'partials/header.html' %} <main> - <ul> - <h5>Ihre Anträge</h5> - <a href="{% url 'aub_apply_for' %}" class="waves-effect waves-light btn green">Neuen Antrag stellen</a> - {% for todo in todos %} - <li><a href='/todos/details/{{todo.id}}'>{{todo.title}}</a>: {{todo.text}}</li> + + <h5>Ihre Anträge</h5> + <a href="{% url 'aub_apply_for' %}" class="waves-effect waves-light btn green">Neuen Antrag stellen</a> + <ul class="collection"> + {% for aub in aubs %} + <li class="collection-item"> + <span class="badge new {{ aub.status.style_classes }}">{{ aub.status.name }}</span> + <p class="title"> + <i class="material-icons left">access_time</i> + {{ aub.from_dt }} bis {{ aub.to_dt }} + </p> + <p><a href="{% url 'aub_details' aub.id %}">{{ aub.description }}</a></p> + </li> {% endfor %} </ul> -</main> +</main> {% include 'partials/footer.html' %} diff --git a/schoolapps/aub/views.py b/schoolapps/aub/views.py index 4684a30ac..5a99ff8ab 100644 --- a/schoolapps/aub/views.py +++ b/schoolapps/aub/views.py @@ -4,13 +4,16 @@ from django.shortcuts import render, redirect from django.urls import reverse from .forms import ApplyForAUBForm -from .models import Aub +from .models import Aub, Status +IN_PROCESSING_STATUS = Status.objects.get_or_create(name='In Bearbeitung', style_classes='orange') +ALLOWED_STATUS = Status.objects.get_or_create(name='Genehmigt', style_classes='green') +NOT_ALLOWED_STATUS = Status.objects.get_or_create(name='Abgelehnt', style_classes='red') @login_required @permission_required('aub.apply_for_aub') def index(request): - aubs = Aub.objects.all()[:10] + aubs = Aub.objects.filter(created_by=request.user).order_by('-created_at')[:10] context = { 'aubs': aubs -- GitLab