0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Merge pull request #51 from jacobtoppm/author-locking-ui

Author locking ui
This commit is contained in:
Karl Hobley 2019-11-04 10:17:20 +00:00 committed by GitHub
commit d5f945186a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 124 additions and 50 deletions

View File

@ -74,6 +74,18 @@
.errorlist {
margin: 0.5em 0 0 1em;
}
.lock {
&:before {
content: map-get($icons, 'locked');
}
}
.unlock {
&:before {
content: map-get($icons, 'unlocked');
}
}
}
.messages.new > ul {

View File

@ -88,7 +88,6 @@ class Menu:
rendered_menu_items = []
for item in sorted(menu_items, key=lambda i: i.order):
rendered_menu_items.append(item.render_html(request))
return mark_safe(''.join(rendered_menu_items))
@ -116,3 +115,4 @@ class SubmenuMenuItem(MenuItem):
admin_menu = Menu(register_hook_name='register_admin_menu_item', construct_hook_name='construct_main_menu')
settings_menu = Menu(register_hook_name='register_settings_menu_item', construct_hook_name='construct_settings_menu')
reports_menu = Menu(register_hook_name='register_reports_menu_item', construct_hook_name='construct_reports_menu')

View File

@ -12,24 +12,24 @@ def render(message, buttons, detail=''):
})
def debug(request, message, buttons=None):
return messages.debug(request, render(message, buttons))
def debug(request, message, buttons=None, extra_tags=''):
return messages.debug(request, render(message, buttons), extra_tags=extra_tags)
def info(request, message, buttons=None):
return messages.info(request, render(message, buttons))
def info(request, message, buttons=None, extra_tags=''):
return messages.info(request, render(message, buttons), extra_tags=extra_tags)
def success(request, message, buttons=None):
return messages.success(request, render(message, buttons))
def success(request, message, buttons=None, extra_tags=''):
return messages.success(request, render(message, buttons), extra_tags=extra_tags)
def warning(request, message, buttons=None):
return messages.warning(request, render(message, buttons))
def warning(request, message, buttons=None, extra_tags=''):
return messages.warning(request, render(message, buttons), extra_tags=extra_tags)
def error(request, message, buttons=None):
return messages.error(request, render(message, buttons))
def error(request, message, buttons=None, extra_tags=''):
return messages.error(request, render(message, buttons), extra_tags=extra_tags)
def validation_error(request, message, form, buttons=None):

View File

@ -3,6 +3,7 @@
<div class="panel nice-padding">{# TODO try moving these classes onto the section tag #}
<section>
<h2>{% trans "Your locked pages" %}</h2>
<a href="{% url 'wagtailadmin_reports:locked_pages' %}" class="button button-small button-secondary">{% trans "See all locked pages" %}</a>
<table class="listing listing-page">
<col />
<col width="15%"/>

View File

@ -1,12 +0,0 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% block titletag %}{% trans "Locked pages" %}{% endblock %}
{% block content %}
{% trans "Locked pages" as title %}
{% include "wagtailadmin/shared/header.html" with title=title icon="doc-empty-inverse" %}
<div id="page-results">
{% include "wagtailadmin/pages/locked_pages_results.html" %}
</div>
{% endblock %}

View File

@ -1,11 +0,0 @@
{% load i18n wagtailadmin_tags %}
<div class="nice-padding">
{% if pages %}
{% include "wagtailadmin/pages/listing/_list_unlock.html" %}
{% url 'wagtailadmin_pages:locked_pages' as pagination_base_url %}
{% paginate pages base_url=pagination_base_url %}
{% else %}
<p>{% trans 'No pages have been locked.' %}</p>
{% endif %}
</div>

View File

@ -0,0 +1,24 @@
{% extends "wagtailadmin/base.html" %}
{% load i18n wagtailadmin_tags %}
{% block titletag %}{{ title }}{% endblock %}
{% block content %}
{% include "wagtailadmin/shared/header.html" with title=title icon=header_icon %}
{% with page_obj as pages %}
<div id="page-results">
<div class="nice-padding">
{% if pages %}
{% block listing %}
{% include "wagtailadmin/pages/listing/_list_explore.html" %}
{% endblock %}
{% paginate pages base_url=request.path %}
{% else %}
{% block no_results %}
<p>{% trans "No pages match this report's criteria." %}</p>
{% endblock %}
{% endif %}
</div>
</div>
{% endwith %}
{% endblock %}

View File

@ -0,0 +1,9 @@
{% extends 'wagtailadmin/reports/base_report.html' %}
{% load i18n %}
{% block listing %}
{% include "wagtailadmin/reports/listing/_list_unlock.html" %}
{% endblock %}
{% block no_results %}
<p>{% trans "No locked pages found." %}</p>
{% endblock %}

View File

