Edit models and create list view

This commit is contained in:
Jan Tuomi
2017-10-11 18:36:26 +03:00
parent df931fb3e5
commit bd45742953
7 changed files with 116 additions and 7 deletions
@@ -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'),
),
]
+13 -3
View File
@@ -91,6 +91,9 @@ class BaseRole(models.Model):
name = models.CharField(_('Name'), max_length=255) name = models.CharField(_('Name'), max_length=255)
is_board = models.BooleanField(_('Board member')) is_board = models.BooleanField(_('Board member'))
def __str__(self):
return self.name.capitalize()
class PresetRole(BaseRole): class PresetRole(BaseRole):
"""Model representing a preset occupation in the guild.""" """Model representing a preset occupation in the guild."""
@@ -101,14 +104,16 @@ class PresetRole(BaseRole):
class PresetKaehmyRole(PresetRole): class PresetKaehmyRole(PresetRole):
"""Model for kaehmy role.""" """Model for kaehmy role."""
pass
form = models.ForeignKey('KaehmyForm', related_name='preset_roles')
class CustomKaehmyRole(BaseRole): class CustomKaehmyRole(BaseRole):
"""Model representing a user-specified custom occupation.""" """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): class MessageParent(models.Model):
@@ -138,6 +143,11 @@ class KaehmyForm(MessageParent):
name = models.CharField(_('Name'), max_length=255) name = models.CharField(_('Name'), max_length=255)
email = models.EmailField(_('Email')) email = models.EmailField(_('Email'))
year = models.IntegerField(_('Year')) 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): class Role(PresetRole):
+8 -2
View File
@@ -16,17 +16,23 @@
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script> <script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script>
<script src="{% static "js/lib/bootstrap.min.js" %}"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<link rel="stylesheet" href="{% static "css/lib/bootstrap.min.css" %}"> <link rel="stylesheet" href="{% static "css/lib/bootstrap.min.css" %}">
<script src="{% static "js/lib/underscore-min.js" %}"></script> <script src="{% static "js/lib/underscore-min.js" %}"></script>
</head> </head>
<body> <body>
{% block header %}
<div class="header"> <div class="header">
{% include "sik_header.html" %} {% include "sik_header.html" %}
</div> </div>
{% endblock %}
<div class="page-content"> <div class="page-content">
{% include "navigation.html" %} {% block navigation %}
{% include "navigation.html" %}
{% endblock %}
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</div> </div>
+34
View File
@@ -0,0 +1,34 @@
{% extends "base.html" %}
{% load static %}
{% load i18n %}
{% block navigation %}
{% endblock %}
{% block content %}
<div>
<div>
<h2>{% trans "All kaehmys" %}</h2>
</div>
<div>
<h6>{% trans "Total kaehmys:" %} {{ application_count }}</h6>
</div>
{% for application in applications %}
<div class="card">
<div class="card-block">
<h4 class="card-title">{{ application.name }}</h4>
<h5 class=class="card-subtitle mb-2 text-muted">{% trans "Roles" %}:</h5>
{% for role in application.custom_roles.all %}
<h6>{{ role.name }}</h6>
{% endfor %}
{% for role in application.preset_roles.all %}
<h6>{{ role.name }}</h6>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
+1 -1
View File
@@ -12,7 +12,7 @@
</div> </div>
<div class="ohlhafv_count"> <div class="ohlhafv_count">
<span>{% trans "Total challenges:" %} {{ challenge_count }}</span> <span>{% trans "Total challenges:" %}{{ application_count }}</span>
</div> </div>
{{ table|safe }} {{ table|safe }}
+6
View File
@@ -18,6 +18,7 @@ from webapp.views import event_calendar_view
from webapp.views import international_view from webapp.views import international_view
from webapp.views import sosso_view from webapp.views import sosso_view
from webapp.views import contact_view from webapp.views import contact_view
from webapp.views import kaehmy_list_view
urlpatterns = [ urlpatterns = [
# main # main
@@ -30,6 +31,8 @@ urlpatterns = [
# git revision # git revision
url(r'^about', about_view), url(r'^about', about_view),
# pages
url(r'^guild', guild_view), url(r'^guild', guild_view),
url(r'^freshmen', freshmen_view), url(r'^freshmen', freshmen_view),
url(r'^event_calendar', event_calendar_view), url(r'^event_calendar', event_calendar_view),
@@ -44,4 +47,7 @@ urlpatterns = [
url(r'^ohlhafv$', ohlhafv_view), url(r'^ohlhafv$', ohlhafv_view),
url(r'^ohlhafv/submit', ohlhafv_submit), url(r'^ohlhafv/submit', ohlhafv_submit),
url(r'^ohlhafv/list', ohlhafv_list), url(r'^ohlhafv/list', ohlhafv_list),
# kaehmy
url(r'^kaehmy', kaehmy_list_view),
] ]
+15 -1
View File
@@ -8,7 +8,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.decorators import permission_required, login_required from django.contrib.auth.decorators import permission_required, login_required
from django.conf import settings from django.conf import settings
import logging import logging
from webapp.models import OhlhafvChallenge from webapp.models import OhlhafvChallenge, KaehmyForm
from webapp.forms import OhlhafvForm from webapp.forms import OhlhafvForm
from webapp.tables import OhlhafvTable from webapp.tables import OhlhafvTable
@@ -146,3 +146,17 @@ def ohlhafv_list(request, *args, **kwargs):
'challenge_count': len(challenges), 'challenge_count': len(challenges),
} }
return render(request, 'ohlhafv_list.html', context) 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)