diff --git a/apps/map/forms.py b/apps/map/forms.py index 977c3aa..9af63f7 100644 --- a/apps/map/forms.py +++ b/apps/map/forms.py @@ -1,4 +1,5 @@ from django import forms +from django.urls import reverse from crispy_forms.helper import FormHelper from crispy_forms.layout import Submit from leaflet.forms.widgets import LeafletWidget @@ -7,7 +8,7 @@ from .models import CaseStudy class BaseCaseStudyForm(forms.ModelForm): - + """Base form class for the CaseStudy model.""" def __init__(self, *args, **kwargs): super(BaseCaseStudyForm, self).__init__(*args, **kwargs) self.helper = FormHelper() @@ -26,6 +27,12 @@ class BaseCaseStudyForm(forms.ModelForm): 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): fields = [ 'entry_name', @@ -50,5 +57,10 @@ class ShortCaseStudyForm(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): fields = '__all__' diff --git a/apps/map/templates/map/form-success.html b/apps/map/templates/map/form-success.html new file mode 100644 index 0000000..13b0143 --- /dev/null +++ b/apps/map/templates/map/form-success.html @@ -0,0 +1,35 @@ +{% extends "base_page.html" %} +{% load bootstrap3 %} +{% load compress %} +{% load i18n %} +{% load humanize %} + +{% block stylesheets %} +{{ block.super }} + +{% endblock %} + +{% block title %}{% trans "Thanks!" %}{% endblock %} +{% block inner %} +

{% trans "Your submission will be reviewed shortly. We will update you via email." %}

+{% endblock %} \ No newline at end of file diff --git a/apps/map/templates/map/index.html b/apps/map/templates/map/index.html index 8a29c75..34d8339 100644 --- a/apps/map/templates/map/index.html +++ b/apps/map/templates/map/index.html @@ -104,7 +104,7 @@ map.on('click', function(e) { var popup = L.popup() .setLatLng(e.latlng) - .setContent("{% trans "Submit a Case Study" %}") + .setContent("{% trans "Submit a Case Study" %}") .openOn(map); }); } diff --git a/apps/map/urls.py b/apps/map/urls.py index 688bca4..6761d76 100644 --- a/apps/map/urls.py +++ b/apps/map/urls.py @@ -10,5 +10,6 @@ urlpatterns = [ 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/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[-\w]+)/?$', views.CaseStudyDetail.as_view(), name='detail') ] diff --git a/apps/map/views.py b/apps/map/views.py index a670e5d..358c129 100644 --- a/apps/map/views.py +++ b/apps/map/views.py @@ -1,7 +1,8 @@ from django.views.generic import DetailView 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.urls import reverse from .models import CaseStudy from .forms import ShortCaseStudyForm, LongCaseStudyForm @@ -14,21 +15,27 @@ class Create(LoginRequiredMixin, TemplateView): template_name = "map/how_much_time.html" -class BaseForm(LoginRequiredMixin, FormView): - """This is the base class for the short and long forms. It handles any shared logic between the two subclasses.""" +class BaseForm(LoginRequiredMixin, CreateView): + """View for base case study form.""" template_name = 'map/form.html' + success_url = '/' + model = CaseStudy class ShortForm(BaseForm): - """Here, we use the short version of the form.""" + """View for short version of case study form.""" form_class = ShortCaseStudyForm class LongForm(BaseForm): - """Here, we use the long version of the form.""" + """View for long version of case study form.""" form_class = LongCaseStudyForm +class FormSuccess(TemplateView): + template_name = 'map/form-success.html' + + class CaseStudyDetail(DetailView): template_name = "map/detail.html" model = CaseStudy diff --git a/ojusomap/settings.py b/ojusomap/settings.py index fc12f4b..842ceac 100644 --- a/ojusomap/settings.py +++ b/ojusomap/settings.py @@ -231,3 +231,7 @@ LEAFLET_CONFIG = { } }, } + +# Moderation +# https://django-moderation.readthedocs.io/ +MODERATION_MODERATORS = ('livvy@base.nu') \ No newline at end of file