From a923e00e636ad8b83bc0a689c9c7e8833aa63219 Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Tue, 31 Oct 2017 17:59:34 +0200 Subject: [PATCH] admin blueprint. First step --- ckan/config/routing.py | 9 - ckan/lib/base.py | 8 +- ckan/logic/__init__.py | 8 +- ckan/templates-bs2/admin/base.html | 6 +- ckan/templates-bs2/admin/config.html | 31 ++- ckan/templates-bs2/admin/index.html | 2 +- ckan/templates-bs2/admin/trash.html | 3 +- ckan/templates/admin/base.html | 6 +- ckan/templates/admin/config.html | 73 ++++--- ckan/templates/admin/index.html | 2 +- ckan/templates/admin/trash.html | 3 +- ckan/tests/legacy/functional/test_admin.py | 3 +- ckan/views/admin.py | 213 +++++++++++++++++++++ 13 files changed, 309 insertions(+), 58 deletions(-) create mode 100644 ckan/views/admin.py diff --git a/ckan/config/routing.py b/ckan/config/routing.py index 08b3a3e3bdc..8f0b246a0bb 100644 --- a/ckan/config/routing.py +++ b/ckan/config/routing.py @@ -371,15 +371,6 @@ def make_map(): m.connect('/revision/list', action='list') m.connect('/revision/{id}', action='read') - - map.connect('ckanadmin_index', '/ckan-admin', controller='admin', - action='index', ckan_icon='gavel') - map.connect('ckanadmin_config', '/ckan-admin/config', controller='admin', - action='config', ckan_icon='check-square-o') - map.connect('ckanadmin_trash', '/ckan-admin/trash', controller='admin', - action='trash', ckan_icon='trash-o') - map.connect('ckanadmin', '/ckan-admin/{action}', controller='admin') - with SubMapper(map, controller='ckan.controllers.storage:StorageController') as m: m.connect('storage_file', '/storage/f/{label:.*}', action='file') diff --git a/ckan/lib/base.py b/ckan/lib/base.py index 16c5eacd4a6..67df4949a31 100644 --- a/ckan/lib/base.py +++ b/ckan/lib/base.py @@ -14,7 +14,10 @@ from pylons.templating import cached_template, pylons_globals from webhelpers.html import literal -from flask import render_template as flask_render_template +from flask import ( + render_template as flask_render_template, + abort as flask_abort +) import ckan.exceptions import ckan import ckan.lib.i18n as i18n @@ -61,6 +64,9 @@ def abort(status_code=None, detail='', headers=None, comment=None): # #1267 Convert detail to plain text, since WebOb 0.9.7.1 (which comes # with Lucid) causes an exception when unicode is received. detail = detail.encode('utf8') + if is_flask_request(): + flask_abort(status_code, detail) + return _abort(status_code=status_code, detail=detail, headers=headers, diff --git a/ckan/logic/__init__.py b/ckan/logic/__init__.py index f0833f316b1..ec8ec67a76c 100644 --- a/ckan/logic/__init__.py +++ b/ckan/logic/__init__.py @@ -132,7 +132,13 @@ def parse_params(params, ignore_keys=None): for key in params: if ignore_keys and key in ignore_keys: continue - value = params.getall(key) + # flask request has `getlist` instead of pylons' `getall` + + if hasattr(params, 'getall'): + value = params.getall(key) + else: + value = params.getlist(key) + # Blank values become '' if not value: value = '' diff --git a/ckan/templates-bs2/admin/base.html b/ckan/templates-bs2/admin/base.html index fc45c38eb90..741c229c324 100644 --- a/ckan/templates-bs2/admin/base.html +++ b/ckan/templates-bs2/admin/base.html @@ -5,8 +5,8 @@ {% block breadcrumb_content %}{% endblock %} {% block content_primary_nav %} - {{ h.build_nav_icon('ckanadmin_index', _('Sysadmins')) }} - {{ h.build_nav_icon('ckanadmin_config', _('Config')) }} - {{ h.build_nav_icon('ckanadmin_trash', _('Trash')) }} + {{ h.build_nav_icon('admin.index', _('Sysadmins'), icon='gavel') }} + {{ h.build_nav_icon('admin.config', _('Config'), icon='check-square-o') }} + {{ h.build_nav_icon('admin.trash', _('Trash'), icon='trash-o') }} {{ h.build_extra_admin_nav() }} {% endblock %} diff --git a/ckan/templates-bs2/admin/config.html b/ckan/templates-bs2/admin/config.html index 840783a9fb3..0d247f4bca4 100644 --- a/ckan/templates-bs2/admin/config.html +++ b/ckan/templates-bs2/admin/config.html @@ -6,21 +6,40 @@ {% block primary_content_inner %} - {{ form.errors(error_summary) }} +{{ form.errors(error_summary) }}
{% block admin_form %} - {{ autoform.generate(form_items, data, errors) }} + + {{ form.input('ckan.site_title', id='field-ckan-site-title', label=_('Site Title'), value=data['ckan.site_title'], error=error, classes=['control-medium']) }} + + {{ form.select('ckan.main_css', id='field-ckan-main-css', label=_('Style'), options=styles, selected=data['ckan.main_css'], error=error) }} + + {{ form.input('ckan.site_description', id='field-ckan-site-description', label=_('Site Tag Line'), value=data['ckan.site_description'], error=error, classes=['control-medium']) }} + + {% set field_url = 'ckan.site_logo' %} + {% set is_upload = data[field_url] and not data[field_url].startswith('http') %} + {% set is_url = data[field_url] and data[field_url].startswith('http') %} + {{ form.image_upload(data, errors, is_upload_enabled=h.uploads_enabled(), is_url=is_url, is_upload=is_upload, upload_label = _('Site logo'), url_label=_('Site logo'), field_url=field_url, field_upload='logo_upload', field_clear='clear_logo_upload' )}} + + {{ form.markdown('ckan.site_about', id='field-ckan-site-about', label=_('About'), value=data['ckan.site_about'], error=error, placeholder=_('About page text')) }} + + {{ form.markdown('ckan.site_intro_text', id='field-ckan-site-intro-text', label=_('Intro Text'), value=data['ckan.site_intro_text'], error=error, placeholder=_('Text on home page')) }} + + {{ form.textarea('ckan.site_custom_css', id='field-ckan-site-custom-css', label=_('Custom CSS'), value=data['ckan.site_custom_css'], error=error, placeholder=_('Customisable css inserted into the page header')) }} + + {{ form.select('ckan.homepage_style', id='field-homepage-style', label=_('Homepage'), options=homepages, selected=data['ckan.homepage_style'], error=error) }} + {% endblock %}
- {{ _('Reset') }} - + {{ _('Reset') }} +
-
+ {% endblock %} {% block secondary_content %} -
+

