Skip to content

Commit

Permalink
merge upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Mayer authored and Florian Mayer committed Jul 14, 2017
2 parents 270ae97 + 7ef03e6 commit 7155808
Show file tree
Hide file tree
Showing 849 changed files with 170,071 additions and 35,670 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -25,6 +25,7 @@ fl_notes.txt
*.ini
.noseids
*~
.idea

# custom style
ckan/public/base/less/custom.less
Expand Down
28 changes: 26 additions & 2 deletions ckan/config/environment.py
Expand Up @@ -69,9 +69,21 @@ def find_controller(self, controller):

# Pylons paths
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

valid_base_public_folder_names = ['public', 'public-bs2']
static_files = app_conf.get('ckan.base_public_folder', 'public')
app_conf['ckan.base_public_folder'] = static_files

if static_files not in valid_base_public_folder_names:
raise CkanConfigurationException(
'You provided an invalid value for ckan.base_public_folder. '
'Possible values are: "public" and "public-bs2".'
)

log.info('Loading static files from %s' % static_files)
paths = dict(root=root,
controllers=os.path.join(root, 'controllers'),
static_files=os.path.join(root, 'public'),
static_files=os.path.join(root, static_files),
templates=[])

# Initialize main CKAN config object
Expand Down Expand Up @@ -220,7 +232,19 @@ def update_config():
helpers.load_plugin_helpers()
config['pylons.h'] = helpers.helper_functions

jinja2_templates_path = os.path.join(root, 'templates')
# Templates and CSS loading from configuration
valid_base_templates_folder_names = ['templates', 'templates-bs2']
templates = config.get('ckan.base_templates_folder', 'templates')
config['ckan.base_templates_folder'] = templates

if templates not in valid_base_templates_folder_names:
raise CkanConfigurationException(
'You provided an invalid value for ckan.base_templates_folder. '
'Possible values are: "templates" and "templates-bs2".'
)

jinja2_templates_path = os.path.join(root, templates)
log.info('Loading templates from %s' % jinja2_templates_path)
template_paths = [jinja2_templates_path]

extra_template_paths = config.get('extra_template_paths', '')
Expand Down
5 changes: 5 additions & 0 deletions ckan/config/middleware/flask_app.py
@@ -1,6 +1,7 @@
# encoding: utf-8

import os
import re
import inspect
import itertools
import pkgutil
Expand Down Expand Up @@ -174,6 +175,10 @@ def hello_world_post():
'bottom': True,
'bundle': True,
}
root_path = config.get('ckan.root_path', None)
if root_path:
root_path = re.sub('/{{LANG}}', '', root_path)
fanstatic_config['base_url'] = root_path
app = Fanstatic(app, **fanstatic_config)

for plugin in PluginImplementations(IMiddleware):
Expand Down
5 changes: 5 additions & 0 deletions ckan/config/middleware/pylons_app.py
@@ -1,6 +1,7 @@
# encoding: utf-8

import os
import re

from pylons.wsgiapp import PylonsApp

Expand Down Expand Up @@ -89,6 +90,10 @@ def make_pylons_stack(conf, full_stack=True, static_files=True,
'bottom': True,
'bundle': True,
}
root_path = config.get('ckan.root_path', None)
if root_path:
root_path = re.sub('/{{LANG}}', '', root_path)
fanstatic_config['base_url'] = root_path
app = Fanstatic(app, **fanstatic_config)

