Skip to content

Commit

Permalink
clean up imports in actions.delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Feb 29, 2012
1 parent 3837111 commit 36b2cb6
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions ckan/logic/action/delete.py
@@ -1,9 +1,7 @@
from ckan.logic import NotFound, ParameterError, ValidationError
from ckan.lib.base import _
from ckan.logic import check_access
from ckan.logic.action import rename_keys
from pylons.i18n import _

from ckan.plugins import PluginImplementations, IGroupController, IPackageController
import ckan.logic as logic
import ckan.plugins as plugins


def package_delete(context, data_dict):
Expand All @@ -15,15 +13,15 @@ def package_delete(context, data_dict):
entity = model.Package.get(id)

if entity is None:
raise NotFound
raise logic.NotFound

check_access('package_delete',context, data_dict)
logic.check_access('package_delete',context, data_dict)

rev = model.repo.new_revision()
rev.author = user
rev.message = _(u'REST API: Delete Package: %s') % entity.name

for item in PluginImplementations(IPackageController):
for item in plugins.PluginImplementations(plugins.IPackageController):
item.delete(entity)
entity.delete()
model.repo.commit()
Expand All @@ -40,19 +38,19 @@ def package_relationship_delete(context, data_dict):
pkg1 = model.Package.get(id)
pkg2 = model.Package.get(id2)
if not pkg1:
raise NotFound('Subject package %r was not found.' % id)
raise logic.NotFound('Subject package %r was not found.' % id)
if not pkg2:
return NotFound('Object package %r was not found.' % id2)
return logic.NotFound('Object package %r was not found.' % id2)

existing_rels = pkg1.get_relationships_with(pkg2, rel)
if not existing_rels:
raise NotFound
raise logic.NotFound

relationship = existing_rels[0]
revisioned_details = 'Package Relationship: %s %s %s' % (id, rel, id2)

context['relationship'] = relationship
check_access('package_relationship_delete', context, data_dict)
logic.check_access('package_relationship_delete', context, data_dict)

rev = model.repo.new_revision()
rev.author = user
Expand All @@ -70,18 +68,18 @@ def group_delete(context, data_dict):
group = model.Group.get(id)
context['group'] = group
if group is None:
raise NotFound('Group was not found.')
raise logic.NotFound('Group was not found.')

revisioned_details = 'Group: %s' % group.name

check_access('group_delete', context, data_dict)
logic.check_access('group_delete', context, data_dict)

rev = model.repo.new_revision()
rev.author = user
rev.message = _(u'REST API: Delete %s') % revisioned_details
group.delete()

for item in PluginImplementations(IGroupController):
for item in plugins.PluginImplementations(plugins.IGroupController):
item.delete(group)

model.repo.commit()
Expand All @@ -96,9 +94,9 @@ def task_status_delete(context, data_dict):
entity = model.TaskStatus.get(id)

if entity is None:
raise NotFound
raise logic.NotFound

check_access('task_status_delete', context, data_dict)
logic.check_access('task_status_delete', context, data_dict)

entity.delete()
model.Session.commit()
Expand All @@ -108,13 +106,13 @@ def vocabulary_delete(context, data_dict):

vocab_id = data_dict.get('id')
if not vocab_id:
raise ValidationError({'id': _('id not in data')})
raise logic.ValidationError({'id': _('id not in data')})

vocab_obj = model.vocabulary.Vocabulary.get(vocab_id)
if vocab_obj is None:
raise NotFound(_('Could not find vocabulary "%s"') % vocab_id)
raise logic.NotFound(_('Could not find vocabulary "%s"') % vocab_id)

check_access('vocabulary_delete', context, data_dict)
logic.check_access('vocabulary_delete', context, data_dict)

vocab_obj.delete()
model.repo.commit()
Expand All @@ -123,17 +121,17 @@ def tag_delete(context, data_dict):
model = context['model']

if not data_dict.has_key('id') or not data_dict['id']:
raise ValidationError({'id': _('id not in data')})
raise logic.ValidationError({'id': _('id not in data')})
tag_id_or_name = data_dict['id']

vocab_id_or_name = data_dict.get('vocabulary_id')

tag_obj = model.tag.Tag.get(tag_id_or_name, vocab_id_or_name)

if tag_obj is None:
raise NotFound(_('Could not find tag "%s"') % tag_id_or_name)
raise logic.NotFound(_('Could not find tag "%s"') % tag_id_or_name)

check_access('tag_delete', context, data_dict)
logic.check_access('tag_delete', context, data_dict)

tag_obj.delete()
model.repo.commit()
Expand All @@ -148,6 +146,6 @@ def package_relationship_delete_rest(context, data_dict):
# object and rel in the URI overwrite any values for these
# in params. This is because you are not allowed to change
# these values.
data_dict = rename_keys(data_dict, key_map, destructive=True)
data_dict = logic.action.rename_keys(data_dict, key_map, destructive=True)

package_relationship_delete(context, data_dict)

0 comments on commit 36b2cb6

Please sign in to comment.