Update contact models and template

This commit is contained in:
Aarni Halinen
2018-05-16 22:39:43 +03:00
parent 55bcc78670
commit 6e68e106aa
7 changed files with 163 additions and 62 deletions
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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'),
),
]
@@ -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'),
),
]
+29 -22
View File
@@ -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
+12 -17
View File
@@ -8,16 +8,12 @@
<link rel="stylesheet" href="{% static "css/contact.css" %}">
<h2>{% trans "Contact" %}</h2>
{% if committee_list %}
{% for com in committee_list %}
{% if committees %}
{% for committee in committees %}
<!--Committee title-->
<h4>{{ com.committee.name }}</h4>
<!--Listing all roles in this committee-->
{% if com.roles_list %}
{% for role in com.roles_list %}
<h4>{{ committee.name }}</h4>
{% for role in committee.current_roles %}
{% for official in role.official.all %}
<div class="role-container">
<div class="row">
<div class="col">
@@ -25,17 +21,16 @@
</div>
</div>
<div class="row">
<div class="col">
<h5>{{role.name}}</h5>
<p>{{role.official.first_name}}
{{role.official.last_name}}
{{role.official.email}}</p>
</div>
<div class="col">
<h5>{{role.name}}</h5>
<p>{{official.first_name}}
{{official.last_name}}
{{official.email}}</p>
</div>
</div>
</div>
{% endfor %}
{%endif%}
{% endfor %}
{% endfor %}
{% else%}
<p>Ei Toimikuntia</p>
+5 -23
View File
@@ -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)