Skip to content

Commit

Permalink
Merge branch 'master' into feature-1781-add-term-translation-table
Browse files Browse the repository at this point in the history
  • Loading branch information
kindly committed Feb 13, 2012
2 parents c99ff1b + 2f78970 commit 0decb55
Show file tree
Hide file tree
Showing 50 changed files with 617 additions and 322 deletions.
2 changes: 1 addition & 1 deletion ckan/__init__.py
@@ -1,4 +1,4 @@
__version__ = '1.5.2a'
__version__ = '1.6.1a'
__description__ = 'Comprehensive Knowledge Archive Network (CKAN) Software'
__long_description__ = \
'''CKAN software provides a hub for datasets. The flagship site running CKAN
Expand Down
4 changes: 2 additions & 2 deletions ckan/config/deployment.ini_tmpl
Expand Up @@ -52,8 +52,8 @@ who.log_file = %(cache_dir)s/who_log.ini
# Location of RDF versions of datasets
#rdf_packages = http://semantic.ckan.net/record/

# Location of licenses group (defaults to local Python licenses dataset)
#licenses_group_url = http://licenses.opendefinition.org/2.0/ckan_original
# Location of licenses group (defaults to cached local version of ckan group)
#licenses_group_url = http://licenses.opendefinition.org/licenses/groups/ckan.json

# Dataset form to use
package_form = standard
Expand Down
2 changes: 0 additions & 2 deletions ckan/controllers/user.py
Expand Up @@ -103,8 +103,6 @@ def read(self, id=None):
c.about_formatted = self._format_about(user_dict['about'])
c.user_activity_stream = user_activity_list_html(context,
{'id':c.user_dict['id']})

c.created_formatted = h.date_str_to_datetime(user_dict['created']).strftime('%b %d, %Y')
return render('user/read.html')

def me(self):
Expand Down
14 changes: 13 additions & 1 deletion ckan/lib/base.py
Expand Up @@ -87,6 +87,18 @@ def __before__(self, action, **params):
i18n.handle_request(request, c)

def _identify_user(self):
'''
Identifies the user using two methods:
a) If he has logged into the web interface then repoze.who will
set REMOTE_USER.
b) For API calls he may set a header with his API key.
If the user is identified then:
c.user = user name (unicode)
c.author = user name
otherwise:
c.user = None
c.author = user\'s IP address (unicode)
'''
# see if it was proxied first
c.remote_addr = request.environ.get('HTTP_X_FORWARDED_FOR', '')
if not c.remote_addr:
Expand All @@ -98,7 +110,7 @@ def _identify_user(self):
c.user = c.user.decode('utf8')
c.userobj = model.User.by_name(c.user)
if c.userobj is None:
# This occurs when you are logged in with openid, clean db
# This occurs when you are logged in, clean db
# and then restart i.e. only really for testers. There is no
# user object, so even though repoze thinks you are logged in
# and your cookie has ckan_display_name, we need to force user
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/create_test_data.py
Expand Up @@ -546,7 +546,7 @@ def get_all_data(cls):
'format':'DOC',
'description':'http://www.statistics.gov.uk/hub/id/119-34565'}],
'groups':'ukgov test1 test2 penguin',
'license':'gpl-3.0',
'license':'odc-by',
'notes':u'''From <http://www.gpoaccess.gov/gils/about.html>
> The Government Information Locator Service (GILS) is an effort to identify, locate, and describe publicly available Federal
Expand Down
12 changes: 8 additions & 4 deletions ckan/lib/dictization/model_save.py
Expand Up @@ -281,10 +281,14 @@ def package_dict_save(pkg_dict, context):
package_tag_list_save(pkg_dict.get("tags", []), pkg, context)
package_membership_list_save(pkg_dict.get("groups", []), pkg, context)

subjects = pkg_dict.get('relationships_as_subject', [])
relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
objects = pkg_dict.get('relationships_as_object', [])
relationship_list_save(subjects, pkg, 'relationships_as_object', context)
# relationships are not considered 'part' of the package, so only
# process this if the key is provided
if 'relationships_as_subject' in pkg_dict:
subjects = pkg_dict.get('relationships_as_subject', [])
relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
if 'relationships_as_object' in pkg_dict:
objects = pkg_dict.get('relationships_as_object', [])
relationship_list_save(objects, pkg, 'relationships_as_object', context)

