ojuso-map/apps/map/forms.py

67 lines
2.1 KiB
Python
Raw Normal View History

2017-06-16 16:06:22 +00:00
from django import forms
2017-10-09 23:58:36 +00:00
from django.urls import reverse
2017-06-16 16:06:22 +00:00
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
from leaflet.forms.widgets import LeafletWidget
from .models import CaseStudy
class BaseCaseStudyForm(forms.ModelForm):
2017-10-09 23:58:36 +00:00
"""Base form class for the CaseStudy model."""
2017-06-16 16:06:22 +00:00
def __init__(self, *args, **kwargs):
super(BaseCaseStudyForm, self).__init__(*args, **kwargs)
2017-06-16 16:06:22 +00:00
self.helper = FormHelper()
self.helper.form_id = 'case-study-form'
self.helper.form_class = 'form-horizontal'
self.helper.form_method = 'post'
self.helper.form_action = 'add'
2017-06-16 16:06:22 +00:00
self.helper.label_class = 'col-lg-2'
self.helper.field_class = 'col-lg-8'
self.helper.add_input(Submit('submit', 'Submit'))
class Meta:
model = CaseStudy
fields = '__all__'
widgets = {'location': LeafletWidget(attrs={})}
class ShortCaseStudyForm(BaseCaseStudyForm):
2017-10-09 23:58:36 +00:00
"""Short version of the CaseStudy form."""
def __init__(self, *args, **kwargs):
super(ShortCaseStudyForm, self).__init__(*args, **kwargs)
self.helper.form_action = reverse('short-form')
class Meta(BaseCaseStudyForm.Meta):
fields = [
'entry_name',
'location',
'sector_of_economy',
'positive_or_negative',
'country',
'area_of_land',
'land_ownership',
'land_ownership_details',
'location_context',
'type_of_ecosystem',
'describe_ecosystem',
'affects_indigenous',
'affects_indigenous_detail',
'project_status',
'synopsis',
'full_description',
'image',
'community_voices'
]
class LongCaseStudyForm(BaseCaseStudyForm):
2017-10-09 23:58:36 +00:00
"""Long version of the CaseStudy form."""
def __init__(self, *args, **kwargs):
super(LongCaseStudyForm, self).__init__(*args, **kwargs)
self.helper.form_action = reverse('long-form')
class Meta(BaseCaseStudyForm.Meta):
fields = '__all__'