mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
layerindex/models: add BBClassRecipe BBClassGlobal
Add support for classes-global and classes-recipe, but use "proxy=True" to not create new tables for the new classes. Rather, we use the bbclass_type field. [YOCTO #15238] Signed-off-by: Tim Orling <tim.orling@konsulko.com>
This commit is contained in:
parent
83378f2f9c
commit
c2a8e07020
|
@ -0,0 +1,41 @@
|
|||
# Generated by Django 4.2.9 on 2024-01-20 21:20
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("layerindex", "0047_layerbranch_updates_enabled"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="BBClassGlobal",
|
||||
fields=[],
|
||||
options={
|
||||
"proxy": True,
|
||||
"indexes": [],
|
||||
"constraints": [],
|
||||
},
|
||||
bases=("layerindex.bbclass",),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="BBClassRecipe",
|
||||
fields=[],
|
||||
options={
|
||||
"proxy": True,
|
||||
"indexes": [],
|
||||
"constraints": [],
|
||||
},
|
||||
bases=("layerindex.bbclass",),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="bbclass",
|
||||
name="bbclass_type",
|
||||
field=models.CharField(
|
||||
choices=[("", "Class"), ("Global", "Global"), ("Recipe", "Recipe")],
|
||||
default="",
|
||||
max_length=25,
|
||||
),
|
||||
),
|
||||
]
|
|
@ -784,18 +784,59 @@ class BBAppend(models.Model):
|
|||
class BBClass(models.Model):
|
||||
layerbranch = models.ForeignKey(LayerBranch, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=100)
|
||||
# Type field
|
||||
TYPE_CHOICES = [
|
||||
('', 'Class'),
|
||||
('Global', 'Global'),
|
||||
('Recipe', 'Recipe')
|
||||
]
|
||||
bbclass_type = models.CharField(max_length=25, choices=TYPE_CHOICES, default='')
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Class"
|
||||
verbose_name_plural = "Classes"
|
||||
|
||||
def vcs_web_url(self):
|
||||
# We cannot override vcs_web_url in the sub-classes without defining self.url
|
||||
# but we want url to be dynamic
|
||||
if self.bbclass_type == 'Global':
|
||||
url = self.layerbranch.file_url(os.path.join('classes-global', "%s.bbclass" % self.name))
|
||||
elif self.bbclass_type == 'Recipe':
|
||||
url = self.layerbranch.file_url(os.path.join('classes-recipe', "%s.bbclass" % self.name))
|
||||
else:
|
||||
url = self.layerbranch.file_url(os.path.join('classes', "%s.bbclass" % self.name))
|
||||
return url or ''
|
||||
|
||||
def __str__(self):
|
||||
return '%s (%s)' % (self.name, self.layerbranch.layer.name)
|
||||
|
||||
class BBClassGlobalManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(bbclass_type='Global')
|
||||
|
||||
class BBClassGlobal(BBClass):
|
||||
objects = BBClassGlobalManager()
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.bbclass_type = 'Global'
|
||||
return super(BBClassGlobal, self).save(*args, **kwargs)
|
||||
|
||||
class BBClassRecipeManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(bbclass_type='Recipe')
|
||||
|
||||
class BBClassRecipe(BBClass):
|
||||
objects = BBClassRecipeManager()
|
||||
|
||||
class Meta:
|
||||
proxy = True
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.bbclass_type = 'Recipe'
|
||||
return super(BBClassRecipe, self).save(*args, **kwargs)
|
||||
|
||||
class IncFile(models.Model):
|
||||
layerbranch = models.ForeignKey(LayerBranch, on_delete=models.CASCADE)
|
||||
|
|
Loading…
Reference in New Issue
Block a user