mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
Add a basic views skeleton for wagtailforms
This commit is contained in:
parent
3855da21bf
commit
49a1ef3079
3 changed files with 162 additions and 0 deletions
23
wagtail/wagtailforms/templates/wagtailforms/index.html
Normal file
23
wagtail/wagtailforms/templates/wagtailforms/index.html
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{% extends "wagtailadmin/base.html" %}
|
||||
{% load i18n %}
|
||||
{% block titletag %}{% trans "Forms" %}{% endblock %}
|
||||
{% block bodyclass %}menu-forms{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
{% include "wagtailadmin/shared/header.html" with title="Forms" %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<ul class="listing">
|
||||
{% for name, description, content_type in form_types %}
|
||||
<li>
|
||||
<div class="row row-flush">
|
||||
<a href="{% url 'wagtailsnippets_list' content_type.app_label content_type.model %}" class="col6">
|
||||
{{ name|capfirst }}
|
||||
</a>
|
||||
<small class="col6">{{ description }}</small>
|
||||
</div>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endblock %}
|
||||
14
wagtail/wagtailforms/urls.py
Normal file
14
wagtail/wagtailforms/urls.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
'wagtail.wagtailforms.views',
|
||||
url(r'^$', 'index', name='wagtailforms_index'),
|
||||
|
||||
#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'),
|
||||
)
|
||||
125
wagtail/wagtailforms/views.py
Normal file
125
wagtail/wagtailforms/views.py
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
from django.http import Http404
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.text import capfirst
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
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
|
||||
|
||||
|
||||
@permission_required('wagtailadmin.access_admin')
|
||||
def index(request):
|
||||
|
||||
|
||||
return render(request, 'wagtailforms/index.html', {
|
||||
#'snippet_types': snippet_types,
|
||||
})
|
||||
|
||||
"""
|
||||
@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):
|
||||
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 = get_snippet_type_name(content_type)[0]
|
||||
|
||||
instance = model()
|
||||
edit_handler_class = get_snippet_edit_handler(model)
|
||||
form_class = edit_handler_class.get_form_class(model)
|
||||
|
||||
if request.POST:
|
||||
form = form_class(request.POST, request.FILES, instance=instance)
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
|
||||
messages.success(
|
||||
request,
|
||||
_("{snippet_type} '{instance}' created.").format(
|
||||
snippet_type=capfirst(get_snippet_type_name(content_type)[0]),
|
||||
instance=instance
|
||||
)
|
||||
)
|
||||
return redirect('wagtailsnippets_list', content_type.app_label, content_type.model)
|
||||
else:
|
||||
messages.error(request, _("The snippet could not be created due to errors."))
|
||||
edit_handler = edit_handler_class(instance=instance, form=form)
|
||||
else:
|
||||
form = form_class(instance=instance)
|
||||
edit_handler = edit_handler_class(instance=instance, form=form)
|
||||
|
||||
return render(request, 'wagtailsnippets/snippets/create.html', {
|
||||
'content_type': content_type,
|
||||
'snippet_type_name': snippet_type_name,
|
||||
'edit_handler': edit_handler,
|
||||
})
|
||||
|
||||
|
||||
@permission_required('wagtailadmin.access_admin') # further permissions are enforced within the view
|
||||
def edit(request, content_type_app_name, content_type_model_name, id):
|
||||
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 = get_snippet_type_name(content_type)[0]
|
||||
|
||||
instance = get_object_or_404(model, id=id)
|
||||
edit_handler_class = get_snippet_edit_handler(model)
|
||||
form_class = edit_handler_class.get_form_class(model)
|
||||
|
||||
if request.POST:
|
||||
form = form_class(request.POST, request.FILES, instance=instance)
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
|
||||
messages.success(
|
||||
request,
|
||||
_("{snippet_type} '{instance}' updated.").format(
|
||||
snippet_type=capfirst(snippet_type_name),
|
||||
instance=instance
|
||||
)
|
||||
)
|
||||
return redirect('wagtailsnippets_list', content_type.app_label, content_type.model)
|
||||
else:
|
||||
messages.error(request, _("The snippet could not be saved due to errors."))
|
||||
edit_handler = edit_handler_class(instance=instance, form=form)
|
||||
else:
|
||||
form = form_class(instance=instance)
|
||||
edit_handler = edit_handler_class(instance=instance, form=form)
|
||||
|
||||
return render(request, 'wagtailsnippets/snippets/edit.html', {
|
||||
'content_type': content_type,
|
||||
'snippet_type_name': snippet_type_name,
|
||||
'instance': instance,
|
||||
'edit_handler': edit_handler,
|
||||
})
|
||||
|
||||
|
||||
"""
|
||||
Loading…
Reference in a new issue