From 780e2d6acbe7a0f1f944dcf2df5af5f8b86867a3 Mon Sep 17 00:00:00 2001 From: Elias Date: Thu, 1 Mar 2018 19:28:27 +0200 Subject: [PATCH 1/4] Committee model --- webapp/models.py | 7 ++++++- webapp/templates/contact.html | 31 +++++++++++++++++++++++++++---- webapp/views.py | 6 ++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/webapp/models.py b/webapp/models.py index c6cea6b..c2bf792 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -236,6 +236,11 @@ class KaehmyForm(MessageParent): return self.preset_roles.filter(is_board=True).exists() or self.custom_roles.filter(is_board=True) +class Committee(models.Model): + """ Committee model, has many Roles found under variable roles """ + name = models.CharField(max_length=255) + + class Role(PresetRole): """ Model for Role. @@ -253,7 +258,7 @@ class Role(PresetRole): start_date = models.DateField(_('Start date')) end_date = models.DateField(_('End date')) official = models.ForeignKey('Official', related_name='roles') - + committee = models.ForeignKey('Committee', related_name='roles', on_delete=models.SET_NULL, blank=True) class Official(User): """Model representing a guild official.""" diff --git a/webapp/templates/contact.html b/webapp/templates/contact.html index a7643c3..320ce45 100644 --- a/webapp/templates/contact.html +++ b/webapp/templates/contact.html @@ -5,10 +5,33 @@
-
-
+

{% trans "Contact" %}

+ {% if roolit %} + {% load static %} +

Kaikki toimihenkilöt

+ + {% for rooli in roolit %} + + + + + {% endfor %} +
+ + + +

{{rooli}} +

{{ rooli.official.first_name }} {{ rooli.official.last_name }}

+ {{ rooli.official.email }} + {{ rooli.official.phone_number }} +

+
+ {% else%} +

Ei rooleja

+ {% endif %} {% if kaikki %} {% for teekkari in kaikki %} @@ -29,8 +52,8 @@

Ei henkilöitä

{% endif %} - - + diff --git a/webapp/views.py b/webapp/views.py index 64915ad..f21c057 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -13,7 +13,7 @@ import logging import requests from dealer.git import git -from webapp.models import PresetKaehmyRole, CustomKaehmyRole, Official +from webapp.models import PresetKaehmyRole, CustomKaehmyRole, Official, Role from webapp.models import OhlhafvChallenge, KaehmyForm, TelegramChannel from webapp.forms import OhlhafvForm, KaehmyForm_Form, KaehmyCommentForm from webapp.tables import OhlhafvTable, KaehmyExportTable @@ -146,7 +146,9 @@ def contact_view(request, *args, **kwargs): """Render "Contact" page.""" kaikki = Official.objects.all() - context = {"kaikki": kaikki} + roolit = Role.objects.all() + + context = {"roolit": roolit, "kaikki": kaikki} return render(request, "contact.html", context) From 7bc277a97883a514ac1fa0eb62f7f54dab216255 Mon Sep 17 00:00:00 2001 From: Elias Date: Thu, 1 Mar 2018 20:53:31 +0200 Subject: [PATCH 2/4] korjauksia --- webapp/admin.py | 3 +- webapp/migrations/0036_auto_20180301_2011.py | 28 ++++++++++++ webapp/models.py | 9 +++- webapp/templates/contact.html | 46 ++++++++++---------- webapp/views.py | 30 +++++++++++-- 5 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 webapp/migrations/0036_auto_20180301_2011.py diff --git a/webapp/admin.py b/webapp/admin.py index 0cfeb8c..3297a3c 100644 --- a/webapp/admin.py +++ b/webapp/admin.py @@ -1,7 +1,7 @@ """File containing webapp app admin registers.""" from django.contrib import admin -from webapp.models import Official, Role +from webapp.models import Official, Role, Committee from webapp.models import Feed, Tag, BaseFeed, Event, Registration from webapp.models import KaehmyForm, KaehmyMessage from webapp.models import CustomKaehmyRole, PresetKaehmyRole @@ -19,6 +19,7 @@ admin.site.register(Event, TranslationAdmin) admin.site.register(Registration, TranslationAdmin) admin.site.register(Official) admin.site.register(Role) +admin.site.register(Committee) admin.site.register(KaehmyForm) admin.site.register(KaehmyMessage) admin.site.register(CustomKaehmyRole) diff --git a/webapp/migrations/0036_auto_20180301_2011.py b/webapp/migrations/0036_auto_20180301_2011.py new file mode 100644 index 0000000..073a964 --- /dev/null +++ b/webapp/migrations/0036_auto_20180301_2011.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-03-01 18:11 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0035_auto_20171019_1413'), + ] + + operations = [ + migrations.CreateModel( + name='Committee', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.AddField( + model_name='role', + name='committee', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='roles', to='webapp.Committee'), + ), + ] diff --git a/webapp/models.py b/webapp/models.py index c2bf792..3010192 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -237,7 +237,12 @@ class KaehmyForm(MessageParent): class Committee(models.Model): - """ Committee model, has many Roles found under variable roles """ + """ + Committee model + + Has many Roles found under variable roles + """ + name = models.CharField(max_length=255) @@ -258,7 +263,7 @@ class Role(PresetRole): start_date = models.DateField(_('Start date')) end_date = models.DateField(_('End date')) official = models.ForeignKey('Official', related_name='roles') - committee = models.ForeignKey('Committee', related_name='roles', on_delete=models.SET_NULL, blank=True) + committee = models.ForeignKey('Committee', related_name='roles', on_delete=models.SET_NULL, null=True) class Official(User): """Model representing a guild official.""" diff --git a/webapp/templates/contact.html b/webapp/templates/contact.html index 320ce45..c400a99 100644 --- a/webapp/templates/contact.html +++ b/webapp/templates/contact.html @@ -9,21 +9,21 @@
-->

{% trans "Contact" %}

- {% if roolit %} + {% if all_roles %} {% load static %} -

Kaikki toimihenkilöt

+

Kaikki Roolit

- {% for rooli in roolit %} + {% for role in all_roles %} @@ -32,24 +32,22 @@ {% else%}

Ei rooleja

{% endif %} - {% if kaikki %} -
-

{{rooli}} -

{{ rooli.official.first_name }} {{ rooli.official.last_name }}

- {{ rooli.official.email }} - {{ rooli.official.phone_number }} +

{{role}} +

{{ role.official.first_name }} {{ rooli.official.last_name }}

+ {{ role.official.email }} + {{ role.official.phone_number }}

- {% for teekkari in kaikki %} - {% load static %} - - - - + + {% if all_committees %} + {% load static %} +

Kaikki Toimikunnat

+ {% for com in all_committees %} +

{{committee.name}}

+ {% if roles_list %} + {% for role in roles_list %} +

{{role.name}}

+ {% endfor %} + {% else %} +

Ei ole rooleja tällä toimikunnalla

+ {% endif %} {% endfor %} -
- - -

{{ teekkari.first_name }} {{ teekkari.last_name }}

- -

{{ teekkari.phone_number }}

-
- {% else %} -

Ei henkilöitä

+ {% else%} +

Ei Toimikuntia

{% endif %}
-

{% trans "Contact" %}

-
- {% if all_roles %} - {% load static %} -

Kaikki Roolit

- - {% for role in all_roles %} - - - - - {% endfor %} -
- + {% load static %} + +

{% trans "Contact" %}

+ + {% if committee_list %} + + {% for com in committee_list %} + + +

{{ com.committee.name }}

+ + + {% if com.roles_list %} + {% for role in com.roles_list %} +
+
+
-
-

{{role}} -

{{ role.official.first_name }} {{ rooli.official.last_name }}

- {{ role.official.email }} - {{ role.official.phone_number }} -

-
- {% else%} -

Ei rooleja

- {% endif %} - - {% if all_committees %} - {% load static %} -

Kaikki Toimikunnat

- {% for com in all_committees %} -

{{committee.name}}

- {% if roles_list %} - {% for role in roles_list %} -

{{role.name}}

- {% endfor %} - {% else %} -

Ei ole rooleja tällä toimikunnalla

- {% endif %} - {% endfor %} - {% else%} -

Ei Toimikuntia

- {% endif %} -
- -
+
+
+
+
+
{{role.name}}
+

{{role.official.first_name}} + {{role.official.last_name}} + {{role.official.email}}

+
+
+
+ {% endfor %} + {%endif%} + + {% endfor %} + {% else%} +

Ei Toimikuntia

+ {% endif %} {% endblock %} diff --git a/webapp/views.py b/webapp/views.py index 9107645..6112a36 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -145,8 +145,6 @@ def sosso_view(request, *args, **kwargs): def contact_view(request, *args, **kwargs): """Render "Contact" page.""" - # TODO - # # Lajitellaan roolit toimikunnittain # in format: context = { # committee_list: [ @@ -162,15 +160,14 @@ def contact_view(request, *args, **kwargs): # ]} # - #all_officials = Official.objects.all() all_roles = Role.objects.all() - all_committees = Committee.objects.all() + all_committees = Committee.objects.order_by('name') committee_list = [] for committee in all_committees: - committee_list.append({"committee":committee, "roles_list":committee.roles}) + committee_list.append({"committee":committee, "roles_list":committee.roles.all()}) - context = {"all_roles": all_roles, "all_committees": committee_list} + context = {"all_roles": all_roles, "committee_list": committee_list} return render(request, "contact.html", context) From 6e68e106aa857641739883db979d4b11bbb5f11c Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Wed, 16 May 2018 22:39:43 +0300 Subject: [PATCH 4/4] Update contact models and template --- webapp/migrations/0038_auto_20180516_2108.py | 34 +++++++++++++ webapp/migrations/0039_auto_20180516_2113.py | 39 +++++++++++++++ webapp/migrations/0040_auto_20180516_2124.py | 24 +++++++++ webapp/migrations/0041_auto_20180516_2204.py | 20 ++++++++ webapp/models.py | 51 +++++++++++--------- webapp/templates/contact.html | 29 +++++------ webapp/views.py | 28 ++--------- 7 files changed, 163 insertions(+), 62 deletions(-) create mode 100644 webapp/migrations/0038_auto_20180516_2108.py create mode 100644 webapp/migrations/0039_auto_20180516_2113.py create mode 100644 webapp/migrations/0040_auto_20180516_2124.py create mode 100644 webapp/migrations/0041_auto_20180516_2204.py diff --git a/webapp/migrations/0038_auto_20180516_2108.py b/webapp/migrations/0038_auto_20180516_2108.py new file mode 100644 index 0000000..b58445c --- /dev/null +++ b/webapp/migrations/0038_auto_20180516_2108.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-16 18:08 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0037_auto_20180301_2111'), + ] + + operations = [ + migrations.RemoveField( + model_name='baserole', + name='category', + ), + migrations.RemoveField( + model_name='role', + name='committee', + ), + migrations.AddField( + model_name='official', + name='committee', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='roles', to='webapp.Committee'), + ), + migrations.AlterField( + model_name='role', + name='official', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='roles', to='webapp.Official'), + ), + ] diff --git a/webapp/migrations/0039_auto_20180516_2113.py b/webapp/migrations/0039_auto_20180516_2113.py new file mode 100644 index 0000000..3fd2671 --- /dev/null +++ b/webapp/migrations/0039_auto_20180516_2113.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-16 18:13 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0038_auto_20180516_2108'), + ] + + operations = [ + migrations.RemoveField( + model_name='official', + name='committee', + ), + migrations.RemoveField( + model_name='role', + name='official', + ), + migrations.AddField( + model_name='official', + name='role', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='roles', to='webapp.Role'), + ), + migrations.AddField( + model_name='role', + name='committee', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='roles', to='webapp.Committee'), + ), + migrations.AlterField( + model_name='committee', + name='name', + field=models.CharField(max_length=255, verbose_name='Name'), + ), + ] diff --git a/webapp/migrations/0040_auto_20180516_2124.py b/webapp/migrations/0040_auto_20180516_2124.py new file mode 100644 index 0000000..7370f7b --- /dev/null +++ b/webapp/migrations/0040_auto_20180516_2124.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-16 18:24 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0039_auto_20180516_2113'), + ] + + operations = [ + migrations.RemoveField( + model_name='official', + name='role', + ), + migrations.AddField( + model_name='official', + name='role', + field=models.ManyToManyField(null=True, related_name='roles', to='webapp.Role'), + ), + ] diff --git a/webapp/migrations/0041_auto_20180516_2204.py b/webapp/migrations/0041_auto_20180516_2204.py new file mode 100644 index 0000000..8c5ac91 --- /dev/null +++ b/webapp/migrations/0041_auto_20180516_2204.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-16 19:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('webapp', '0040_auto_20180516_2124'), + ] + + operations = [ + migrations.AlterField( + model_name='official', + name='role', + field=models.ManyToManyField(related_name='official', to='webapp.Role'), + ), + ] diff --git a/webapp/models.py b/webapp/models.py index 6f40f60..bd3ef97 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -90,26 +90,26 @@ class Registration(models.Model): class BaseRole(models.Model): """Base model for occupations/roles.""" - CATEGORIES = ( - ('corporate', _('Corporate affairs')), - ('freshman', _('Freshmen')), - ('international', _('International')), - ('external', _('External affairs')), - ('media', _('Media')), - ('tech', _('Technology')), - ('wellbeing', _('Wellbeing')), - ('elepaja', _('Elepaja')), - ('ceremonies', _('Ceremonies')), - ('culture', _('Culture')), - ('studies', _('Studies')), - ('sosso', _('Sössö magazine')), - ('alumni', _('Alumni relations')), - ('others', _('Others')), - ) + # CATEGORIES = ( + # ('corporate', _('Corporate affairs')), + # ('freshman', _('Freshmen')), + # ('international', _('International')), + # ('external', _('External affairs')), + # ('media', _('Media')), + # ('tech', _('Technology')), + # ('wellbeing', _('Wellbeing')), + # ('elepaja', _('Elepaja')), + # ('ceremonies', _('Ceremonies')), + # ('culture', _('Culture')), + # ('studies', _('Studies')), + # ('sosso', _('Sössö magazine')), + # ('alumni', _('Alumni relations')), + # ('others', _('Others')), + # ) name = models.CharField(_('Name'), max_length=255) is_board = models.BooleanField(_('Board member')) - category = models.CharField(_('Category'), choices=CATEGORIES, default='others', max_length=255) + # category = models.CharField(_('Category'), choices=CATEGORIES, default='others', max_length=255) def __str__(self): n = self.name.capitalize() @@ -237,10 +237,9 @@ class KaehmyForm(MessageParent): class Committee(models.Model): - """ + """ Committee model - - Has many Roles found under variable roles + Has many Roles found under variable roles """ class Meta: @@ -252,7 +251,11 @@ class Committee(models.Model): def __str__(self): return _('Committee: {}').format(self.name) - name = models.CharField(max_length=255) + name = models.CharField(_("Name"), max_length=255) + + @property + def current_roles(self): + return self.roles.all().filter(end_date__gte=timezone.now()).filter(start_date__lte=timezone.now()) class Role(PresetRole): @@ -271,9 +274,9 @@ class Role(PresetRole): start_date = models.DateField(_('Start date')) end_date = models.DateField(_('End date')) - official = models.ForeignKey('Official', related_name='roles') committee = models.ForeignKey('Committee', related_name='roles', on_delete=models.SET_NULL, null=True) + class Official(User): """Model representing a guild official.""" @@ -284,6 +287,10 @@ class Official(User): verbose_name_plural = _('Officials') phone_number = PhoneNumberField(_('Phone number')) + role = models.ManyToManyField('Role', related_name='official') + + def __str__(self): + return '{} {}'.format(self.first_name, self.last_name) # Ohlhafv diff --git a/webapp/templates/contact.html b/webapp/templates/contact.html index bf51df3..98ef85a 100644 --- a/webapp/templates/contact.html +++ b/webapp/templates/contact.html @@ -8,16 +8,12 @@

