Make collection validation more powerful
Handle and use exceptions. An example is provided with the redmine backend (not very useful though). If you cd into the project title instead of the id, it is accepted and the path is corrected.
This commit is contained in:
parent
5578618b06
commit
e70a125ab9
3 changed files with 44 additions and 22 deletions
|
|
@ -107,15 +107,18 @@ class RedmineBackend(BaseBackend, ICapContent, ICapBugTracker, ICapCollection):
|
|||
|
||||
raise CollectionNotFound(split_path)
|
||||
|
||||
def _is_collection_valid(self, objs, split_path):
|
||||
if len(split_path) == 0:
|
||||
return True
|
||||
if Issue in objs and len(split_path) == 1:
|
||||
for project in self.browser.iter_projects():
|
||||
if split_path[0] in (project['id'], project['name']):
|
||||
return True
|
||||
return self.get_project(split_path[0]) is not None
|
||||
return False
|
||||
def validate_collection(self, objs, collection):
|
||||
if len(collection.split_path) == 0:
|
||||
return
|
||||
if Issue in objs and len(collection.split_path) == 1:
|
||||
for project in self.iter_projects():
|
||||
if collection.split_path[0] == project.id:
|
||||
return Collection([project.id], project.name)
|
||||
# if the project is not found by ID, try again by name
|
||||
for project in self.iter_projects():
|
||||
if collection.split_path[0] == project.name:
|
||||
return Collection([project.id], project.name)
|
||||
raise CollectionNotFound(collection.split_path)
|
||||
|
||||
############# CapBugTracker ###################################################
|
||||
def _build_project(self, project_dict):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue