Tests pass, woohoo
This commit is contained in:
@ -15,6 +15,32 @@ from .models import CaseStudy, SpatialRefSys, PointOfInterest
|
||||
from .widgets import JSONFileListWidget
|
||||
|
||||
|
||||
SECTOR_HELP = {
|
||||
'RN': _("including electricity, heat or combined heat and power generation"),
|
||||
'PG': '',
|
||||
'ST': _('Biological, chemical, electrical, electromagnetic, electrochemical, mechanical including gravitational potential, thermal etc.'),
|
||||
'SM': _("including supply of minerals"),
|
||||
'MA': '',
|
||||
}
|
||||
|
||||
POWER_TECHNOLOGY_HELP = {
|
||||
'PT': _('Lines, transformers, machinery etc.'),
|
||||
'HN': _('District heating/cooling, etc.'),
|
||||
'OT': '',
|
||||
}
|
||||
|
||||
def add_explanatory_text(model_choices, explanatory_text):
|
||||
return [
|
||||
(
|
||||
choice[0],
|
||||
mark_safe('<b>%s</b><br><span class="text-muted">%s</span>' %
|
||||
(choice[1], explanatory_text[choice[0]])
|
||||
)
|
||||
) for choice in model_choices
|
||||
]
|
||||
|
||||
|
||||
|
||||
class MinimumZoomWidget(LeafletWidget):
|
||||
geometry_field_class = 'MinimumZoomField'
|
||||
|
||||
@ -87,6 +113,16 @@ class ShortCaseStudyForm(BaseCaseStudyForm):
|
||||
self.helper.form_action = reverse('short-form')
|
||||
self.helper.add_input(Submit('submit', _('Submit'), css_class='btn-success center-block'))
|
||||
|
||||
# Duplicate code from long form, below...
|
||||
self.fields['sector_of_economy'] = forms.ChoiceField(
|
||||
widget=forms.RadioSelect(),
|
||||
choices=add_explanatory_text(
|
||||
CaseStudy.SECTOR_CHOICES,
|
||||
SECTOR_HELP
|
||||
),
|
||||
required=False
|
||||
)
|
||||
|
||||
class Meta(BaseCaseStudyForm.Meta):
|
||||
fields = [
|
||||
'entry_name',
|
||||
@ -176,32 +212,6 @@ class LongCaseStudyForm(BaseCaseStudyForm):
|
||||
initial=4326,
|
||||
)
|
||||
|
||||
SECTOR_HELP = {
|
||||
'RN': _("including electricity, heat or combined heat and power generation"),
|
||||
'PG': '',
|
||||
'ST': _('Biological, chemical, electrical, electromagnetic, electrochemical, mechanical including gravitational potential, thermal etc.'),
|
||||
'SM': _("including supply of minerals"),
|
||||
'MA': '',
|
||||
}
|
||||
|
||||
POWER_TECHNOLOGY_HELP = {
|
||||
'PT': _('Lines, transformers, machinery etc.'),
|
||||
'HN': _('District heating/cooling, etc.'),
|
||||
'OT': '',
|
||||
}
|
||||
|
||||
# TODO: Allow explanatory_text to not contain text for every option
|
||||
# TODO: Only output <span> if there is explanatory text
|
||||
def add_explanatory_text(self, model_choices, explanatory_text):
|
||||
return [
|
||||
(
|
||||
choice[0],
|
||||
mark_safe('<b>%s</b><br><span class="text-muted">%s</span>' %
|
||||
(choice[1], explanatory_text[choice[0]])
|
||||
)
|
||||
) for choice in model_choices
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LongCaseStudyForm, self).__init__(*args, **kwargs)
|
||||
|
||||
@ -210,18 +220,18 @@ class LongCaseStudyForm(BaseCaseStudyForm):
|
||||
|
||||
self.fields['sector_of_economy'] = forms.ChoiceField(
|
||||
widget=forms.RadioSelect(),
|
||||
choices=self.add_explanatory_text(
|
||||
choices=add_explanatory_text(
|
||||
CaseStudy.SECTOR_CHOICES,
|
||||
self.SECTOR_HELP
|
||||
SECTOR_HELP
|
||||
),
|
||||
required=False
|
||||
)
|
||||
|
||||
self.fields['power_technology'] = forms.ChoiceField(
|
||||
widget=forms.RadioSelect(),
|
||||
choices=self.add_explanatory_text(
|
||||
choices=add_explanatory_text(
|
||||
CaseStudy.POWER_TECHNOLOGY_CHOICES,
|
||||
self.POWER_TECHNOLOGY_HELP
|
||||
POWER_TECHNOLOGY_HELP
|
||||
),
|
||||
required=False
|
||||
)
|
||||
|
Reference in New Issue
Block a user