Skip to content

Commit

Permalink
Merge branch 'master' into feature-2536-clean-activity-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Aug 6, 2012
2 parents 548de8e + b04aa65 commit 1593e75
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ckan/controllers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _form_to_db_schema(self, group_type=None):
def _db_to_form_schema(self, group_type=None):
'''This is an interface to manipulate data from the database
into a format suitable for the form (optional)'''
return lookup_group_plugin(group_type).form_to_db_schema()
return lookup_group_plugin(group_type).db_to_form_schema()

def _setup_template_variables(self, context, data_dict, group_type=None):
return lookup_group_plugin(group_type).\
Expand Down Expand Up @@ -100,7 +100,7 @@ def read(self, id):
group_type = self._get_group_type(id.split('@')[0])
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'schema': self._form_to_db_schema(group_type=group_type),
'schema': self._db_to_form_schema(group_type=group_type),
'for_view': True, 'extras_as_string': True}
data_dict = {'id': id}
# unicode format (decoded from utf8)
Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def get_metadata(self, label):
qualified=False
)
if url.startswith('/'):
url = config.get('ckan.site_url','') + url
url = config.get('ckan.site_url','').rstrip('/') + '/' + url

if not self.ofs.exists(bucket, label):
abort(404)
Expand Down
18 changes: 12 additions & 6 deletions ckan/lib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,6 @@ def history_template(self):
def group_form(self):
return 'group/new_group_form.html'

def form_to_db_schema(self):
return logic.schema.group_form_schema()

def form_to_db_schema_options(self, options):
''' This allows us to select different schemas for different
purpose eg via the web interface or via the api or creation vs
Expand All @@ -366,11 +363,20 @@ def form_to_db_schema_options(self, options):

if options.get('api'):
if options.get('type') == 'create':
return logic.schema.default_group_schema()
return self.form_to_db_schema_api_create()
else:
return logic.schema.default_update_group_schema()
return self.form_to_db_schema_api_update()
else:
return logic.schema.group_form_schema()
return self.form_to_db_schema()

def form_to_db_schema_api_create(self):
return logic.schema.default_group_schema()

def form_to_db_schema_api_update(self):
return logic.schema.default_update_group_schema()

def form_to_db_schema(self):
return logic.schema.group_form_schema()

def db_to_form_schema(self):
'''This is an interface to manipulate data from the database
Expand Down
8 changes: 8 additions & 0 deletions ckan/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ def group_create(context, data_dict):
except AttributeError:
schema = group_plugin.form_to_db_schema()

if 'api_version' not in context:
# old plugins do not support passing the schema so we need
# to ensure they still work
try:
group_plugin.check_data_dict(data_dict, schema)
except TypeError:
group_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
log.debug('group_create validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'), data_dict.get('name'), data_dict)
Expand Down
4 changes: 2 additions & 2 deletions ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ def _follower_list(context, data_dict, FollowerClass):
users = [user for user in users if user is not None]

# Dictize the list of User objects.
return [model_dictize.user_dictize(user,context) for user in users]
return model_dictize.user_list_dictize(users, context)

def user_follower_list(context, data_dict):
'''Return the list of users that are following the given user.
Expand Down Expand Up @@ -2052,7 +2052,7 @@ def user_followee_list(context, data_dict):
users = [user for user in users if user is not None]

# Dictize the list of User objects.
return [model_dictize.user_dictize(user, context) for user in users]
return model_dictize.user_list_dictize(users, context)

def dataset_followee_list(context, data_dict):
'''Return the list of datasets that are followed by the given user.
Expand Down
8 changes: 8 additions & 0 deletions ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ def group_update(context, data_dict):

_check_access('group_update', context, data_dict)

if 'api_version' not in context:
# old plugins do not support passing the schema so we need
# to ensure they still work
try:
group_plugin.check_data_dict(data_dict, schema)
except TypeError:
group_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
log.debug('group_update validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'),
Expand Down
1 change: 1 addition & 0 deletions ckan/logic/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def db_to_form_package_schema():
# TODO: Fix this elsewhere so we don't need to workaround it here.
schema['resources'].update({
'created': [ckan.lib.navl.validators.ignore_missing],
'position': [not_empty],
'last_modified': [ckan.lib.navl.validators.ignore_missing],
'cache_last_updated': [ckan.lib.navl.validators.ignore_missing],
'webstore_last_updated': [ckan.lib.navl.validators.ignore_missing],
Expand Down
4 changes: 2 additions & 2 deletions ckan/public/scripts/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ CKAN.Templates.resourceDetails = ' \
CKAN.Templates.resourceExtra = ' \
<div class="dynamic-extra"> \
<button class="btn btn-danger remove-resource-extra">X</button>\
<input type="text" placeholder="Key" class="extra-key" value="${key}" /> \
<input type="text" placeholder="Value" class="extra-value" value="${value}" /> \
<input type="text" placeholder="'+CKAN.Strings.key+'" class="extra-key" value="${key}" /> \
<input type="text" placeholder="'+CKAN.Strings.value+'" class="extra-value" value="${value}" /> \
</div> \
';
2 changes: 2 additions & 0 deletions ckan/templates/js_strings.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
unknown = _('Unknown'),
extraFields = _('Extra Fields'),
addExtraField = _('Add Extra Field'),
key = _('Key'),
value = _('Value'),
deleteResource = _('Delete Resource'),
youCanUseMarkdown = _('You can use %aMarkdown formatting%b here.'),
datesAreInISO = _('Dates are in %aISO Format%b &mdash; eg. %c2012-12-25%d or %c2010-05-31T14:30%d.'),
Expand Down

0 comments on commit 1593e75

Please sign in to comment.