Skip to content

Commit

Permalink
Merge remote-tracking branch 'okfn/master' into 368-new-history-page
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Feb 19, 2013
2 parents 867ae73 + 90a6ef2 commit d5e0155
Show file tree
Hide file tree
Showing 274 changed files with 50,097 additions and 11,212 deletions.
5 changes: 2 additions & 3 deletions ckan/controllers/group.py
Expand Up @@ -628,9 +628,8 @@ def activity(self, id, offset=0):

# Add the group's activity stream (already rendered to HTML) to the
# template context for the group/read.html template to retrieve later.
c.group_activity_stream = \
get_action('group_activity_list_html')(context,
{'id': c.group_dict['id'], 'offset': offset})
c.group_activity_stream = get_action('group_activity_list_html')(
context, {'id': c.group_dict['id'], 'offset': offset})

return render('group/activity_stream.html')

Expand Down
3 changes: 0 additions & 3 deletions ckan/controllers/package.py
Expand Up @@ -594,7 +594,6 @@ def new_resource(self, id, data=None, errors=None, error_summary=None):
del data['id']

context = {'model': model, 'session': model.Session,
'api_version': 3,
'user': c.user or c.author,
'extras_as_string': True}

Expand Down Expand Up @@ -680,7 +679,6 @@ def new_metadata(self, id, data=None, errors=None, error_summary=None):
# 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,
'user': c.user or c.author,
'extras_as_string': True}
data_dict = get_action('package_show')(context, {'id': id})
Expand Down Expand Up @@ -964,7 +962,6 @@ def _save_edit(self, name_or_id, context, package_type=None):
data_dict = clean_dict(unflatten(
tuplize_dict(parse_params(request.POST))))
if '_ckan_phase' in data_dict:
context['api_version'] = 3
# we allow partial updates to not destroy existing resources
context['allow_partial_update'] = True
data_dict['tags'] = self._tag_string_to_list(
Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/related.py
Expand Up @@ -61,7 +61,7 @@ def pager_url(q=None, page=None):
page=page,
url=pager_url,
item_count=query.count(),
items_per_page=8
items_per_page=9
)

c.filters = dict(params_nopage)
Expand Down
63 changes: 62 additions & 1 deletion ckan/controllers/user.py
Expand Up @@ -503,13 +503,74 @@ def activity(self, id, offset=0):

return render('user/activity_stream.html')

def _get_dashboard_context(self, filter_type=None, filter_id=None,
q=None):
'''Return a dict needed by the dashboard view to determine context.'''

def display_name(followee):
'''Return a display name for a user, group or dataset dict.'''
display_name = followee.get('display_name')
fullname = followee.get('fullname')
title = followee.get('title')
name = followee.get('name')
return display_name or fullname or title or name

if (filter_type and filter_id):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': filter_id}
followee = None

action_functions = {
'dataset': 'package_show',
'user': 'user_show',
'group': 'group_show'
}
action_function = logic.get_action(action_functions.get(filter_type))
# Is this a valid type?
if action_function is None:
raise abort(404, _('Follow item not found'))
try:
followee = action_function(context, data_dict)
except NotFound:
abort(404, _('{0} not found').format(filter_type))
except NotAuthorized:
abort(401, _('Unauthorized to read {0} {1}').format(
filter_type, id))

if followee is not None:
return {
'filter_type': filter_type,
'q': q,
'context': display_name(followee),
'selected_id': followee.get('id'),
'dict': followee,
}

return {
'filter_type': filter_type,
'q': q,
'context': _('Everything'),
'selected_id': False,
'dict': None,
}

def dashboard(self, id=None, offset=0):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'for_view': True}
data_dict = {'id': id, 'user_obj': c.userobj, 'offset': offset}
self._setup_template_variables(context, data_dict)

c.dashboard_activity_stream = h.dashboard_activity_stream(id, offset)
q = request.params.get('q', u'')
filter_type = request.params.get('type', u'')
filter_id = request.params.get('name', u'')

c.followee_list = get_action('followee_list')(
context, {'id': c.userobj.id, 'q': q})
c.dashboard_activity_stream_context = self._get_dashboard_context(
filter_type, filter_id, q)
c.dashboard_activity_stream = h.dashboard_activity_stream(
id, filter_type, filter_id, offset)

# Mark the user's new activities as old whenever they view their
# dashboard page.
Expand Down
16 changes: 8 additions & 8 deletions ckan/lib/activity_streams.py
Expand Up @@ -13,29 +13,29 @@
# etc.

