Fix some collecton validation
And add restrict_level helper method.
This commit is contained in:
parent
e70a125ab9
commit
1430b40bc5
7 changed files with 11 additions and 13 deletions
|
|
@ -64,8 +64,7 @@ class NovaBackend(BaseBackend, ICapRadio, ICapCollection):
|
|||
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Radio in objs:
|
||||
if len(split_path) > 0:
|
||||
raise CollectionNotFound(split_path)
|
||||
self._restrict_level(split_path)
|
||||
|
||||
for id in self._RADIOS.iterkeys():
|
||||
yield self.get_radio(id)
|
||||
|
|
|
|||
|
|
@ -48,8 +48,7 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
|||
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Radio in objs:
|
||||
if len(split_path) > 0:
|
||||
raise CollectionNotFound(split_path)
|
||||
self._restrict_level(split_path)
|
||||
|
||||
for id in self._RADIOS.iterkeys():
|
||||
yield self.get_radio(id)
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class RadioFranceBackend(BaseBackend, ICapRadio, ICapCollection, ICapVideo):
|
|||
for _id in sorted(self._RADIOS.iterkeys()):
|
||||
if not _id.startswith('fb'):
|
||||
yield self.get_radio(_id)
|
||||
yield Collection(['francebleu'], 'France Bleu')
|
||||
yield Collection([u'francebleu'], u'France Bleu')
|
||||
else:
|
||||
raise CollectionNotFound(split_path)
|
||||
|
||||
|
|
|
|||
|
|
@ -96,17 +96,15 @@ class RedmineBackend(BaseBackend, ICapContent, ICapBugTracker, ICapCollection):
|
|||
############# CapCollection ###################################################
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Project in objs or Issue in objs:
|
||||
self._restrict_level(split_path, 1)
|
||||
if len(split_path) == 0:
|
||||
return [Collection([project.id], project.name)
|
||||
for project in self.iter_projects()]
|
||||
|
||||
if len(split_path) == 1:
|
||||
elif len(split_path) == 1:
|
||||
query = Query()
|
||||
query.project = unicode(split_path[0])
|
||||
return self.iter_issues(query)
|
||||
|
||||
raise CollectionNotFound(split_path)
|
||||
|
||||
def validate_collection(self, objs, collection):
|
||||
if len(collection.split_path) == 0:
|
||||
return
|
||||
|
|
|
|||
|
|
@ -96,8 +96,7 @@ class Transfer(CapBaseObject):
|
|||
class ICapBank(ICapCollection):
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Account in objs:
|
||||
if len(split_path) > 0:
|
||||
raise CollectionNotFound(split_path)
|
||||
self._restrict_level(split_path)
|
||||
|
||||
return self.iter_accounts()
|
||||
|
||||
|
|
|
|||
|
|
@ -56,8 +56,7 @@ class Subscription(CapBaseObject):
|
|||
class ICapBill(ICapCollection):
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Subscription in objs:
|
||||
if len(split_path) > 0:
|
||||
raise CollectionNotFound(split_path)
|
||||
self._restrict_level(split_path)
|
||||
|
||||
return self.iter_subscription()
|
||||
|
||||
|
|
|
|||
|
|
@ -100,3 +100,7 @@ class ICapCollection(IBaseCap):
|
|||
i.next()
|
||||
except StopIteration:
|
||||
raise CollectionNotFound(collection.split_path)
|
||||
|
||||
def _restrict_level(self, split_path, lmax=0):
|
||||
if len(split_path) > lmax:
|
||||
raise CollectionNotFound(split_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue