Converted wagtailsites to use viewsets

pull/3545/merge
Karl Hobley 2015-12-23 15:24:43 +00:00 zatwierdzone przez Matt Westcott
rodzic 022ff09e3f
commit f97536f14d
3 zmienionych plików z 26 dodań i 47 usunięć

Wyświetl plik

@ -1,12 +0,0 @@
from __future__ import absolute_import, unicode_literals
from django.conf.urls import url
from wagtail.wagtailsites import views
urlpatterns = [
url(r'^$', views.Index.as_view(), name='index'),
url(r'^add/$', views.Create.as_view(), name='add'),
url(r'^(\d+)/$', views.Edit.as_view(), name='edit'),
url(r'^(\d+)/delete/$', views.Delete.as_view(), name='delete'),
]

Wyświetl plik

@ -2,56 +2,49 @@ from __future__ import absolute_import, unicode_literals
from django.utils.translation import ugettext_lazy from django.utils.translation import ugettext_lazy
from wagtail.wagtailadmin.views.generic import CreateView, DeleteView, EditView, IndexView from wagtail.wagtailadmin.views import generic
from wagtail.wagtailadmin.viewsets.model import ModelViewSet
from wagtail.wagtailcore.models import Site from wagtail.wagtailcore.models import Site
from wagtail.wagtailcore.permissions import site_permission_policy from wagtail.wagtailcore.permissions import site_permission_policy
from wagtail.wagtailsites.forms import SiteForm from wagtail.wagtailsites.forms import SiteForm
class Index(IndexView): class IndexView(generic.IndexView):
permission_policy = site_permission_policy
model = Site
context_object_name = 'sites'
template_name = 'wagtailsites/index.html' template_name = 'wagtailsites/index.html'
add_url_name = 'wagtailsites:add'
page_title = ugettext_lazy("Sites") page_title = ugettext_lazy("Sites")
add_item_label = ugettext_lazy("Add a site") add_item_label = ugettext_lazy("Add a site")
header_icon = 'site' context_object_name = 'sites'
class Create(CreateView): class CreateView(generic.CreateView):
permission_policy = site_permission_policy
form_class = SiteForm
page_title = ugettext_lazy("Add site") page_title = ugettext_lazy("Add site")
success_message = ugettext_lazy("Site '{0}' created.") success_message = ugettext_lazy("Site '{0}' created.")
add_url_name = 'wagtailsites:add'
edit_url_name = 'wagtailsites:edit'
index_url_name = 'wagtailsites:index'
template_name = 'wagtailsites/create.html' template_name = 'wagtailsites/create.html'
header_icon = 'site'
class Edit(EditView): class EditView(generic.EditView):
permission_policy = site_permission_policy
model = Site
form_class = SiteForm
success_message = ugettext_lazy("Site '{0}' updated.") success_message = ugettext_lazy("Site '{0}' updated.")
error_message = ugettext_lazy("The site could not be saved due to errors.") error_message = ugettext_lazy("The site could not be saved due to errors.")
delete_item_label = ugettext_lazy("Delete site") delete_item_label = ugettext_lazy("Delete site")
edit_url_name = 'wagtailsites:edit'
index_url_name = 'wagtailsites:index'
delete_url_name = 'wagtailsites:delete'
context_object_name = 'site' context_object_name = 'site'
template_name = 'wagtailsites/edit.html' template_name = 'wagtailsites/edit.html'
header_icon = 'site'
class Delete(DeleteView): class DeleteView(generic.DeleteView):
permission_policy = site_permission_policy
model = Site
success_message = ugettext_lazy("Site '{0}' deleted.") success_message = ugettext_lazy("Site '{0}' deleted.")
index_url_name = 'wagtailsites:index'
delete_url_name = 'wagtailsites:delete'
page_title = ugettext_lazy("Delete site") page_title = ugettext_lazy("Delete site")
confirmation_message = ugettext_lazy("Are you sure you want to delete this site?") confirmation_message = ugettext_lazy("Are you sure you want to delete this site?")
header_icon = 'site'
class SiteViewSet(ModelViewSet):
icon = 'site'
model = Site
permission_policy = site_permission_policy
index_view_class = IndexView
add_view_class = CreateView
edit_view_class = EditView
delete_view_class = DeleteView
def get_form_class(self, for_update=False):
return SiteForm

Wyświetl plik

@ -1,6 +1,5 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from django.conf.urls import include, url
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.core import urlresolvers from django.core import urlresolvers
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -8,14 +7,13 @@ from django.utils.translation import ugettext_lazy as _
from wagtail.wagtailadmin.menu import MenuItem from wagtail.wagtailadmin.menu import MenuItem
from wagtail.wagtailcore import hooks from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.permissions import site_permission_policy from wagtail.wagtailcore.permissions import site_permission_policy
from wagtail.wagtailsites import urls
from .views import SiteViewSet
@hooks.register('register_admin_urls') @hooks.register('register_admin_viewset')
def register_admin_urls(): def register_viewset():
return [ return SiteViewSet('wagtailsites')
url(r'^sites/', include(urls, app_name='wagtailsites', namespace='wagtailsites')),
]
class SitesMenuItem(MenuItem): class SitesMenuItem(MenuItem):