def get_snippet_actor(activity, detail):
return literal('''<span class="actor" data-module="popover-context" data-module-type="user" data-module-id="%s">%s</span>'''
% (activity['user_id'], h.linked_user(activity['user_id'], 0, 30))
return literal('''<span class="actor">%s</span>'''
% (h.linked_user(activity['user_id'], 0, 30))
)

def get_snippet_user(activity, detail):
return literal('''<span data-module="popover-context" data-module-type="user" data-module-id="%s">%s</span>'''
% (activity['object_id'], h.linked_user(activity['object_id'], 0, 20))
return literal('''<span>%s</span>'''
% (h.linked_user(activity['object_id'], 0, 20))
)

def get_snippet_dataset(activity, detail):
data = activity['data']
link = h.dataset_link(data.get('package') or data.get('dataset'))
return literal('''<span data-module="popover-context" data-module-type="dataset" data-module-id="%s">%s</span>'''
% (activity['object_id'], link)
return literal('''<span>%s</span>'''
% (link)
)

def get_snippet_tag(activity, detail):
return h.tag_link(detail['data']['tag'])

def get_snippet_group(activity, detail):
link = h.group_link(activity['data']['group'])
return literal('''<span data-module="popover-context" data-module-type="group" data-module-id="%s">%s</span>'''
% (activity['object_id'], link)
return literal('''<span>%s</span>'''
% (link)
)

def get_snippet_organization(activity, detail):
Expand Down
8 changes: 7 additions & 1 deletion ckan/lib/app_globals.py
Expand Up @@ -3,10 +3,12 @@
import logging
import time
from threading import Lock
import re

from paste.deploy.converters import asbool
from pylons import config

import ckan
import ckan.model as model

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -49,7 +51,7 @@
'type': 'split',
'name': 'facets'},
'package_hide_extras': {'type': 'split'},
'plugins': {'type': 'split'},
'ckan.plugins': {'type': 'split'},

# bool
'openid_enabled': {'default': 'true', 'type' : 'bool'},
Expand Down Expand Up @@ -172,6 +174,10 @@ def _check_uptodate(self):
self._mutex.release()

def _init(self):

self.ckan_version = ckan.__version__
self.ckan_base_version = re.sub('[^0-9\.]', '', self.ckan_version)

# process the config_details to set globals
for name, options in config_details.items():
if 'name' in options:
Expand Down
122 changes: 122 additions & 0 deletions ckan/lib/cli.py
Expand Up @@ -1757,13 +1757,16 @@ class MinifyCommand(CkanCommand):
usage = __doc__
min_args = 1

exclude_dirs = ['vendor']

def command(self):
self._load_config()
for base_path in self.args:
if os.path.isfile(base_path):
self.minify_file(base_path)
elif os.path.isdir(base_path):
for root, dirs, files in os.walk(base_path):
dirs[:] = [d for d in dirs if not d in self.exclude_dirs]
for filename in files:
path = os.path.join(root, filename)
self.minify_file(path)
Expand Down Expand Up @@ -1801,3 +1804,122 @@ def minify_file(self, path):
f.write(rjsmin.jsmin(source))
f.close()
print "Minified file '{0}'".format(path)


class LessCommand(CkanCommand):
'''Compile all root less documents into their CSS counterparts
Usage:
paster less
'''
summary = __doc__.split('\n')[0]
usage = __doc__
min_args = 0

def command(self):
self.less()

custom_css = {
'fuchsia': '''
@layoutLinkColor: #b509b5;
@mastheadBackgroundColorStart: #dc0bdc;
@mastheadBackgroundColorEnd: #f31df3;
@btnPrimaryBackground: #f544f5;
@btnPrimaryBackgroundHighlight: #f76bf7;
''',

'green': '''
@layoutLinkColor: #045b04;
@mastheadBackgroundColorStart: #068106;
@mastheadBackgroundColorEnd: #08a808;
@btnPrimaryBackground: #0acf0a;
@btnPrimaryBackgroundHighlight: #10f210
''',

'red': '''
@layoutLinkColor: #b50909;
@mastheadBackgroundColorStart: #dc0b0b;
@mastheadBackgroundColorEnd: #f31d1d;
@btnPrimaryBackground: #f54444;
@btnPrimaryBackgroundHighlight: #f76b6b;
''',

'maroon': '''
@layoutLinkColor: #5b0404;
@mastheadBackgroundColorStart: #810606;
@mastheadBackgroundColorEnd: #a80808;
@btnPrimaryBackground: #cf0a0a;
@btnPrimaryBackgroundHighlight: #f21010;
''',
}
def less(self):
''' Compile less files '''
import subprocess
command = 'npm bin'
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
output = process.communicate()
directory = output[0].strip()
less_bin = os.path.join(directory, 'lessc')

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:
f = open(custom_less, 'w')
f.write(self.custom_css[color])
f.close()
self.compile_less(root, less_bin, color)
f = open(custom_less, 'w')
f.write('// This file is needed in order for ./bin/less to compile in less 1.3.1+\n')
f.close()
self.compile_less(root, less_bin, 'main')



def compile_less(self, root, less_bin, color):
print 'compile %s.css' % color
import subprocess
main_less = os.path.join(root, 'less', 'main.less')
main_css = os.path.join(root, 'css', '%s.css' % color)

command = '%s %s %s' % (less_bin, main_less, main_css)

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



class FrontEndBuildCommand(CkanCommand):
''' Creates and minifies css and JavaScript files
Usage:
paster front-end-build
'''

summary = __doc__.split('\n')[0]
usage = __doc__
min_args = 0

def command(self):
self._load_config()

# Less css
cmd = LessCommand('less')
cmd.command()

# js translation strings
cmd = TranslationsCommand('trans')
cmd.options = self.options
cmd.args = ('js',)
cmd.command()

# minification
cmd = MinifyCommand('minify')
cmd.options = self.options
root = os.path.join(os.path.dirname(__file__), '..', 'public', 'base')
root = os.path.abspath(root)
cmd.args = (root,)
cmd.command()
2 changes: 2 additions & 0 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -220,6 +220,7 @@ def package_dictize(pkg, context):
q = q.where(resource_group.c.package_id == pkg.id)
result = _execute_with_revision(q, res_rev, context)
result_dict["resources"] = resource_list_dictize(result, context)
result_dict['num_resources'] = len(result_dict.get('resources', []))

#tags
tag_rev = model.package_tag_revision_table
Expand All @@ -229,6 +230,7 @@ def package_dictize(pkg, context):
).where(tag_rev.c.package_id == pkg.id)
result = _execute_with_revision(q, tag_rev, context)
result_dict["tags"] = d.obj_list_dictize(result, context, lambda x: x["name"])
result_dict['num_tags'] = len(result_dict.get('tags', []))

# Add display_names to tags. At first a tag's display_name is just the
# same as its name, but the display_name might get changed later (e.g.
Expand Down

0 comments on commit d5e0155

Please sign in to comment.