{{ _('CKAN config options') }} diff --git a/ckan/templates-bs2/admin/index.html b/ckan/templates-bs2/admin/index.html index 498da63d440..c313bf32573 100644 --- a/ckan/templates-bs2/admin/index.html +++ b/ckan/templates-bs2/admin/index.html @@ -2,7 +2,7 @@ {% block primary_content_inner %}
    - {% for user in c.sysadmins %} + {% for user in sysadmins %}
  • {{ h.linked_user(user) }}
  • {% endfor %}
diff --git a/ckan/templates-bs2/admin/trash.html b/ckan/templates-bs2/admin/trash.html index 2484eb7cefd..108ce9e6b35 100644 --- a/ckan/templates-bs2/admin/trash.html +++ b/ckan/templates-bs2/admin/trash.html @@ -4,7 +4,7 @@ {% set truncate = truncate or 180 %} {% set truncate_title = truncate_title or 80 %}
    - {% for pkg in c.deleted_packages %} + {% for pkg in deleted_packages %} {% set title = pkg.title or pkg.name %}
  • {{ h.link_to(h.truncate(title, truncate_title), h.url_for(controller='package', action='read', id=pkg.name)) }}
  • {% endfor %} @@ -35,4 +35,3 @@

{% endblock %} - diff --git a/ckan/templates/admin/base.html b/ckan/templates/admin/base.html index fc45c38eb90..741c229c324 100644 --- a/ckan/templates/admin/base.html +++ b/ckan/templates/admin/base.html @@ -5,8 +5,8 @@ {% block breadcrumb_content %}{% endblock %} {% block content_primary_nav %} - {{ h.build_nav_icon('ckanadmin_index', _('Sysadmins')) }} - {{ h.build_nav_icon('ckanadmin_config', _('Config')) }} - {{ h.build_nav_icon('ckanadmin_trash', _('Trash')) }} + {{ h.build_nav_icon('admin.index', _('Sysadmins'), icon='gavel') }} + {{ h.build_nav_icon('admin.config', _('Config'), icon='check-square-o') }} + {{ h.build_nav_icon('admin.trash', _('Trash'), icon='trash-o') }} {{ h.build_extra_admin_nav() }} {% endblock %} diff --git a/ckan/templates/admin/config.html b/ckan/templates/admin/config.html index 6ac7d26c072..37e09caeda9 100644 --- a/ckan/templates/admin/config.html +++ b/ckan/templates/admin/config.html @@ -10,12 +10,31 @@
{% block admin_form %} - {{ autoform.generate(form_items, data, errors) }} - {% endblock %} -
- {{ _('Reset') }} - -
+ + {{ form.input('ckan.site_title', id='field-ckan-site-title', label=_('Site Title'), value=data['ckan.site_title'], error=error, classes=['control-medium']) }} + + {{ form.select('ckan.main_css', id='field-ckan-main-css', label=_('Style'), options=styles, selected=data['ckan.main_css'], error=error) }} + + {{ form.input('ckan.site_description', id='field-ckan-site-description', label=_('Site Tag Line'), value=data['ckan.site_description'], error=error, classes=['control-medium']) }} + + {% set field_url = 'ckan.site_logo' %} + {% set is_upload = data[field_url] and not data[field_url].startswith('http') %} + {% set is_url = data[field_url] and data[field_url].startswith('http') %} + {{ form.image_upload(data, errors, is_upload_enabled=h.uploads_enabled(), is_url=is_url, is_upload=is_upload, upload_label = _('Site logo'), url_label=_('Site logo'), field_url=field_url, field_upload='logo_upload', field_clear='clear_logo_upload' )}} + + {{ form.markdown('ckan.site_about', id='field-ckan-site-about', label=_('About'), value=data['ckan.site_about'], error=error, placeholder=_('About page text')) }} + + {{ form.markdown('ckan.site_intro_text', id='field-ckan-site-intro-text', label=_('Intro Text'), value=data['ckan.site_intro_text'], error=error, placeholder=_('Text on home page')) }} + + {{ form.textarea('ckan.site_custom_css', id='field-ckan-site-custom-css', label=_('Custom CSS'), value=data['ckan.site_custom_css'], error=error, placeholder=_('Customisable css inserted into the page header')) }} + + {{ form.select('ckan.homepage_style', id='field-homepage-style', label=_('Homepage'), options=homepages, selected=data['ckan.homepage_style'], error=error) }} + + {% endblock %} +
+ {{ _('Reset') }} + +
{% endblock %} @@ -27,28 +46,28 @@