extras = package_extras_save(pkg_dict.get("extras", []), pkg, context)

Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/hash.py
Expand Up @@ -12,7 +12,7 @@ def get_message_hash(value):
# avoid getting config value at module scope since config may
# not be read in yet
secret = config['beaker.session.secret']
return hmac.new(secret, value, hashlib.sha1).hexdigest()
return hmac.new(secret, value.encode('utf8'), hashlib.sha1).hexdigest()

def get_redirect():
'''Checks the return_to value against the hash, and if it
Expand Down
16 changes: 8 additions & 8 deletions ckan/lib/helpers.py
Expand Up @@ -204,10 +204,7 @@ def linked_user(user, maxlength=0):
return user_name
if user:
_name = user.name if model.User.VALID_NAME.match(user.name) else user.id
# Absolute URL of default user icon
from pylons import config
_icon_url_default = icon_url("user")
_icon = gravatar(user.email_hash, 16, _icon_url_default)+" "
_icon = gravatar(user.email_hash, 20)
displayname = user.display_name
if maxlength and len(user.display_name) > maxlength:
displayname = displayname[:maxlength] + '...'
Expand Down Expand Up @@ -252,14 +249,14 @@ def icon_html(url, alt=None):
def icon(name, alt=None):
return icon_html(icon_url(name),alt)

def linked_gravatar(email_hash, size=100, default="mm"):
def linked_gravatar(email_hash, size=100, default="identicon"):
return literal('''<a href="https://gravatar.com/" target="_blank"
title="Update your avatar at gravatar.com">
%s</a>''' %
gravatar(email_hash,size,default)
)

def gravatar(email_hash, size=100, default="mm"):
def gravatar(email_hash, size=100, default="identicon"):
return literal('''<img src="http://gravatar.com/avatar/%s?s=%d&amp;d=%s"
class="gravatar" />'''
% (email_hash, size, default)
Expand All @@ -284,12 +281,15 @@ def pager(self, *args, **kwargs):
)
return super(Page, self).pager(*args, **kwargs)

def render_datetime(datetime_, date_format='%Y-%m-%d %H:%M'):
def render_datetime(datetime_, date_format=None, with_hours=False):
'''Render a datetime object or timestamp string as a pretty string
(Y-m-d H:m).
If timestamp is badly formatted, then a blank string is returned.
'''
from ckan import model
if not date_format:
date_format = '%b %d, %Y'
if with_hours:
date_format += ', %H:%M'
if isinstance(datetime_, datetime.datetime):
return datetime_.strftime(date_format)
elif isinstance(datetime_, basestring):
Expand Down
2 changes: 1 addition & 1 deletion ckan/lib/search/__init__.py
Expand Up @@ -127,7 +127,7 @@ def rebuild(package=None):
else:
# rebuild index
package_index.clear()
for pkg in model.Session.query(model.Package).all():
for pkg in model.Session.query(model.Package).filter(model.Package.state == 'active').all():
package_index.insert_dict(
get_action('package_show_rest')(
{'model': model, 'ignore_auth': True},
Expand Down
17 changes: 11 additions & 6 deletions ckan/logic/validators.py
@@ -1,5 +1,6 @@
import re
import datetime
from itertools import count
import re
from pylons.i18n import _, ungettext, N_, gettext
from ckan.lib.navl.dictization_functions import Invalid, Missing, missing, unflatten
from ckan.authz import Authorizer
Expand Down Expand Up @@ -268,13 +269,17 @@ def tag_string_convert(key, data, errors, context):
'''Takes a list of tags that is a comma-separated string (in data[key])
and parses tag names. These are added to the data dict, enumerated. They
are also validated.'''
tag_string = data[key]

tags = [tag.strip() \
for tag in tag_string.split(',') \
if tag.strip()]
if isinstance(data[key], basestring):
tags = [tag.strip() \
for tag in data[key].split(',') \
if tag.strip()]
else:
tags = data[key]

current_index = max( [int(k[1]) for k in data.keys() if len(k) == 3 and k[0] == 'tags'] + [-1] )

for num, tag in enumerate(tags):
for num, tag in zip(count(current_index+1), tags):
data[('tags', num, 'name')] = tag

for tag in tags:
Expand Down

0 comments on commit 0decb55

Please sign in to comment.