Fixup forms and templates for forms

This commit is contained in:
Livvy Mackintosh 2017-10-10 00:58:36 +01:00
parent 8c38748347
commit 52090ec25a
6 changed files with 66 additions and 7 deletions

View File

@ -1,4 +1,5 @@
from django import forms from django import forms
from django.urls import reverse
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit from crispy_forms.layout import Submit
from leaflet.forms.widgets import LeafletWidget from leaflet.forms.widgets import LeafletWidget
@ -7,7 +8,7 @@ from .models import CaseStudy
class BaseCaseStudyForm(forms.ModelForm): class BaseCaseStudyForm(forms.ModelForm):
"""Base form class for the CaseStudy model."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(BaseCaseStudyForm, self).__init__(*args, **kwargs) super(BaseCaseStudyForm, self).__init__(*args, **kwargs)
self.helper = FormHelper() self.helper = FormHelper()
@ -26,6 +27,12 @@ class BaseCaseStudyForm(forms.ModelForm):
class ShortCaseStudyForm(BaseCaseStudyForm): class ShortCaseStudyForm(BaseCaseStudyForm):
"""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): class Meta(BaseCaseStudyForm.Meta):
fields = [ fields = [
'entry_name', 'entry_name',
@ -50,5 +57,10 @@ class ShortCaseStudyForm(BaseCaseStudyForm):
class LongCaseStudyForm(BaseCaseStudyForm): class LongCaseStudyForm(BaseCaseStudyForm):
"""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): class Meta(BaseCaseStudyForm.Meta):
fields = '__all__' fields = '__all__'

View File

@ -0,0 +1,35 @@
{% extends "base_page.html" %}
{% load bootstrap3 %}
{% load compress %}
{% load i18n %}
{% load humanize %}
{% block stylesheets %}
{{ block.super }}
<style>
a.btn-jumbo {
color: navy;
width:320px;
height:240px;
border: 1px solid black;
border-radius: 5px;
white-space: normal;
line-height:55px;
padding:80px 20px;
margin: 20px;
}
a.btn-jumbo > * {
vertical-align: middle;
display: inline-block;
line-height:20px;
}
div.btn-jumbo-group {
text-align: center;
}
</style>
{% endblock %}
{% block title %}{% trans "Thanks!" %}{% endblock %}
{% block inner %}
<p class="lead text-center">{% trans "Your submission will be reviewed shortly. We will update you via email." %}</p>
{% endblock %}

View File

@ -104,7 +104,7 @@
map.on('click', function(e) { map.on('click', function(e) {
var popup = L.popup() var popup = L.popup()
.setLatLng(e.latlng) .setLatLng(e.latlng)
.setContent("<a class='btn btn-primary btn-sm' href='case-study/add?lat="+e.latlng.lat+"&lng="+e.latlng.lng+"' role='button'>{% trans "Submit a Case Study" %}</a>") .setContent("<a class='btn btn-primary btn-sm' href='{% url 'create' %}?lat="+e.latlng.lat+"&lng="+e.latlng.lng+"' role='button'>{% trans "Submit a Case Study" %}</a>")
.openOn(map); .openOn(map);
}); });
} }

View File

@ -10,5 +10,6 @@ urlpatterns = [
url(r'^case-study/create/?$', views.Create.as_view(), name="create"), url(r'^case-study/create/?$', views.Create.as_view(), name="create"),
url(r'^case-study/create/short/?$', views.ShortForm.as_view(), name='short-form'), url(r'^case-study/create/short/?$', views.ShortForm.as_view(), name='short-form'),
url(r'^case-study/create/long/?$', views.LongForm.as_view(), name='long-form'), url(r'^case-study/create/long/?$', views.LongForm.as_view(), name='long-form'),
url(r'^case-study/create/success/?$', views.FormSuccess.as_view(), name='form-success'),
url(r'^case-study/(?P<slug>[-\w]+)/?$', views.CaseStudyDetail.as_view(), name='detail') url(r'^case-study/(?P<slug>[-\w]+)/?$', views.CaseStudyDetail.as_view(), name='detail')
] ]

View File

@ -1,7 +1,8 @@
from django.views.generic import DetailView from django.views.generic import DetailView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView from django.views.generic.edit import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse
from .models import CaseStudy from .models import CaseStudy
from .forms import ShortCaseStudyForm, LongCaseStudyForm from .forms import ShortCaseStudyForm, LongCaseStudyForm
@ -14,21 +15,27 @@ class Create(LoginRequiredMixin, TemplateView):
template_name = "map/how_much_time.html" template_name = "map/how_much_time.html"
class BaseForm(LoginRequiredMixin, FormView): class BaseForm(LoginRequiredMixin, CreateView):
"""This is the base class for the short and long forms. It handles any shared logic between the two subclasses.""" """View for base case study form."""
template_name = 'map/form.html' template_name = 'map/form.html'
success_url = '/'
model = CaseStudy
class ShortForm(BaseForm): class ShortForm(BaseForm):
"""Here, we use the short version of the form.""" """View for short version of case study form."""
form_class = ShortCaseStudyForm form_class = ShortCaseStudyForm
class LongForm(BaseForm): class LongForm(BaseForm):
"""Here, we use the long version of the form.""" """View for long version of case study form."""
form_class = LongCaseStudyForm form_class = LongCaseStudyForm
class FormSuccess(TemplateView):
template_name = 'map/form-success.html'
class CaseStudyDetail(DetailView): class CaseStudyDetail(DetailView):
template_name = "map/detail.html" template_name = "map/detail.html"
model = CaseStudy model = CaseStudy

View File

@ -231,3 +231,7 @@ LEAFLET_CONFIG = {
} }
}, },
} }
# Moderation
# https://django-moderation.readthedocs.io/
MODERATION_MODERATORS = ('livvy@base.nu')