148 lines
6.6 KiB
Python
148 lines
6.6 KiB
Python
# w.c.s. - web application for online forms
|
|
# Copyright (C) 2005-2019 Entr'ouvert
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from quixote import get_publisher, get_request
|
|
from quixote.directory import Directory
|
|
|
|
from wcs.admin.logged_errors import LoggedErrorsDirectory
|
|
from wcs.backoffice.deprecations import DeprecationsDirectory
|
|
from wcs.backoffice.pagination import pagination_links
|
|
from wcs.blocks import BlockDef
|
|
from wcs.carddef import CardDef
|
|
from wcs.comment_templates import CommentTemplate
|
|
from wcs.data_sources import NamedDataSource
|
|
from wcs.formdef import FormDef
|
|
from wcs.mail_templates import MailTemplate
|
|
from wcs.qommon import _, misc, pgettext, template
|
|
from wcs.qommon.form import get_response
|
|
from wcs.workflows import Workflow
|
|
from wcs.wscalls import NamedWsCall
|
|
|
|
|
|
class ChangesDirectory(Directory):
|
|
_q_exports = ['']
|
|
|
|
def _q_index(self):
|
|
get_response().breadcrumb.append(('all-changes/', pgettext('studio', 'All changes')))
|
|
get_response().set_title(pgettext('studio', 'All Changes'))
|
|
limit = misc.get_int_or_400(
|
|
get_request().form.get('limit', get_publisher().get_site_option('default-page-size')) or 20
|
|
)
|
|
offset = misc.get_int_or_400(get_request().form.get('offset', 0))
|
|
|
|
backoffice_root = get_publisher().get_backoffice_root()
|
|
object_types = []
|
|
if backoffice_root.is_accessible('workflows'):
|
|
object_types += [Workflow, MailTemplate, CommentTemplate]
|
|
if backoffice_root.is_accessible('forms'):
|
|
object_types += [NamedDataSource, BlockDef, FormDef]
|
|
if backoffice_root.is_accessible('workflows'):
|
|
object_types += [NamedDataSource]
|
|
if backoffice_root.is_accessible('settings'):
|
|
object_types += [NamedDataSource, NamedWsCall]
|
|
if backoffice_root.is_accessible('cards'):
|
|
object_types += [CardDef]
|
|
object_types = [ot.xml_root_node for ot in object_types]
|
|
|
|
objects = []
|
|
links = ''
|
|
if get_publisher().snapshot_class:
|
|
objects = get_publisher().snapshot_class.get_recent_changes(
|
|
object_types=object_types, limit=limit, offset=offset
|
|
)
|
|
total_count = get_publisher().snapshot_class.count_recent_changes(object_types=object_types)
|
|
links = pagination_links(offset, limit, total_count, load_js=False)
|
|
|
|
return template.QommonTemplateResponse(
|
|
templates=['wcs/backoffice/changes.html'],
|
|
context={
|
|
'objects': objects,
|
|
'pagination_links': links,
|
|
},
|
|
)
|
|
|
|
def is_accessible(self, user, traversal=False):
|
|
return user.is_admin
|
|
|
|
|
|
class StudioDirectory(Directory):
|
|
_q_exports = ['', 'deprecations', ('logged-errors', 'logged_errors_dir'), ('all-changes', 'changes_dir')]
|
|
|
|
deprecations = DeprecationsDirectory()
|
|
changes_dir = ChangesDirectory()
|
|
|
|
def __init__(self):
|
|
self.logged_errors_dir = LoggedErrorsDirectory(parent_dir=self)
|
|
|
|
def _q_traverse(self, path):
|
|
get_response().breadcrumb.append(('studio/', _('Studio')))
|
|
get_response().set_backoffice_section('studio')
|
|
return super()._q_traverse(path)
|
|
|
|
def _q_index(self):
|
|
get_response().set_title(_('Studio'))
|
|
extra_links = []
|
|
backoffice_root = get_publisher().get_backoffice_root()
|
|
object_types = []
|
|
if backoffice_root.is_accessible('forms'):
|
|
extra_links.append(('../forms/blocks/', pgettext('studio', 'Blocks of fields')))
|
|
if backoffice_root.is_accessible('workflows'):
|
|
extra_links.append(('../workflows/mail-templates/', pgettext('studio', 'Mail templates')))
|
|
extra_links.append(('../workflows/comment-templates/', pgettext('studio', 'Comment templates')))
|
|
object_types += [Workflow, MailTemplate, CommentTemplate]
|
|
if backoffice_root.is_accessible('forms'):
|
|
extra_links.append(('../forms/data-sources/', pgettext('studio', 'Data sources')))
|
|
object_types += [NamedDataSource, BlockDef, FormDef]
|
|
elif backoffice_root.is_accessible('workflows'):
|
|
extra_links.append(('../workflows/data-sources/', pgettext('studio', 'Data sources')))
|
|
object_types += [NamedDataSource]
|
|
elif backoffice_root.is_accessible('settings'):
|
|
extra_links.append(('../settings/data-sources/', pgettext('studio', 'Data sources')))
|
|
object_types += [NamedDataSource]
|
|
if backoffice_root.is_accessible('settings'):
|
|
extra_links.append(('../settings/wscalls/', pgettext('studio', 'Webservice calls')))
|
|
object_types += [NamedWsCall]
|
|
if backoffice_root.is_accessible('cards'):
|
|
object_types += [CardDef]
|
|
if backoffice_root.is_accessible('i18n') and get_publisher().has_i18n_enabled():
|
|
extra_links.append(('../i18n/', pgettext('studio', 'Multilinguism')))
|
|
if backoffice_root.is_accessible('journal'):
|
|
extra_links.append(('../journal/', pgettext('studio', 'Audit Journal')))
|
|
|
|
user = get_request().user
|
|
context = {
|
|
'has_sidebar': False,
|
|
'extra_links': extra_links,
|
|
'recent_errors': LoggedErrorsDirectory.get_errors(offset=0, limit=5)[0],
|
|
'show_all_changes': get_publisher().snapshot_class and user and user.is_admin,
|
|
}
|
|
if get_publisher().snapshot_class:
|
|
context['recent_objects'] = get_publisher().snapshot_class.get_recent_changes(
|
|
object_types=[ot.xml_root_node for ot in object_types],
|
|
user=get_request().user,
|
|
)
|
|
return template.QommonTemplateResponse(
|
|
templates=['wcs/backoffice/studio.html'], context=context, is_django_native=True
|
|
)
|
|
|
|
def is_accessible(self, user, traversal=False):
|
|
backoffice_root = get_publisher().get_backoffice_root()
|
|
return (
|
|
backoffice_root.is_accessible('forms')
|
|
or backoffice_root.is_accessible('workflows')
|
|
or backoffice_root.is_accessible('cards')
|
|
)
|