mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
Add basic form submission views
Add two urls: index which lists all different forms that have been defined and submissions which for a specific form will list all its submissions. The index lists each Page seperately (so if we have two different instances of a form they will be listed seperately here), so the submissions view will need the app_label, model_name and id to find out all the submissions of a specific page.
This commit is contained in:
parent
49a1ef3079
commit
e3cb37ca72
5 changed files with 95 additions and 32 deletions
25
wagtail/wagtailforms/templates/wagtailforms/form_index.html
Normal file
25
wagtail/wagtailforms/templates/wagtailforms/form_index.html
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{% extends "wagtailadmin/base.html" %}
|
||||
{% load i18n %}
|
||||
{% block titletag %}{% blocktrans with form_title=form_page.title|capfirst %}Submissions of {{ form_title }}{% endblocktrans %}{% endblock %}
|
||||
{% block bodyclass %}menu-snippets{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
<header class="nice-padding">
|
||||
<div class="row row-flush">
|
||||
<div class="left col9">
|
||||
<h1>
|
||||
{% blocktrans with form_title=form_page.title|capfirst %}Submissions of <span>{{ form_title }}</span>{% endblocktrans %}
|
||||
</div>
|
||||
<div class="right col3">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="nice-padding">
|
||||
{% if submissions %}
|
||||
{% include "wagtailforms/list.html" %}
|
||||
{% else %}
|
||||
<p class="no-results-message">{% blocktrans with title=form_page.title %}No submissions of the '{{ title }}' form.{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -3,18 +3,20 @@
|
|||
{% block titletag %}{% trans "Forms" %}{% endblock %}
|
||||
{% block bodyclass %}menu-forms{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% include "wagtailadmin/shared/header.html" with title="Forms" %}
|
||||
{% trans "Forms" as forms_str %}
|
||||
{% trans "Please select a form to view its submissions" as select_form_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=forms_str subtitle=select_form_str %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<ul class="listing">
|
||||
{% for name, description, content_type in form_types %}
|
||||
{% for fp in form_pages %}
|
||||
<li>
|
||||
<div class="row row-flush">
|
||||
<a href="{% url 'wagtailsnippets_list' content_type.app_label content_type.model %}" class="col6">
|
||||
{{ name|capfirst }}
|
||||
<a href="{% url 'wagtailforms_list_submissions' fp.content_type.app_label fp.content_type.model fp.id %}" class="col6">
|
||||
{{ fp|capfirst }}
|
||||
</a>
|
||||
<small class="col6">{{ description }}</small>
|
||||
|
||||
<small class="col6">{{ fp.content_type.name |capfirst }} ({{ fp.content_type.app_label }}.{{ fp.content_type.model }})</small>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
|
|||
28
wagtail/wagtailforms/templates/wagtailforms/list.html
Normal file
28
wagtail/wagtailforms/templates/wagtailforms/list.html
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{% load i18n %}
|
||||
<table class="listing">
|
||||
<col />
|
||||
<col />
|
||||
<col width="16%" />
|
||||
<thead>
|
||||
<tr class="table-headers">
|
||||
<th>{% trans "Submission Date" %}</th>
|
||||
<th>{% trans "User" %}</th>
|
||||
<th>{% trans "Data" %}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for submission in submissions %}
|
||||
<tr>
|
||||
<td class="title">
|
||||
{{ submission.submit_time }}
|
||||
</td>
|
||||
<td class="title">
|
||||
{{ submission.user }}
|
||||
</td>
|
||||
<td class="title">
|
||||
{{ submission.form_data }}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -4,11 +4,6 @@ from django.conf.urls import patterns, url
|
|||
urlpatterns = patterns(
|
||||
'wagtail.wagtailforms.views',
|
||||
url(r'^$', 'index', name='wagtailforms_index'),
|
||||
url(r'^submissions/(\w+)/(\w+)/(\d+)/$', 'list_submissions', name='wagtailforms_list_submissions'),
|
||||
|
||||
#url(r'^choose/$', 'chooser.choose', name='wagtailsnippets_choose_generic'),
|
||||
#url(r'^choose/(\w+)/(\w+)/$', 'chooser.choose', name='wagtailsnippets_choose'),
|
||||
|
||||
#url(r'^(\w+)/(\w+)/$', 'snippets.list', name='wagtailsnippets_list'),
|
||||
#url(r'^(\w+)/(\w+)/new/$', 'snippets.create', name='wagtailsnippets_create'),
|
||||
#url(r'^(\w+)/(\w+)/(\d+)/$', 'snippets.edit', name='wagtailsnippets_edit'),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,35 +9,48 @@ from django.core.exceptions import PermissionDenied
|
|||
from django.utils.translation import ugettext as _
|
||||
|
||||
from wagtail.wagtailadmin.edit_handlers import ObjectList, extract_panel_definitions_from_model_class
|
||||
from wagtail.wagtailcore.models import Page
|
||||
from wagtail.wagtailforms.models import FormSubmission, get_form_types
|
||||
|
||||
|
||||
def get_form_type_from_url_params(app_name, model_name):
|
||||
"""
|
||||
Retrieve a form type from an app_name / model_name combo.
|
||||
Throw Http404 if not a valid form type
|
||||
"""
|
||||
try:
|
||||
content_type = ContentType.objects.get_by_natural_key(app_name, model_name)
|
||||
except ContentType.DoesNotExist:
|
||||
raise Http404
|
||||
if content_type not in get_form_types():
|
||||
raise Http404
|
||||
|
||||
return content_type
|
||||
|
||||
|
||||
@permission_required('wagtailadmin.access_admin')
|
||||
def index(request):
|
||||
|
||||
form_types = get_form_types()
|
||||
form_pages = Page.objects.filter(content_type__in=form_types)
|
||||
|
||||
return render(request, 'wagtailforms/index.html', {
|
||||
#'snippet_types': snippet_types,
|
||||
'form_pages': form_pages,
|
||||
})
|
||||
|
||||
@permission_required('wagtailadmin.access_admin')
|
||||
def list_submissions(request, app_label, model, id):
|
||||
|
||||
model = get_form_type_from_url_params(app_label, model).model_class()
|
||||
form_page = get_object_or_404(model, id=id)
|
||||
|
||||
submissions = FormSubmission.objects.filter(form_page=form_page)
|
||||
|
||||
return render(request, 'wagtailforms/form_index.html', {
|
||||
'form_page': form_page,
|
||||
'submissions': submissions,
|
||||
})
|
||||
|
||||
"""
|
||||
@permission_required('wagtailadmin.access_admin') # further permissions are enforced within the view
|
||||
def list(request, content_type_app_name, content_type_model_name):
|
||||
content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
|
||||
if not user_can_edit_snippet_type(request.user, content_type):
|
||||
raise PermissionDenied
|
||||
|
||||
model = content_type.model_class()
|
||||
snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)
|
||||
|
||||
items = model.objects.all()
|
||||
|
||||
return render(request, 'wagtailsnippets/snippets/type_index.html', {
|
||||
'content_type': content_type,
|
||||
'snippet_type_name': snippet_type_name,
|
||||
'snippet_type_name_plural': snippet_type_name_plural,
|
||||
'items': items,
|
||||
})
|
||||
|
||||
|
||||
@permission_required('wagtailadmin.access_admin') # further permissions are enforced within the view
|
||||
def create(request, content_type_app_name, content_type_model_name):
|
||||
|
|
|
|||
Loading…
Reference in a new issue