Add formsets/dynamic formsets.

This commit is contained in:
Jan Philipp Timme 2014-11-26 10:20:46 +01:00
parent ee034e976f
commit 63ecd5f4aa
5 changed files with 73 additions and 4 deletions

View File

@ -21,7 +21,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# PIPELINE_ENABLED = False
PIPELINE_ENABLED = False
TEMPLATE_DEBUG = True
@ -119,6 +119,12 @@ PIPELINE_JS = {
),
'output_filename': 'js/b.js',
},
'formsets': {
'source_filenames': (
'js/jquery.formset.js',
),
'output_filename': 'js/f.js',
}
}
CRISPY_TEMPLATE_PACK = 'bootstrap3'

View File

@ -81,3 +81,54 @@ class PersonMapForm(forms.Form):
global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all(), required=False)
preferred_identity = forms.BooleanField(initial=False, required=False)
class PresentationForm(forms.Form):
def __init__(self, *args, **kwargs):
super(PresentationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = u'form-horizontal'
self.helper.label_class = u'col-lg-2'
self.helper.field_class = u'col-lg-4'
self.helper.form_method = u'post'
self.helper.layout = Layout(
u'title',
u'event_type',
u'abstract',
u'given_name',
u'additional_name',
u'family_name',
u'hsh_membership',
u'date',
u'rahmen',
u'workshop',
u'place',
u'startdate',
u'enddate',
u'comments',
u'email',
Submit(u'send', u'Abschicken', css_class=u'btn-default')
)
pass
title = forms.CharField()
event_type = forms.ChoiceField(choices=[(u'new', u'Hauptvortrag'), (u'existing', u'andere Veranstaltung')], initial=u'new', widget=forms.RadioSelect())
abstract = forms.CharField()
# Teilnehmer
given_name = forms.CharField()
additional_name = forms.CharField()
family_name = forms.CharField()
hsh_membership = forms.ChoiceField(choices=[(u'new', u'Yes'), (u'existing', u'No'), (u'idk', u'Maybe')], initial=u'new', widget=forms.RadioSelect())
# Event (other event)
date = forms.DateField()
rahmen = forms.CharField()
workshop = forms.BooleanField()
place = forms.CharField()
startdate = forms.DateField()
enddate = forms.DateField()
comments = forms.CharField()
email = forms.EmailField()

View File

@ -1,5 +1,10 @@
{% extends "layout/base.html" %}
{% block head%}
{% load crispy_forms_tags %}
{% endblock %}
{% block content %}
hallo <br>
<a href="{% url 'frontend-index' %}">zurück</a>
<p>{% crispy form %}</p>
{% endblock %}

View File

@ -12,6 +12,8 @@
<!-- Bootstrap -->
{% compressed_css 'bootstrap' %}
{% compressed_js 'bootstrap' %}
<!-- Dynamic Formsets -->
{% compressed_js 'formsets' %}
<!-- /Bootstrap -->
{% compressed_css 'frontend' %}
<!-- Additional -->

View File

@ -14,7 +14,7 @@ from django.contrib.auth.views import login, logout
from django.core.urlresolvers import reverse
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm
from frontend.forms import NewProjectForm, FileUploadForm, PersonMapForm, PresentationForm
from frontend.models import Project
@ -101,10 +101,15 @@ class ProtectedUpdateView(LoggedInMixin, MyUpdateView):
class IndexView(ProtectedTemplateView):
template_name = u'index.html'
page_title = u'Index'
class HelloView(ProtectedTemplateView):
class HelloView(ProtectedFormView):
template_name = u'hello.html'
page_title = u'Hello'
form_class = PresentationForm
success_url = u'/hello'
def form_valid(self, form):
pass
class ProjectView(ProtectedFormView):
template_name = u'projects.html'