{% trans "Contact" %}

- {% if committee_list %} - - {% for com in committee_list %} - + {% if committees %} + {% for committee in committees %} -

{{ com.committee.name }}

- - - {% if com.roles_list %} - {% for role in com.roles_list %} +

{{ committee.name }}

+ {% for role in committee.current_roles %} + {% for official in role.official.all %}
@@ -25,17 +21,16 @@
-
-
{{role.name}}
-

{{role.official.first_name}} - {{role.official.last_name}} - {{role.official.email}}

-
+
+
{{role.name}}
+

{{official.first_name}} + {{official.last_name}} + {{official.email}}

+
{% endfor %} - {%endif%} - + {% endfor %} {% endfor %} {% else%}

Ei Toimikuntia

diff --git a/webapp/views.py b/webapp/views.py index 6112a36..6523eb0 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -8,6 +8,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import permission_required, login_required from django.conf import settings +from django.utils import timezone import logging import requests @@ -144,30 +145,11 @@ def sosso_view(request, *args, **kwargs): @require_http_methods(["GET"]) def contact_view(request, *args, **kwargs): """Render "Contact" page.""" + committees = Committee.objects.order_by('name') - # Lajitellaan roolit toimikunnittain - # in format: context = { - # committee_list: [ - # {"committee": 'toimikunta_object', - # "roles_list": [ {role:'Taittaja', officer:'Pekka'}, - # {role:'PJ', officer:'Pentti'}, - # {role:'X-Vastaava', officer:'Petra'} - # ]}, - # {roles_list: [ {role:'Taittaja', officer:'Pekka'}, - # {role:'PJ', officer:'Pentti'}, - # {role:'X-Vastaava', officer:'Petra'} - # ]} - # ]} - # - - all_roles = Role.objects.all() - all_committees = Committee.objects.order_by('name') - - committee_list = [] - for committee in all_committees: - committee_list.append({"committee":committee, "roles_list":committee.roles.all()}) - - context = {"all_roles": all_roles, "committee_list": committee_list} + context = { + "committees": committees + } return render(request, "contact.html", context)