kopia lustrzana https://github.com/wagtail/wagtail
Converted wagtailsites to use viewsets
rodzic
022ff09e3f
commit
f97536f14d
|
@ -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'),
|
||||
]
|
|
@ -2,56 +2,49 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
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.permissions import site_permission_policy
|
||||
from wagtail.wagtailsites.forms import SiteForm
|
||||
|
||||
|
||||
class Index(IndexView):
|
||||
permission_policy = site_permission_policy
|
||||
model = Site
|
||||
context_object_name = 'sites'
|
||||
class IndexView(generic.IndexView):
|
||||
template_name = 'wagtailsites/index.html'
|
||||
add_url_name = 'wagtailsites:add'
|
||||
page_title = ugettext_lazy("Sites")
|
||||
add_item_label = ugettext_lazy("Add a site")
|
||||
header_icon = 'site'
|
||||
context_object_name = 'sites'
|
||||
|
||||
|
||||
class Create(CreateView):
|
||||
permission_policy = site_permission_policy
|
||||
form_class = SiteForm
|
||||
class CreateView(generic.CreateView):
|
||||
page_title = ugettext_lazy("Add site")
|
||||
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'
|
||||
header_icon = 'site'
|
||||
|
||||
|
||||
class Edit(EditView):
|
||||
permission_policy = site_permission_policy
|
||||
model = Site
|
||||
form_class = SiteForm
|
||||
class EditView(generic.EditView):
|
||||
success_message = ugettext_lazy("Site '{0}' updated.")
|
||||
error_message = ugettext_lazy("The site could not be saved due to errors.")
|
||||
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'
|
||||
template_name = 'wagtailsites/edit.html'
|
||||
header_icon = 'site'
|
||||
|
||||
|
||||
class Delete(DeleteView):
|
||||
permission_policy = site_permission_policy
|
||||
model = Site
|
||||
class DeleteView(generic.DeleteView):
|
||||
success_message = ugettext_lazy("Site '{0}' deleted.")
|
||||
index_url_name = 'wagtailsites:index'
|
||||
delete_url_name = 'wagtailsites:delete'
|
||||
page_title = ugettext_lazy("Delete 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
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.core import urlresolvers
|
||||
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.wagtailcore import hooks
|
||||
from wagtail.wagtailcore.permissions import site_permission_policy
|
||||
from wagtail.wagtailsites import urls
|
||||
|
||||
from .views import SiteViewSet
|
||||
|
||||
|
||||
@hooks.register('register_admin_urls')
|
||||
def register_admin_urls():
|
||||
return [
|
||||
url(r'^sites/', include(urls, app_name='wagtailsites', namespace='wagtailsites')),
|
||||
]
|
||||
@hooks.register('register_admin_viewset')
|
||||
def register_viewset():
|
||||
return SiteViewSet('wagtailsites')
|
||||
|
||||
|
||||
class SitesMenuItem(MenuItem):
|
||||
|
|
Ładowanie…
Reference in New Issue