@ -9,6 +9,7 @@ from django.views.defaults import page_not_found
from wagtail.admin.auth import require_admin_access
from wagtail.admin.urls import pages as wagtailadmin_pages_urls
from wagtail.admin.urls import collections as wagtailadmin_collections_urls
from wagtail.admin.urls import reports as wagtailadmin_reports_urls
from wagtail.admin.urls import password_reset as wagtailadmin_password_reset_urls
from wagtail.admin.views import account, chooser, home, pages, tags, userbar
from wagtail.admin.api import urls as api_urls
@ -44,6 +45,8 @@ urlpatterns = [
url(r'^collections/', include(wagtailadmin_collections_urls, namespace='wagtailadmin_collections')),
url(r'^reports/', include(wagtailadmin_reports_urls, namespace='wagtailadmin_reports')),
url(r'^account/$', account.account, name='wagtailadmin_account'),
url(r'^account/change_password/$', account.change_password, name='wagtailadmin_account_change_password'),
url(r'^account/change_email/$', account.change_email, name='wagtailadmin_account_change_email'),

View File

@ -33,7 +33,6 @@ urlpatterns = [
url(r'^(\d+)/lock/$', pages.lock, name='lock'),
url(r'^(\d+)/unlock/$', pages.unlock, name='unlock'),
url(r'^locked/$', pages.locked_pages, name='locked_pages'),
url(r'^(\d+)/revisions/$', pages.revisions_index, name='revisions_index'),
url(r'^(\d+)/revisions/(\d+)/view/$', pages.revisions_view, name='revisions_view'),

View File

@ -0,0 +1,8 @@
from django.conf.urls import url
from wagtail.admin.views import reports
app_name = 'wagtailadmin_reports'
urlpatterns = [
url(r'^locked/$', reports.LockedPagesView.as_view(), name='locked_pages')
]

View File

@ -11,6 +11,7 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import timezone
from django.utils.html import format_html
from django.utils.http import is_safe_url, urlquote
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
@ -345,6 +346,14 @@ def edit(request, page_id):
user_has_lock = page.locked_by_id == request.user.id
page_locked = page_perms.page_locked()
if user_has_lock:
messages.warning(request, format_html(_("<b>Page '{}' was locked</b> by <b>you</b> on <b>{}</b>."), page.get_admin_display_title(), page.locked_at.strftime("%d %b %Y %H:%M")), extra_tags='lock')
if page_locked:
locked_by_message = ""
if page.locked_by:
locked_by_message = format_html(" by <b>{}</b>", str(page.locked_by))
messages.error(request, format_html(_("<b>Page '{}' was locked</b>{} on <b>{}</b>."), page.get_admin_display_title(), locked_by_message, page.locked_at.strftime("%d %b %Y %H:%M")), extra_tags='lock')
next_url = get_valid_next_url_from_request(request)
errors_debug = None
@ -1080,8 +1089,6 @@ def lock(request, page_id):
page.locked_at = timezone.now()
page.save()
messages.success(request, _("Page '{0}' is now locked.").format(page.get_admin_display_title()))
# Redirect
redirect_to = request.POST.get('next', None)
if redirect_to and is_safe_url(url=redirect_to, allowed_hosts={request.get_host()}):
@ -1106,7 +1113,7 @@ def unlock(request, page_id):
page.locked_at = None
page.save()
messages.success(request, _("Page '{0}' is now unlocked.").format(page.get_admin_display_title()))
messages.success(request, _("Page '{0}' is now unlocked.").format(page.get_admin_display_title()), extra_tags='unlock')
# Redirect
redirect_to = request.POST.get('next', None)
@ -1278,14 +1285,3 @@ def revisions_unschedule(request, page_id, revision_id):
'next': next_url,
'subtitle': subtitle
})
def locked_pages(request):
pages = UserPagePermissionsProxy(request.user).editable_pages().filter(locked=True)
paginator = Paginator(pages, per_page=10)
pages = paginator.get_page(request.GET.get('p'))
return render(request, 'wagtailadmin/pages/locked_pages.html', {
'pages': pages,
})

View File

@ -0,0 +1,30 @@
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateResponseMixin
from django.views.generic.list import BaseListView
from wagtail.core.models import UserPagePermissionsProxy
class ReportView(TemplateResponseMixin, BaseListView):
header_icon = ''
page_kwarg = 'p'
template_name = None
title = ''
paginate_by = 10
def get_context_data(self, *args, object_list=None, **kwargs):
context = super().get_context_data(*args, object_list=object_list, **kwargs)
context['title'] = self.title
context['header_icon'] = self.header_icon
return context
class LockedPagesView(ReportView):
template_name = 'wagtailadmin/reports/locked_pages.html'
title = _('Locked Pages')
header_icon = 'locked'
def get_queryset(self):
pages = UserPagePermissionsProxy(self.request.user).editable_pages().filter(locked=True)
self.queryset = pages
return super().get_queryset()

View File

@ -7,7 +7,7 @@ from draftjs_exporter.dom import DOM
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
from wagtail.admin.auth import user_has_any_page_permission
from wagtail.admin.locale import get_available_admin_languages, get_available_admin_time_zones
from wagtail.admin.menu import MenuItem, SubmenuMenuItem, settings_menu
from wagtail.admin.menu import MenuItem, SubmenuMenuItem, reports_menu, settings_menu
from wagtail.admin.navigation import get_explorable_root_page
from wagtail.admin.rich_text import (
HalloFormatPlugin, HalloHeadingPlugin, HalloListPlugin, HalloPlugin)
@ -614,3 +614,18 @@ def register_core_features(features):
'style_map': {'CODE': 'code'}
}
})
class ReportsMenuItem(SubmenuMenuItem):
template = 'wagtailadmin/shared/menu_submenu_item.html'
@hooks.register('register_reports_menu_item')
def register_locked_pages_menu_item():
return MenuItem(_('Locked Pages'), reverse('wagtailadmin_reports:locked_pages'), classnames='icon icon-locked', order=700)
@hooks.register('register_admin_menu_item')
def register_reports_menu():
return ReportsMenuItem(
_('Reports'), reports_menu, classnames='icon icon-site', order=9000)