diff --git a/wagtail/wagtailforms/forms.py b/wagtail/wagtailforms/forms.py index 6e938822d6..2543bc3cd3 100644 --- a/wagtail/wagtailforms/forms.py +++ b/wagtail/wagtailforms/forms.py @@ -65,3 +65,6 @@ class FormBuilder(): def get_form_class(self): return type('WagtailForm', (django.forms.Form,), self.formfields ) +class SelectDateForm(django.forms.Form): + date_from = django.forms.DateField(required=False, widget=django.forms.DateInput(attrs={'placeholder':'Date from'})) + date_to = django.forms.DateField(required=False, widget=django.forms.DateInput(attrs={'placeholder':'Date to'})) \ No newline at end of file diff --git a/wagtail/wagtailforms/models.py b/wagtail/wagtailforms/models.py index f64f56df7c..1849801e94 100644 --- a/wagtail/wagtailforms/models.py +++ b/wagtail/wagtailforms/models.py @@ -41,7 +41,10 @@ class FormSubmission(models.Model): form_page = models.ForeignKey('wagtailcore.Page',related_name='+') submit_time = models.DateTimeField(auto_now_add=True) user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True) - + + def get_data(self): + return json.loads(self.form_data) + def __unicode__(self): return self.form_data @@ -183,7 +186,8 @@ class ConcreteEmailForm(AbstractEmailForm): ConcreteEmailForm.content_panels = [ FieldPanel('title', classname="full title"), FieldPanel('thank_you', classname="full"), - FieldPanel('email_from', classname="full"), - FieldPanel('email_to', classname="full"), + FieldPanel('to_address', classname="full"), + FieldPanel('from_address', classname="full"), + FieldPanel('subject', classname="full"), InlinePanel(ConcreteEmailForm, 'form_fields', label="Form Fields"), ] diff --git a/wagtail/wagtailforms/templates/wagtailforms/form_index.html b/wagtail/wagtailforms/templates/wagtailforms/form_index.html index ebeac81536..51d4ad03eb 100644 --- a/wagtail/wagtailforms/templates/wagtailforms/form_index.html +++ b/wagtail/wagtailforms/templates/wagtailforms/form_index.html @@ -1,18 +1,56 @@ {% extends "wagtailadmin/base.html" %} {% load i18n %} +{% load localize %} {% block titletag %}{% blocktrans with form_title=form_page.title|capfirst %}Submissions of {{ form_title }}{% endblocktrans %}{% endblock %} {% block bodyclass %}menu-snippets{% endblock %} +{% block extra_js %} + {% get_localized_datepicker_js %} + {% get_date_format_override as format_override %} + + +{% endblock %} {% block content %}
-
+

{% blocktrans with form_title=form_page.title|capfirst %}Submissions of {{ form_title }}{% endblocktrans %} +

-
- -
+
+
    + {% for field in select_date_form %} +
    + {% include "wagtailadmin/shared/field_as_li.html" with field=field %} +
    + {% endfor %} +
    +
    +
+
+ +
diff --git a/wagtail/wagtailforms/templates/wagtailforms/list.html b/wagtail/wagtailforms/templates/wagtailforms/list.html index 243846615d..86f65f2570 100644 --- a/wagtail/wagtailforms/templates/wagtailforms/list.html +++ b/wagtail/wagtailforms/templates/wagtailforms/list.html @@ -2,7 +2,7 @@ - + @@ -20,7 +20,9 @@ {{ submission.user }} {% endfor %} diff --git a/wagtail/wagtailforms/views.py b/wagtail/wagtailforms/views.py index 3146f457c9..a325f17c0e 100644 --- a/wagtail/wagtailforms/views.py +++ b/wagtail/wagtailforms/views.py @@ -1,3 +1,5 @@ +import datetime + from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.http import Http404 from django.shortcuts import get_object_or_404, render, redirect @@ -9,7 +11,7 @@ from django.utils.translation import ugettext as _ from wagtail.wagtailcore.models import Page from wagtail.wagtailforms.models import FormSubmission, get_form_types - +from wagtail.wagtailforms.forms import SelectDateForm def get_form_type_from_url_params(app_name, model_name): """ @@ -42,10 +44,23 @@ def list_submissions(request, app_label, model, id): form_page = get_object_or_404(model, id=id) submissions = FormSubmission.objects.filter(form_page=form_page) - + select_date_form = SelectDateForm(request.GET) + if select_date_form.is_valid(): + date_from = select_date_form.cleaned_data.get('date_from') + date_to = select_date_form.cleaned_data.get('date_to') + # careful: date_to should be increased by 1 day since the submit_time + # is a time so it will always be greater + date_to += datetime.timedelta(days=1) + if date_from and date_to: + submissions=submissions.filter(submit_time__range=[date_from, date_to] ) + elif date_from and not date_to: + submissions=submissions.filter(submit_time__gte=date_from) + elif not date_from and date_to: + submissions=submissions.filter(submit_time__lte=date_to) + p = request.GET.get('p', 1) paginator = Paginator(submissions, 20) - + try: submissions = paginator.page(p) except PageNotAnInteger: @@ -53,9 +68,9 @@ def list_submissions(request, app_label, model, id): except EmptyPage: submissions = paginator.page(paginator.num_pages) - return render(request, 'wagtailforms/form_index.html', { 'form_page': form_page, + 'select_date_form': select_date_form, 'submissions': submissions, })
{% trans "Submission Date" %} - {{ submission.form_data }} + {% for data in submission.get_data.items %} + {{ data.0 }}: {{ data.1 }}{% if not forloop.last %}, {% endif %} + {% endfor %}