summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/orm/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
-rw-r--r--bitbake/lib/toaster/orm/models.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 0174233498..4a868e7ded 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -91,18 +91,25 @@ class ProjectManager(models.Manager):
91 91
92 return prj 92 return prj
93 93
94 def create(self, *args, **kwargs):
95 raise Exception("Invalid call to Project.objects.create. Use Project.objects.create_project() to create a project")
96
97 # return single object with is_default = True 94 # return single object with is_default = True
98 def get_default_project(self): 95 def get_or_create_default_project(self):
99 projects = super(ProjectManager, self).filter(is_default = True) 96 projects = super(ProjectManager, self).filter(is_default = True)
97
100 if len(projects) > 1: 98 if len(projects) > 1:
101 raise Exception("Inconsistent project data: multiple " + 99 raise Exception('Inconsistent project data: multiple ' +
102 "default projects (i.e. with is_default=True)") 100 'default projects (i.e. with is_default=True)')
103 elif len(projects) < 1: 101 elif len(projects) < 1:
104 raise Exception("Inconsistent project data: no default project found") 102 options = {
105 return projects[0] 103 'name': 'Command line builds',
104 'short_description': 'Project for builds started outside Toaster',
105 'is_default': True
106 }
107 project = Project.objects.create(**options)
108 project.save()
109
110 return project
111 else:
112 return projects[0]
106 113
107class Project(models.Model): 114class Project(models.Model):
108 search_allowed_fields = ['name', 'short_description', 'release__name', 'release__branch_name'] 115 search_allowed_fields = ['name', 'short_description', 'release__name', 'release__branch_name']