Skip to content

Commit

Permalink
Merge branch 'master' of github.com:okfn/ckan into 1635-feature-email…
Browse files Browse the repository at this point in the history
…-notifications-for-activity-streams
  • Loading branch information
Sean Hammond committed Dec 12, 2012
2 parents 7bdc620 + 6e7560b commit 16ddee4
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 79 deletions.
3 changes: 2 additions & 1 deletion ckan/i18n/check_po_files.py
Expand Up @@ -11,7 +11,6 @@
'''
import re
import polib
import paste.script.command

def simple_conv_specs(s):
Expand Down Expand Up @@ -98,6 +97,8 @@ class CheckPoFiles(paste.script.command.Command):
parser = paste.script.command.Command.standard_parser(verbose=True)

def command(self):
import polib

test_simple_conv_specs()
test_mapping_keys()
test_replacement_fields()
Expand Down
68 changes: 49 additions & 19 deletions ckan/lib/app_globals.py
Expand Up @@ -29,6 +29,38 @@
'ckan.site_custom_css',
]

config_details = {
'ckan.favicon': {}, # default gets set in config.environment.py
'ckan.template_head_end': {},
'ckan.template_footer_end': {},
# has been setup in load_environment():
'ckan.site_id': {},
'ckan.recaptcha.publickey': {'name': 'recaptcha_publickey'},
'ckan.recaptcha.privatekey': {'name': 'recaptcha_publickey'},
'ckan.template_title_deliminater': {'default': '-'},
'ckan.template_head_end': {},
'ckan.template_footer_end': {},
'ckan.dumps_url': {},
'ckan.dumps_format': {},
'ckan.api_url': {},

# split string
'search.facets': {'default': 'groups tags res_format license',
'type': 'split',
'name': 'facets'},
'package_hide_extras': {'type': 'split'},
'plugins': {'type': 'split'},

# bool
'openid_enabled': {'default': 'true', 'type' : 'bool'},
'debug': {'default': 'false', 'type' : 'bool'},
'ckan.debug_supress_header' : {'default': 'false', 'type' : 'bool'},

# int
'ckan.datasets_per_page': {'default': '20', 'type': 'int'},
}


# A place to store the origional config options of we override them
_CONFIG_CACHE = {}

Expand Down Expand Up @@ -139,29 +171,27 @@ def _check_uptodate(self):
self._mutex.release()

def _init(self):
self.favicon = config.get('ckan.favicon', '/images/icons/ckan.ico')
facets = config.get('search.facets', 'groups tags res_format license')
self.facets = facets.split()

# has been setup in load_environment():
self.site_id = config.get('ckan.site_id')

self.template_head_end = config.get('ckan.template_head_end', '')
self.template_footer_end = config.get('ckan.template_footer_end', '')

# hide these extras fields on package read
package_hide_extras = config.get('package_hide_extras', '').split()
self.package_hide_extras = package_hide_extras

self.openid_enabled = asbool(config.get('openid_enabled', 'true'))
# process the config_details to set globals
for name, options in config_details.items():
if 'name' in options:
key = options['name']
elif name.startswith('ckan.'):
key = name[5:]
else:
key = name
value = config.get(name, options.get('default', ''))

self.recaptcha_publickey = config.get('ckan.recaptcha.publickey', '')
self.recaptcha_privatekey = config.get('ckan.recaptcha.privatekey', '')
data_type = options.get('type')
if data_type == 'bool':
value = asbool(value)
elif data_type == 'int':
value = int(value)
elif data_type == 'split':
value = value.split()

datasets_per_page = int(config.get('ckan.datasets_per_page', '20'))
self.datasets_per_page = datasets_per_page
setattr(self, key, value)

self.debug_supress_header = asbool(config.get('ckan.debug_supress_header', 'false'))

app_globals = _Globals()
del _Globals
4 changes: 4 additions & 0 deletions ckan/lib/base.py
Expand Up @@ -128,6 +128,10 @@ def render_template():

# Jinja2 templates
if template_type == 'jinja2':
# We don't want to have the config in templates it should be
# accessed via g (app_globals) as this gives us flexability such
# as changing via database settings.
del globs['config']
# TODO should we raise error if genshi filters??
return render_jinja2(template_name, globs)

Expand Down
75 changes: 31 additions & 44 deletions ckan/lib/cli.py
Expand Up @@ -577,9 +577,12 @@ class UserCmd(CkanCommand):
user - lists users
user list - lists users
user <user-name> - shows user properties
user add <user-name> [apikey=<apikey>] [password=<password>]
- add a user (prompts for password if
not supplied)
user add <user-name> [<field>=<value>]
- add a user (prompts for password
if not supplied).
Field can be: apikey
password
email
user setpass <user-name> - set user password (prompts)
user remove <user-name> - removes user from users
user search <query> - searches for a user name
Expand Down Expand Up @@ -676,53 +679,37 @@ def add(self):

if len(self.args) < 2:
print 'Need name of the user.'
return
username = self.args[1]
user = model.User.by_name(unicode(username))
if user:
print 'User "%s" already found' % username
sys.exit(1)
username = self.args[1]

# parse args
apikey = None
password = None
args = self.args[2:]
if len(args) == 1 and not (args[0].startswith('password') or \
args[0].startswith('apikey')):
# continue to support the old syntax of just supplying
# the apikey
apikey = args[0]
else:
# new syntax: password=foo apikey=bar
for arg in args:
split = arg.find('=')
if split == -1:
split = arg.find(' ')
if split == -1:
raise ValueError('Could not parse arg: %r (expected "--<option>=<value>)")' % arg)
key, value = arg[:split], arg[split+1:]
if key == 'password':
password = value
elif key == 'apikey':
apikey = value
else:
raise ValueError('Could not parse arg: %r (expected password/apikey argument)' % arg)
# parse args into data_dict
data_dict = {'name': username}
for arg in self.args[2:]:
try:
field, value = arg.split('=', 1)
data_dict[field] = value
except ValueError:
raise ValueError('Could not parse arg: %r (expected "<option>=<value>)"' % arg)

if not password:
password = self.password_prompt()
if 'password' not in data_dict:
data_dict['password'] = self.password_prompt()

print('Creating user: %r' % username)


user_params = {'name': unicode(username),
'password': password}
if apikey:
user_params['apikey'] = unicode(apikey)
user = model.User(**user_params)
model.Session.add(user)
model.repo.commit_and_remove()
user = model.User.by_name(unicode(username))
print user
try:
import ckan.logic as logic
site_user = logic.get_action('get_site_user')({'model': model, 'ignore_auth': True}, {})
context = {
'model': model,
'session': model.Session,
'ignore_auth': True,
'user': site_user['name'],
}
user_dict = logic.get_action('user_create')(context, data_dict)
pprint(user_dict)
except logic.ValidationError, e:
print e
sys.exit(1)

def remove(self):
import ckan.model as model
Expand Down
20 changes: 11 additions & 9 deletions ckan/templates/base.html
Expand Up @@ -10,6 +10,10 @@
<!--[if gt IE 8]><!--> <html lang="{{ lang }}"> <!--<![endif]-->
{%- endblock -%}

<!--
{{ g }}
-->

{# Allows custom attributes to be added to the <head> tag #}
<head{% block headtag %}{% endblock %}>
{#
Expand Down Expand Up @@ -41,7 +45,7 @@
<title>
{%- block title -%}
{%- block subtitle %}{% endblock -%}
{%- if self.subtitle()|trim %} {{ config.template_title_delimiter or '-' }} {% endif -%}
{%- if self.subtitle()|trim %} {{ g.template_title_deliminater }} {% endif -%}
{{ g.site_title }}
{%- endblock -%}
</title>
Expand All @@ -51,9 +55,7 @@
such as rss feeds and favicons in the same way as the meta block.
#}
{% block links -%}
{%- with favicon = config.get('ckan.favicon') or h.url_for_static('/base/images/ckan.ico') -%}
<link rel="shortcut icon" href="{{ favicon }}" />
{% endwith -%}
<link rel="shortcut icon" href="{{ g.favicon }}" />
{% endblock -%}

{#
Expand All @@ -72,9 +74,9 @@
{% resource g.main_css[6:] %}
{% endblock %}

{# defined in the config.ini under "ckan.template_head_end" #}
{% block head_extras %}
{{ config.get('ckan.template_head_end', '') | safe }}
{# defined in the config.ini under "ckan.template_head_end" #}
{{ g.template_head_end | safe }}
{% endblock %}

{%- block custom_styles %}
Expand All @@ -87,7 +89,7 @@
</head>

{# Allows custom attributes to be added to the <body> tag #}
<body{% block bodytag %} data-site-root="{{ h.url('/', locale='default', qualified=true) }}" data-locale-root="{{ h.url('/', qualified=true) }}" data-api-root="{{ config.get('ckan.api_url', '') }}"{% endblock %}>
<body{% block bodytag %} data-site-root="{{ h.url('/', locale='default', qualified=true) }}" data-locale-root="{{ h.url('/', qualified=true) }}" data-api-root="{{ g.api_url }}"{% endblock %}>

{#
The page block allows you to add content to the page. Most of the time it is
Expand Down Expand Up @@ -119,9 +121,9 @@
{%- block scripts %}
{% endblock -%}

{# defined in the config.ini under "ckan.template_footer_end" #}
{% block body_extras -%}
{{ config.get('ckan.template_footer_end', '') | safe }}
{# defined in the config.ini under "ckan.template_footer_end" #}
{{ g.template_footer_end | safe }}
{%- endblock %}
</body>
</html>
2 changes: 1 addition & 1 deletion ckan/templates/footer.html
Expand Up @@ -29,7 +29,7 @@
</div>

{% block footer_debug %}
{% if config.debug %}
{% if g.debug %}
{% include 'snippets/debug.html' %}
{% endif %}
{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/header.html
@@ -1,5 +1,5 @@
<header class="masthead">
{% if config.debug and not g.debug_supress_header %}
{% if g.debug and not g.debug_supress_header %}
<div class="debug">Controller : {{ c.controller }}<br/>Action : {{ c.action }}</div>
{% endif %}
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/package/resource_read.html
Expand Up @@ -32,7 +32,7 @@
</li>
{% endif %}

{% if 'datastore' in config.get('ckan.plugins') %}
{% if 'datastore' in g.plugins %}
<li>{% snippet 'package/snippets/data_api_button.html', resource=res, datastore_root_url=c.datastore_api %}</li>
{% endif %}
{% endblock %}
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/package/search.html
Expand Up @@ -75,8 +75,8 @@
You can also access this registry using the {{ h.link_to(_('API'), h.url_for(controller='api', action='get_api', ver=1)) }}
<!--! FIXME the API Docs link should be for the version of ckan being used but the dev version of ckan needs to point to latest so not trivial -->
(see {{ h.link_to(_('API Docs'), 'http://docs.ckan.org/en/latest/api.html') }})
{% if config.get('ckan.dumps_url') -%}
or download a <a href="{{ config.get('ckan.dumps_url') }}">full {{ config.get('ckan.dumps_format', '') }} dump</a>
{% if g.dumps_url -%}
or download a <a href="{{ g.dumps_url }}">full {{ g.dumps_format }} dump</a>
{%- endif %}.
</small>
</section>
Expand Down
2 changes: 1 addition & 1 deletion ckan/templates/page.html
Expand Up @@ -97,7 +97,7 @@ <h2>A sidebar item</h2>
{%- block scripts %}
{% resource 'base/main' %}
{% resource 'base/ckan' %}
{% if config.get('ckan.tracking_enabled', 'false') %}
{% if g.tracking_enabled %}
{% resource 'base/tracking.js' %}
{% endif %}
{{ super() }}
Expand Down

0 comments on commit 16ddee4

Please sign in to comment.