kopia lustrzana https://github.com/wagtail/wagtail
Add submit date from/to filter for form submission
rodzic
016511eb85
commit
cf3883cb22
|
@ -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'}))
|
|
@ -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"),
|
||||
]
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
<script>
|
||||
window.overrideDateInputFormat ='{{ format_override }}';
|
||||
$(function() {
|
||||
if(window.overrideDateInputFormat && window.overrideDateInputFormat !='') {
|
||||
$('#id_date_from').datepicker({
|
||||
dateFormat: window.overrideDateInputFormat, constrainInput: false, /* showOn: 'button', */ firstDay: 1
|
||||
});
|
||||
$('#id_date_to').datepicker({
|
||||
dateFormat: window.overrideDateInputFormat, constrainInput: false, /* showOn: 'button', */ firstDay: 1
|
||||
});
|
||||
} else {
|
||||
$('#id_date_from').datepicker({
|
||||
constrainInput: false, /* showOn: 'button', */ firstDay: 1
|
||||
});
|
||||
$('#id_date_to').datepicker({
|
||||
constrainInput: false, /* showOn: 'button', */ firstDay: 1
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<header class="nice-padding">
|
||||
<div class="row row-flush">
|
||||
<div class="left col9">
|
||||
<div class="left col6">
|
||||
<h1>
|
||||
{% blocktrans with form_title=form_page.title|capfirst %}Submissions of <span>{{ form_title }}</span>{% endblocktrans %}
|
||||
</h1>
|
||||
</div>
|
||||
<div class="right col3">
|
||||
|
||||
</div>
|
||||
<form class="col" action="" method="get">
|
||||
<ul class="fields">
|
||||
{% for field in select_date_form %}
|
||||
<div class="right col3">
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class='col3'
|
||||
<li class="submit"><input type="submit" value="Filter" /></li>
|
||||
</div>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
</header>
|
||||
<div class="nice-padding">
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<table class="listing">
|
||||
<col />
|
||||
<col />
|
||||
<col width="16%" />
|
||||
<col width="75%" />
|
||||
<thead>
|
||||
<tr class="table-headers">
|
||||
<th>{% trans "Submission Date" %}</th>
|
||||
|
@ -20,7 +20,9 @@
|
|||
{{ submission.user }}
|
||||
</td>
|
||||
<td class="title">
|
||||
{{ submission.form_data }}
|
||||
{% for data in submission.get_data.items %}
|
||||
{{ data.0 }}: {{ data.1 }}{% if not forloop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue