From bd4574295374ee1503dd5b9bda78c7eb97a713f6 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Wed, 11 Oct 2017 18:36:26 +0300 Subject: [PATCH] Edit models and create list view --- webapp/migrations/0016_auto_20171011_1828.py | 39 ++++++++++++++++++++ webapp/models.py | 16 ++++++-- webapp/templates/base.html | 10 ++++- webapp/templates/kaehmy_list.html | 34 +++++++++++++++++ webapp/templates/ohlhafv_list.html | 2 +- webapp/urls.py | 6 +++ webapp/views.py | 16 +++++++- 7 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 webapp/migrations/0016_auto_20171011_1828.py create mode 100644 webapp/templates/kaehmy_list.html diff --git a/webapp/migrations/0016_auto_20171011_1828.py b/webapp/migrations/0016_auto_20171011_1828.py new file mode 100644 index 0000000..00c14c7 --- /dev/null +++ b/webapp/migrations/0016_auto_20171011_1828.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-10-11 15:28 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0015_auto_20170928_2331'), + ] + + operations = [ + migrations.CreateModel( + name='KaehmyFormSelectedRole', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + migrations.RemoveField( + model_name='customkaehmyrole', + name='form', + ), + migrations.RemoveField( + model_name='presetkaehmyrole', + name='form', + ), + migrations.AddField( + model_name='kaehmyform', + name='custom_roles', + field=models.ManyToManyField(blank=True, related_name='forms', to='webapp.CustomKaehmyRole'), + ), + migrations.AddField( + model_name='kaehmyform', + name='preset_roles', + field=models.ManyToManyField(blank=True, related_name='forms', to='webapp.PresetKaehmyRole'), + ), + ] diff --git a/webapp/models.py b/webapp/models.py index b48add0..6ff12c5 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -91,6 +91,9 @@ class BaseRole(models.Model): name = models.CharField(_('Name'), max_length=255) is_board = models.BooleanField(_('Board member')) + def __str__(self): + return self.name.capitalize() + class PresetRole(BaseRole): """Model representing a preset occupation in the guild.""" @@ -101,14 +104,16 @@ class PresetRole(BaseRole): class PresetKaehmyRole(PresetRole): """Model for kaehmy role.""" - - form = models.ForeignKey('KaehmyForm', related_name='preset_roles') + pass class CustomKaehmyRole(BaseRole): """Model representing a user-specified custom occupation.""" + pass - form = models.ForeignKey('KaehmyForm', related_name='custom_roles') + +class KaehmyFormSelectedRole(models.Model): + pass class MessageParent(models.Model): @@ -138,6 +143,11 @@ class KaehmyForm(MessageParent): name = models.CharField(_('Name'), max_length=255) email = models.EmailField(_('Email')) year = models.IntegerField(_('Year')) + custom_roles = models.ManyToManyField('CustomKaehmyRole', related_name='forms', blank=True) + preset_roles = models.ManyToManyField('PresetKaehmyRole', related_name='forms', blank=True) + + def __str__(self): + return _('Hakemus: {}').format(self.name) class Role(PresetRole): diff --git a/webapp/templates/base.html b/webapp/templates/base.html index d864e21..9982589 100644 --- a/webapp/templates/base.html +++ b/webapp/templates/base.html @@ -16,17 +16,23 @@ - + + {% block header %}
{% include "sik_header.html" %}
+ {% endblock %} +
- {% include "navigation.html" %} + {% block navigation %} + {% include "navigation.html" %} + {% endblock %} + {% block content %} {% endblock %}
diff --git a/webapp/templates/kaehmy_list.html b/webapp/templates/kaehmy_list.html new file mode 100644 index 0000000..9ff354c --- /dev/null +++ b/webapp/templates/kaehmy_list.html @@ -0,0 +1,34 @@ +{% extends "base.html" %} + +{% load static %} +{% load i18n %} + +{% block navigation %} +{% endblock %} + +{% block content %} +
+
+

{% trans "All kaehmys" %}

+
+ +
+
{% trans "Total kaehmys:" %} {{ application_count }}
+
+ + {% for application in applications %} +
+
+

{{ application.name }}

+
{% trans "Roles" %}:
+ {% for role in application.custom_roles.all %} +
{{ role.name }}
+ {% endfor %} + {% for role in application.preset_roles.all %} +
{{ role.name }}
+ {% endfor %} +
+
+ {% endfor %} +
+{% endblock content %} diff --git a/webapp/templates/ohlhafv_list.html b/webapp/templates/ohlhafv_list.html index a21e7e5..057ce06 100644 --- a/webapp/templates/ohlhafv_list.html +++ b/webapp/templates/ohlhafv_list.html @@ -12,7 +12,7 @@
- {% trans "Total challenges:" %} {{ challenge_count }} + {% trans "Total challenges:" %}{{ application_count }}
{{ table|safe }} diff --git a/webapp/urls.py b/webapp/urls.py index f9a1f04..fd047b3 100644 --- a/webapp/urls.py +++ b/webapp/urls.py @@ -18,6 +18,7 @@ from webapp.views import event_calendar_view from webapp.views import international_view from webapp.views import sosso_view from webapp.views import contact_view +from webapp.views import kaehmy_list_view urlpatterns = [ # main @@ -30,6 +31,8 @@ urlpatterns = [ # git revision url(r'^about', about_view), + + # pages url(r'^guild', guild_view), url(r'^freshmen', freshmen_view), url(r'^event_calendar', event_calendar_view), @@ -44,4 +47,7 @@ urlpatterns = [ url(r'^ohlhafv$', ohlhafv_view), url(r'^ohlhafv/submit', ohlhafv_submit), url(r'^ohlhafv/list', ohlhafv_list), + + # kaehmy + url(r'^kaehmy', kaehmy_list_view), ] diff --git a/webapp/views.py b/webapp/views.py index 0c2ea69..040a2db 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -8,7 +8,7 @@ from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import permission_required, login_required from django.conf import settings import logging -from webapp.models import OhlhafvChallenge +from webapp.models import OhlhafvChallenge, KaehmyForm from webapp.forms import OhlhafvForm from webapp.tables import OhlhafvTable @@ -146,3 +146,17 @@ def ohlhafv_list(request, *args, **kwargs): 'challenge_count': len(challenges), } return render(request, 'ohlhafv_list.html', context) + + +@ensure_csrf_cookie +@require_http_methods(["GET"]) +def kaehmy_list_view(request, *args, **kwargs): + """Kaehmy application list""" + + applications = KaehmyForm.objects.all() + + context = { + 'applications': applications, + 'application_count': len(applications) + } + return render(request, 'kaehmy_list.html', context)