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):
|
def iter_resources(self, objs, split_path):
|
||||||
if Radio in objs:
|
if Radio in objs:
|
||||||
if len(split_path) > 0:
|
self._restrict_level(split_path)
|
||||||
raise CollectionNotFound(split_path)
|
|
||||||
|
|
||||||
for id in self._RADIOS.iterkeys():
|
for id in self._RADIOS.iterkeys():
|
||||||
yield self.get_radio(id)
|
yield self.get_radio(id)
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,7 @@ class OuiFMBackend(BaseBackend, ICapRadio, ICapCollection):
|
||||||
|
|
||||||
def iter_resources(self, objs, split_path):
|
def iter_resources(self, objs, split_path):
|
||||||
if Radio in objs:
|
if Radio in objs:
|
||||||
if len(split_path) > 0:
|
self._restrict_level(split_path)
|
||||||
raise CollectionNotFound(split_path)
|
|
||||||
|
|
||||||
for id in self._RADIOS.iterkeys():
|
for id in self._RADIOS.iterkeys():
|
||||||
yield self.get_radio(id)
|
yield self.get_radio(id)
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,7 @@ class RadioFranceBackend(BaseBackend, ICapRadio, ICapCollection, ICapVideo):
|
||||||
for _id in sorted(self._RADIOS.iterkeys()):
|
for _id in sorted(self._RADIOS.iterkeys()):
|
||||||
if not _id.startswith('fb'):
|
if not _id.startswith('fb'):
|
||||||
yield self.get_radio(_id)
|
yield self.get_radio(_id)
|
||||||
yield Collection(['francebleu'], 'France Bleu')
|
yield Collection([u'francebleu'], u'France Bleu')
|
||||||
else:
|
else:
|
||||||
raise CollectionNotFound(split_path)
|
raise CollectionNotFound(split_path)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,17 +96,15 @@ class RedmineBackend(BaseBackend, ICapContent, ICapBugTracker, ICapCollection):
|
||||||
############# CapCollection ###################################################
|
############# CapCollection ###################################################
|
||||||
def iter_resources(self, objs, split_path):
|
def iter_resources(self, objs, split_path):
|
||||||
if Project in objs or Issue in objs:
|
if Project in objs or Issue in objs:
|
||||||
|
self._restrict_level(split_path, 1)
|
||||||
if len(split_path) == 0:
|
if len(split_path) == 0:
|
||||||
return [Collection([project.id], project.name)
|
return [Collection([project.id], project.name)
|
||||||
for project in self.iter_projects()]
|
for project in self.iter_projects()]
|
||||||
|
elif len(split_path) == 1:
|
||||||
if len(split_path) == 1:
|
|
||||||
query = Query()
|
query = Query()
|
||||||
query.project = unicode(split_path[0])
|
query.project = unicode(split_path[0])
|
||||||
return self.iter_issues(query)
|
return self.iter_issues(query)
|
||||||
|
|
||||||
raise CollectionNotFound(split_path)
|
|
||||||
|
|
||||||
def validate_collection(self, objs, collection):
|
def validate_collection(self, objs, collection):
|
||||||
if len(collection.split_path) == 0:
|
if len(collection.split_path) == 0:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,7 @@ class Transfer(CapBaseObject):
|
||||||
class ICapBank(ICapCollection):
|
class ICapBank(ICapCollection):
|
||||||
def iter_resources(self, objs, split_path):
|
def iter_resources(self, objs, split_path):
|
||||||
if Account in objs:
|
if Account in objs:
|
||||||
if len(split_path) > 0:
|
self._restrict_level(split_path)
|
||||||
raise CollectionNotFound(split_path)
|
|
||||||
|
|
||||||
return self.iter_accounts()
|
return self.iter_accounts()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,7 @@ class Subscription(CapBaseObject):
|
||||||
class ICapBill(ICapCollection):
|
class ICapBill(ICapCollection):
|
||||||
def iter_resources(self, objs, split_path):
|
def iter_resources(self, objs, split_path):
|
||||||
if Subscription in objs:
|
if Subscription in objs:
|
||||||
if len(split_path) > 0:
|
self._restrict_level(split_path)
|
||||||
raise CollectionNotFound(split_path)
|
|
||||||
|
|
||||||
return self.iter_subscription()
|
return self.iter_subscription()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,3 +100,7 @@ class ICapCollection(IBaseCap):
|
||||||
i.next()
|
i.next()
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
raise CollectionNotFound(collection.split_path)
|
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