Skip to content

Commit

Permalink
admin blueprint. First step
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Oct 31, 2017
1 parent c5a1be8 commit a923e00
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 58 deletions.
9 changes: 0 additions & 9 deletions ckan/config/routing.py
Expand Up @@ -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')
Expand Down
8 changes: 7 additions & 1 deletion ckan/lib/base.py
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion ckan/logic/__init__.py
Expand Up @@ -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 = ''
Expand Down
6 changes: 3 additions & 3 deletions ckan/templates-bs2/admin/base.html
Expand Up @@ -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 %}
31 changes: 25 additions & 6 deletions ckan/templates-bs2/admin/config.html
Expand Up @@ -6,21 +6,40 @@

{% block primary_content_inner %}

{{ form.errors(error_summary) }}
{{ form.errors(error_summary) }}

<form method='post' action="" class="form-horizontal" id="admin-config-form" enctype="multipart/form-data">
{% 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 %}
<div class="form-actions">
<a href="{% url_for controller='admin', action='reset_config' %}" class="btn btn-danger pull-left" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to reset the config?') }}">{{ _('Reset') }}</a>
<button type="submit" class="btn btn-primary" name="save">{{ _('Update Config') }}</button>
<a href="{% url_for controller='admin', action='reset_config' %}" class="btn btn-danger pull-left" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to reset the config?') }}">{{ _('Reset') }}</a>
<button type="submit" class="btn btn-primary" name="save">{{ _('Update Config') }}</button>
</div>
</form>
</form>
{% endblock %}

{% block secondary_content %}
<div class="module module-narrow module-shallow">
<div class="module module-narrow module-shallow">
<h2 class="module-heading">
<i class="fa fa-info-circle"></i>
{{ _('CKAN config options') }}
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates-bs2/admin/index.html
Expand Up @@ -2,7 +2,7 @@

{% block primary_content_inner %}
<ul class="user-list">
{% for user in c.sysadmins %}
{% for user in sysadmins %}
<li>{{ h.linked_user(user) }}</li>
{% endfor %}
</ul>
Expand Down
3 changes: 1 addition & 2 deletions ckan/templates-bs2/admin/trash.html
Expand Up @@ -4,7 +4,7 @@
{% set truncate = truncate or 180 %}
{% set truncate_title = truncate_title or 80 %}
<ul class="user-list">
{% for pkg in c.deleted_packages %}
{% for pkg in deleted_packages %}
{% set title = pkg.title or pkg.name %}
<li>{{ h.link_to(h.truncate(title, truncate_title), h.url_for(controller='package', action='read', id=pkg.name)) }}</li>
{% endfor %}
Expand Down Expand Up @@ -35,4 +35,3 @@ <h2 class="module-heading">
</div>
</div>
{% endblock %}

6 changes: 3 additions & 3 deletions ckan/templates/admin/base.html
Expand Up @@ -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 %}
73 changes: 46 additions & 27 deletions ckan/templates/admin/config.html
Expand Up @@ -10,12 +10,31 @@

<form method='post' action="" id="admin-config-form" enctype="multipart/form-data">
{% block admin_form %}
{{ autoform.generate(form_items, data, errors) }}
{% endblock %}
<div class="form-actions">
<a href="{% url_for controller='admin', action='reset_config' %}" class="btn btn-danger pull-left" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to reset the config?') }}">{{ _('Reset') }}</a>
<button type="submit" class="btn btn-primary" name="save">{{ _('Update Config') }}</button>
</div>

{{ 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 %}
<div class="form-actions">
<a href="{% url_for controller='admin', action='reset_config' %}" class="btn btn-danger pull-left" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to reset the config?') }}">{{ _('Reset') }}</a>
<button type="submit" class="btn btn-primary" name="save">{{ _('Update Config') }}</button>
</div>
</form>
{% endblock %}

Expand All @@ -27,28 +46,28 @@ <h2 class="module-heading">
</h2>
<div class="module-content">
{% 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 %}
<p><strong>Site Title:</strong> This is the title of this CKAN instance
It appears in various places throughout CKAN.</p>
<p><strong>Style:</strong> Choose from a list of simple variations of
the main colour scheme to get a very quick custom theme working.</p>
<p><strong>Site Tag Logo:</strong> This is the logo that appears in the
header of all the CKAN instance templates.</p>
<p><strong>About:</strong> This text will appear on this CKAN instances
<a href="{{ about_url }}">about page</a>.</p>
<p><strong>Intro Text:</strong> This text will appear on this CKAN instances
<a href="{{ home_url }}">home page</a> as a welcome to visitors.</p>
<p><strong>Custom CSS:</strong> This is a block of CSS that appears in
<code>&lt;head&gt;</code> tag of every page. If you wish to customize
the templates more fully we recommend
<a href="{{ docs_url }}" target="_blank">reading the documentation</a>.</p>
<p><strong>Homepage:</strong> This is for choosing a predefined layout for
the modules that appear on your homepage.</p>
{% 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 %}
<p><strong>Site Title:</strong> This is the title of this CKAN instance
It appears in various places throughout CKAN.</p>
<p><strong>Style:</strong> Choose from a list of simple variations of
the main colour scheme to get a very quick custom theme working.</p>
<p><strong>Site Tag Logo:</strong> This is the logo that appears in the
header of all the CKAN instance templates.</p>
<p><strong>About:</strong> This text will appear on this CKAN instances
<a href="{{ about_url }}">about page</a>.</p>
<p><strong>Intro Text:</strong> This text will appear on this CKAN instances
<a href="{{ home_url }}">home page</a> as a welcome to visitors.</p>
<p><strong>Custom CSS:</strong> This is a block of CSS that appears in
<code>&lt;head&gt;</code> tag of every page. If you wish to customize
the templates more fully we recommend
<a href="{{ docs_url }}" target="_blank">reading the documentation</a>.</p>
<p><strong>Homepage:</strong> This is for choosing a predefined layout for
the modules that appear on your homepage.</p>
{% endtrans %}
{% endblock %}
{% endblock %}
</div>
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion ckan/templates/admin/index.html
Expand Up @@ -2,7 +2,7 @@

{% block primary_content_inner %}
<ul class="user-list">
{% for user in c.sysadmins %}
{% for user in sysadmins %}
<li>{{ h.linked_user(user) }}</li>
{% endfor %}
</ul>
Expand Down
3 changes: 1 addition & 2 deletions ckan/templates/admin/trash.html
Expand Up @@ -4,7 +4,7 @@
{% set truncate = truncate or 180 %}
{% set truncate_title = truncate_title or 80 %}
<ul class="user-list">
{% for pkg in c.deleted_packages %}
{% for pkg in deleted_packages %}
{% set title = pkg.title or pkg.name %}
<li>{{ h.link_to(h.truncate(title, truncate_title), h.url_for(controller='package', action='read', id=pkg.name)) }}</li>
{% endfor %}
Expand Down Expand Up @@ -35,4 +35,3 @@ <h2 class="module-heading">
</div>
</div>
{% endblock %}

3 changes: 1 addition & 2 deletions ckan/tests/legacy/functional/test_admin.py
Expand Up @@ -15,7 +15,7 @@ def teardown_class(self):

#test that only sysadmins can access the /ckan-admin page
def test_index(self):
url = url_for('ckanadmin', action='index')
url = url_for('admin.index')
response = self.app.get(url, status=[403])
# random username
response = self.app.get(url, status=[403],
Expand All @@ -25,4 +25,3 @@ def test_index(self):
response = self.app.get(url,
extra_environ={'REMOTE_USER': username})
assert 'Administration' in response, response

0 comments on commit a923e00

Please sign in to comment.