diff options
| author | Elliot Smith <elliot.smith@intel.com> | 2015-12-09 19:56:29 -0800 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-14 23:13:06 +0000 |
| commit | 7a0c45e478fac9de2bae63544f7e98187ceb59a7 (patch) | |
| tree | 0552588396da878af3f3a0487e3f267fd5ca6268 /bitbake/lib/toaster/orm/models.py | |
| parent | 9de8dfa11a9d0008fd43bd38f81ab3d65b998033 (diff) | |
| download | poky-7a0c45e478fac9de2bae63544f7e98187ceb59a7.tar.gz | |
bitbake: toaster: Create default project with get_or_create* method
Rather than maintain data as part of the migrations (as was
done for the default project previously), create the default
(cli builds) project on demand as a by-product of getting
it from the database.
[YOCTO #8364]
(Bitbake rev: 5fd8e90ab9b81d1bd0d301bc1c91228ecbbea74b)
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: brian avery <avery.brian@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/orm/models.py')
| -rw-r--r-- | bitbake/lib/toaster/orm/models.py | 23 |
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 | ||
| 107 | class Project(models.Model): | 114 | class 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'] |
