citavi_mapper/frontend/forms.py

71 lines
2.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from django import forms
from frontend.models import Project, PersonGlobalIdentity
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout
2014-08-07 14:47:59 +02:00
class NewProjectForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
2014-08-07 14:47:59 +02:00
super(NewProjectForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-lg-2'
self.helper.field_class = 'col-lg-4'
self.helper.form_method = 'post'
self.helper.layout = Layout(
'name',
'description',
Submit('send', 'Create', css_class='btn-default')
)
name = forms.CharField(
label="Name",
max_length=255,
required=True,
)
description = forms.CharField(
label="Description",
required=True,
)
class Meta:
model = Project
fields = ['name', 'description']
class FileUploadForm(forms.Form):
def __init__(self, *args, **kwargs):
super(FileUploadForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-lg-2'
self.helper.field_class = 'col-lg-4'
self.helper.form_method = 'post'
self.helper.layout = Layout(
'file',
Submit('send', 'Upload', css_class='btn-default')
)
file = forms.FileField()
class PersonMapForm(forms.Form):
def __init__(self, *args, **kwargs):
super(PersonMapForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-lg-2'
self.helper.field_class = 'col-lg-4'
self.helper.form_method = 'post'
self.helper.layout = Layout(
'action',
'global_identity',
Submit('skip', 'Skip', css_class='btn-default'),
Submit('save-continue', 'Save and continue', css_class='btn-default'),
)
action = forms.ChoiceField(choices=[('new', 'Create new global Identity'), ('existing', 'Map to existing identity')], initial='new', widget=forms.RadioSelect())
global_identity = forms.ModelChoiceField(queryset=PersonGlobalIdentity.objects.all(), required=False)