for plugin in PluginImplementations(IMiddleware):
Expand Down
11 changes: 6 additions & 5 deletions ckan/controllers/feed.py
Expand Up @@ -411,11 +411,12 @@ def output_feed(self, results, feed_title, feed_description,
author_email=pkg.get('author_email', ''),
categories=[t['name'] for t in pkg.get('tags', [])],
enclosure=webhelpers.feedgenerator.Enclosure(
self.base_url + h.url_for(controller='api',
register='package',
action='show',
id=pkg['name'],
ver='2'),
h.url_for(controller='api',
register='package',
action='show',
id=pkg['name'],
ver='3',
qualified=True),
unicode(len(json.dumps(pkg))), # TODO fix this
u'application/json'),
**additional_fields
Expand Down
5 changes: 4 additions & 1 deletion ckan/controllers/group.py
Expand Up @@ -670,8 +670,11 @@ def member_new(self, id):

context = {'model': model, 'session': model.Session,
'user': c.user}
try:
self._check_access('group_member_create', context, {'id': id})
except NotAuthorized:
abort(403, _('Unauthorized to create group %s members') % '')

# self._check_access('group_delete', context, {'id': id})
try:
data_dict = {'id': id}
data_dict['include_datasets'] = False
Expand Down
17 changes: 10 additions & 7 deletions ckan/controllers/package.py
Expand Up @@ -546,17 +546,23 @@ def new(self, data=None, errors=None, error_summary=None):
def resource_edit(self, id, resource_id, data=None, errors=None,
error_summary=None):

context = {'model': model, 'session': model.Session,
'api_version': 3, 'for_edit': True,
'user': c.user, 'auth_user_obj': c.userobj}
data_dict = {'id': id}

try:
check_access('package_update', context, data_dict)
except NotAuthorized:
abort(403, _('User %r not authorized to edit %s') % (c.user, id))

if request.method == 'POST' and not data:
data = data or \
clean_dict(dict_fns.unflatten(tuplize_dict(parse_params(
request.POST))))
# we don't want to include save as it is part of the form
del data['save']

context = {'model': model, 'session': model.Session,
'api_version': 3, 'for_edit': True,
'user': c.user, 'auth_user_obj': c.userobj}

data['package_id'] = id
try:
if resource_id:
Expand All @@ -574,9 +580,6 @@ def resource_edit(self, id, resource_id, data=None, errors=None,
h.redirect_to(controller='package', action='resource_read', id=id,
resource_id=resource_id)

context = {'model': model, 'session': model.Session,
'api_version': 3, 'for_edit': True,
'user': c.user, 'auth_user_obj': c.userobj}
pkg_dict = get_action('package_show')(context, {'id': id})
if pkg_dict['state'].startswith('draft'):
# dataset has not yet been fully created
Expand Down
25 changes: 15 additions & 10 deletions ckan/lib/cli.py
Expand Up @@ -26,7 +26,6 @@
import ckan.model as model
import ckan.include.rjsmin as rjsmin
import ckan.include.rcssmin as rcssmin
import ckan.lib.fanstatic_resources as fanstatic_resources
import ckan.plugins as p
from ckan.common import config

Expand Down Expand Up @@ -230,6 +229,7 @@ def load_config(config, load_site_user=True):
import pylons
registry.register(pylons.translator, MockTranslator())

site_user = None
if model.user_table.exists() and load_site_user:
# If the DB has already been initialized, create and register
# a pylons context object, and add the site user to it, so the
Expand All @@ -249,6 +249,8 @@ def load_config(config, load_site_user=True):
request_config.host = parsed.netloc + parsed.path
request_config.protocol = parsed.scheme

return site_user


def paster_click_group(summary):
'''Return a paster command click.Group for paster subcommands
Expand Down Expand Up @@ -305,11 +307,7 @@ class CkanCommand(paste.script.command.Command):
group_name = 'ckan'

def _load_config(self, load_site_user=True):
load_config(self.options.config, load_site_user)

def _setup_app(self):
cmd = paste.script.appinstall.SetupCommand('setup-app')
cmd.run([self.filename])
self.site_user = load_config(self.options.config, load_site_user)


class ManageDb(CkanCommand):
Expand Down Expand Up @@ -1478,7 +1476,6 @@ class CreateTestDataCommand(CkanCommand):

def command(self):
self._load_config()
self._setup_app()
from ckan import plugins
from create_test_data import CreateTestData

Expand Down Expand Up @@ -1795,8 +1792,9 @@ def command(self):
saturation = None
lightness = None

public = config.get(u'ckan.base_public_folder')
path = os.path.dirname(__file__)
path = os.path.join(path, '..', 'public', 'base', 'less', 'custom.less')
path = os.path.join(path, '..', public, 'base', 'less', 'custom.less')

if self.args:
arg = self.args[0]
Expand Down Expand Up @@ -1987,6 +1985,8 @@ def minify_file(self, path):
:param path: The path to the .js or .css file to minify
'''
import ckan.lib.fanstatic_resources as fanstatic_resources

path_only, extension = os.path.splitext(path)

if path_only.endswith('.min'):
Expand Down Expand Up @@ -2022,6 +2022,7 @@ class LessCommand(CkanCommand):
min_args = 0

def command(self):
self._load_config()
self.less()

custom_css = {
Expand Down Expand Up @@ -2071,7 +2072,9 @@ def less(self):
directory = output[0].strip()
less_bin = os.path.join(directory, 'lessc')

root = os.path.join(os.path.dirname(__file__), '..', 'public', 'base')
public = config.get(u'ckan.base_public_folder')

root = os.path.join(os.path.dirname(__file__), '..', public, 'base')
root = os.path.abspath(root)
custom_less = os.path.join(root, 'less', 'custom.less')
for color in self.custom_css:
Expand All @@ -2094,6 +2097,7 @@ def compile_less(self, root, less_bin, color):

process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
output = process.communicate()
print output


class FrontEndBuildCommand(CkanCommand):
Expand Down Expand Up @@ -2124,7 +2128,8 @@ def command(self):
# minification
cmd = MinifyCommand('minify')
cmd.options = self.options
root = os.path.join(os.path.dirname(__file__), '..', 'public', 'base')
public = config.get(u'ckan.base_public_folder')
root = os.path.join(os.path.dirname(__file__), '..', public, 'base')
root = os.path.abspath(root)
ckanext = os.path.join(os.path.dirname(__file__), '..', '..', 'ckanext')
ckanext = os.path.abspath(ckanext)
Expand Down
24 changes: 15 additions & 9 deletions ckan/lib/fanstatic_resources.py
Expand Up @@ -4,6 +4,7 @@
import sys
import logging
import ConfigParser
from ckan.common import config

from fanstatic import Library, Resource, Group, get_library_registry
import fanstatic.core as core
Expand Down Expand Up @@ -78,10 +79,10 @@ def create_resource(path, lib_name, count, inline=False):
condition = IE_conditionals[path][0]
if inline or condition:
kw['renderer'] = fanstatic_extensions.CkanCustomRenderer(
condition=condition,
script=inline,
renderer=renderer,
other_browsers=other_browsers)
condition=condition,
script=inline,
renderer=renderer,
other_browsers=other_browsers)
resource = Resource(library, path, **kw)

# Add our customised ordering
Expand Down Expand Up @@ -161,7 +162,8 @@ def create_resource(path, lib_name, count, inline=False):
dep_resources = [dep]
else:
dep_resources = groups[dep]
diff = [res for res in dep_resources if res not in depends[resource]]
diff = [
res for res in dep_resources if res not in depends[resource]]
depends[resource].extend(diff)

# process each .js/.css file found
Expand All @@ -174,8 +176,8 @@ def create_resource(path, lib_name, count, inline=False):
filepath = os.path.join(rel_path, f)
filename_only, extension = os.path.splitext(f)
if extension in ('.css', '.js') and (
not filename_only.endswith('.min')):
resource_list.append(filepath)
not filename_only.endswith('.min')):
resource_list.append(filepath)

# if groups are defined make sure the order supplied there is honored
for group in groups:
Expand Down Expand Up @@ -227,9 +229,13 @@ def create_resource(path, lib_name, count, inline=False):
registry = get_library_registry()
registry.add(library)

base_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'..', 'public', 'base'))