{% block admin_form_help %} - {% set about_url = h.url_for(controller='home', action='about') %} - {% set home_url = h.url_for(controller='home', action='index') %} - {% set docs_url = "http://docs.ckan.org/en/{0}/theming".format(g.ckan_doc_version) %} - {% trans %} -

Site Title: This is the title of this CKAN instance - It appears in various places throughout CKAN.

-

Style: Choose from a list of simple variations of - the main colour scheme to get a very quick custom theme working.

-

Site Tag Logo: This is the logo that appears in the - header of all the CKAN instance templates.

-

About: This text will appear on this CKAN instances - about page.

-

Intro Text: This text will appear on this CKAN instances - home page as a welcome to visitors.

-

Custom CSS: This is a block of CSS that appears in - <head> tag of every page. If you wish to customize - the templates more fully we recommend - reading the documentation.

-

Homepage: This is for choosing a predefined layout for - the modules that appear on your homepage.

+ {% set about_url = h.url_for(controller='home', action='about') %} + {% set home_url = h.url_for(controller='home', action='index') %} + {% set docs_url = "http://docs.ckan.org/en/{0}/theming".format(g.ckan_doc_version) %} + {% trans %} +

Site Title: This is the title of this CKAN instance + It appears in various places throughout CKAN.

+

Style: Choose from a list of simple variations of + the main colour scheme to get a very quick custom theme working.

+

Site Tag Logo: This is the logo that appears in the + header of all the CKAN instance templates.

+

About: This text will appear on this CKAN instances + about page.

+

Intro Text: This text will appear on this CKAN instances + home page as a welcome to visitors.

+

Custom CSS: This is a block of CSS that appears in + <head> tag of every page. If you wish to customize + the templates more fully we recommend + reading the documentation.

+

Homepage: This is for choosing a predefined layout for + the modules that appear on your homepage.

{% endtrans %} - {% endblock %} + {% endblock %}
{% endblock %} diff --git a/ckan/templates/admin/index.html b/ckan/templates/admin/index.html index 498da63d440..c313bf32573 100644 --- a/ckan/templates/admin/index.html +++ b/ckan/templates/admin/index.html @@ -2,7 +2,7 @@ {% block primary_content_inner %} diff --git a/ckan/templates/admin/trash.html b/ckan/templates/admin/trash.html index 2484eb7cefd..108ce9e6b35 100644 --- a/ckan/templates/admin/trash.html +++ b/ckan/templates/admin/trash.html @@ -4,7 +4,7 @@ {% set truncate = truncate or 180 %} {% set truncate_title = truncate_title or 80 %}