Form and associated view for Kaehmy

This commit is contained in:
Aarni
2017-10-11 18:55:20 +03:00
parent c36f227bf0
commit 074c4897a7
6 changed files with 68 additions and 3 deletions
+7 -1
View File
@@ -1,7 +1,13 @@
from django import forms
from django.utils.translation import ugettext_lazy as _
from webapp.models import OhlhafvChallenge
from webapp.models import OhlhafvChallenge, KaehmyForm
class KaehmyForm_Form(forms.ModelForm):
class Meta:
model = KaehmyForm
fields = ['name', 'email', 'year', 'preset_roles', 'custom_roles', 'text']
class OhlhafvForm(forms.ModelForm):
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-10-11 15:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('webapp', '0017_kaehmyform_text'),
]
operations = [
migrations.AlterField(
model_name='kaehmyform',
name='year',
field=models.IntegerField(choices=[(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, 'N')], verbose_name='Year'),
),
]
+8 -1
View File
@@ -139,10 +139,17 @@ class KaehmyForm(MessageParent):
Allows user to choose from existing roles or to create custom ones.
"""
YEAR_CHOICES = (
(1, '1'),
(2, '2'),
(3, '3'),
(4, '4'),
(5, 'N'),
)
name = models.CharField(_('Name'), max_length=255)
email = models.EmailField(_('Email'))
year = models.IntegerField(_('Year'))
year = models.IntegerField(_('Year'), choices=YEAR_CHOICES)
text = models.TextField(_('Text'), default="", max_length=300)
custom_roles = models.ManyToManyField('CustomKaehmyRole', related_name='forms', blank=True)
preset_roles = models.ManyToManyField('PresetKaehmyRole', related_name='forms', blank=True)
+21
View File
@@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load bootstrap3 %}
{% load i18n %}
{% block content %}
<div>
<h3>{% trans "Kaehmy" %}</h3>
<div id="input_form">
<form name="kaehmyForm" action="/kaehmy/submit/" method="post" class="form">{% csrf_token %}
{% bootstrap_form form %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans "Submit" %}
</button>
{% endbuttons %}
</form>
</div>
</div>
{% endblock content %}
+4
View File
@@ -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_view
from webapp.views import kaehmy_list_view
urlpatterns = [
@@ -43,6 +44,9 @@ urlpatterns = [
# corporate
url(r'^jobs', jobs_view),
#kaehmy
url(r'^kaehmy$', kaehmy_view),
# ohlhafv
url(r'^ohlhafv$', ohlhafv_view),
url(r'^ohlhafv/submit', ohlhafv_submit),
+8 -1
View File
@@ -9,7 +9,7 @@ from django.contrib.auth.decorators import permission_required, login_required
from django.conf import settings
import logging
from webapp.models import OhlhafvChallenge, KaehmyForm
from webapp.forms import OhlhafvForm
from webapp.forms import OhlhafvForm, KaehmyForm_Form
from webapp.tables import OhlhafvTable
@@ -106,6 +106,13 @@ def contact_view(request, *args, **kwargs):
return render(request, "contact.html", {})
@require_http_methods(["GET"])
def kaehmy_view(request, *args, **kwargs):
"""Render Ohlhafv form page."""
form = KaehmyForm_Form()
return render(request, 'kaehmy.html', {'form': form})
@require_http_methods(["GET"])
def ohlhafv_view(request, *args, **kwargs):
"""Render Ohlhafv form page."""