public = config.get('ckan.base_public_folder')

base_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', public, 'base'))

log.info('Base path {0}'.format(base_path))
create_library('vendor', os.path.join(base_path, 'vendor'), depend_base=False)

create_library('base', os.path.join(base_path, 'javascript'),
Expand Down
9 changes: 6 additions & 3 deletions ckan/lib/helpers.py
Expand Up @@ -33,7 +33,6 @@
import i18n

import ckan.exceptions
import ckan.lib.fanstatic_resources as fanstatic_resources
import ckan.model as model
import ckan.lib.formatters as formatters
import ckan.lib.maintain as maintain
Expand Down Expand Up @@ -1088,7 +1087,7 @@ class Page(paginate.Page):

def pager(self, *args, **kwargs):
kwargs.update(
format=u"<div class='pagination pagination-centered'><ul>"
format=u"<div class='pagination-wrapper'><ul class='pagination'>"
"$link_previous ~2~ $link_next</ul></div>",
symbol_previous=u'«', symbol_next=u'»',
curpage_attr={'class': 'active'}, link_attr={}
Expand Down Expand Up @@ -1621,6 +1620,7 @@ def remove_url_param(key, value=None, replace=None, controller=None,

@core_helper
def include_resource(resource):
import ckan.lib.fanstatic_resources as fanstatic_resources
r = getattr(fanstatic_resources, resource)
r.need()

Expand All @@ -1632,6 +1632,8 @@ def urls_for_resource(resource):
NOTE: This is for special situations only and is not the way to generally
include resources. It is advised not to use this function.'''
import ckan.lib.fanstatic_resources as fanstatic_resources

r = getattr(fanstatic_resources, resource)
resources = list(r.resources)
core = fanstatic_resources.fanstatic_extensions.core
Expand Down Expand Up @@ -2325,7 +2327,8 @@ def get_translated(data_dict, field):
try:
return data_dict[field + u'_translated'][language]
except KeyError:
return data_dict.get(field, '')
val = data_dict.get(field, '')
return _(val) if val and isinstance(val, basestring) else val


@core_helper
Expand Down

0 comments on commit 7155808

Please sign in to comment.