Skip to content

Commit

Permalink
[#1081] Add new get_package_id() method to Resource
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Jul 3, 2013
1 parent 50ba9bf commit fe79fed
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ckan/model/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ def as_dict(self, core_columns_only=False):
_dict[u'format'] = model_dictize._unified_resource_format(self.format)
return _dict

def get_package_id(self):
'''Returns the package id for a resource. '''
query = meta.Session.query(ResourceGroupRevision) \
.filter(and_(ResourceGroupRevision.id==self.resource_group_id,
ResourceGroupRevision.state == u'active',
ResourceGroupRevision.current == True))
resource_group = query.first()
if resource_group is None:
return None
return resource_group.package_id

@classmethod
def get(cls, reference):
'''Returns a resource object referenced by its name or id.'''
Expand Down

0 comments on commit fe79fed

Please sign in to comment.