Skip to content

Commit

Permalink
[#1506][editresources][m]: Straightened out some glitches.
Browse files Browse the repository at this point in the history
  • Loading branch information
teajaymars committed Feb 23, 2012
1 parent 75528b4 commit aa87ae9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 46 deletions.
51 changes: 7 additions & 44 deletions ckan/controllers/package.py
Expand Up @@ -513,52 +513,15 @@ def edit(self, id, data=None, errors=None, error_summary=None):
c.form = render(self.package_form, extra_vars=vars)
else:
c.form = render(self._package_form(package_type=package_type), extra_vars=vars)
return render('package/edit.html')

def editresources(self, id, data=None, errors=None, error_summary=None):
package_type = self._get_package_type(id)
context = {'model': model, 'session': model.Session,
'user': c.user or c.author, 'extras_as_string': True,
'save': 'save' in request.params,
'moderated': config.get('moderated'),
'pending': True,
'schema': self._form_to_db_schema(package_type=package_type)}

if context['save'] and not data:
return self._save_edit(id, context)
try:
old_data = get_action('package_show')(context, {'id':id})
schema = self._db_to_form_schema(package_type=package_type)
if schema and not data:
old_data, errors = validate(old_data, schema, context=context)
data = data or old_data
# Merge all elements for the complete package dictionary
c.pkg_dict = dict(old_data.items() + data.items())
except NotAuthorized:
abort(401, _('Unauthorized to read package %s') % '')
except NotFound:
abort(404, _('Package not found'))

c.pkg = context.get("package")
c.pkg_json = json.dumps(data)

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

errors = errors or {}
vars = {'data': data, 'errors': errors, 'error_summary': error_summary}

self._setup_template_variables(context, {'id': id}, package_type=package_type)

# TODO: This check is to maintain backwards compatibility with the old way of creating
# custom forms. This behaviour is now deprecated.
if hasattr(self, 'package_form'):
c.form = render(self.package_form, extra_vars=vars)
if (c.action == u'editresources'):
return render('package/editresources.html')
else:
c.form = render(self._package_form(package_type=package_type), extra_vars=vars)
return render('package/editresources.html')
return render('package/edit.html')

def editresources(self, id, data=None, errors=None, error_summary=None):
'''Hook method made available for routing purposes.'''
return self.edit(id,data,errors,error_summary)

def read_ajax(self, id, revision=None):
package_type=self._get_package_type(id)
Expand Down
2 changes: 1 addition & 1 deletion ckan/public/scripts/application.js
Expand Up @@ -651,7 +651,7 @@ CKAN.View.ResourceEditList = Backbone.View.extend({
var resource = $(li).data('resource');
if (resource) {
var $table = resource.view_table;
$.each($table.find('input'), function(input_idx, input) {
$.each($table.find('input,textarea'), function(input_idx, input) {
var name = $(input).attr('name');
name = name.replace(/(resources__)\d+(.*)/, '$1'+li_idx+'$2')
$(input).attr('name',name);
Expand Down
2 changes: 1 addition & 1 deletion ckan/public/scripts/templates.js
Expand Up @@ -96,7 +96,7 @@ CKAN.Templates.resourceTable = ' \
<tr> \
<td class="dataset-label" property="rdfs:label">'+CKAN.Strings.description+'</td> \
<td class="dataset-details" property="rdf:value"> \
<textarea name="resources__${num}__description" type="text" value="${resource.description}" class="long" /> \
<textarea name="resources__${num}__description" type="text">${resource.description}</textarea> \
</td> \
</tr> \
<tr> \
Expand Down

0 comments on commit aa87ae9

Please sign in to comment.