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.orl...@konsulko.com> --- ...obal_bbclassrecipe_bbclass_bbclass_type.py | 41 ++++++++++++++++++ layerindex/models.py | 43 ++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 layerindex/migrations/0048_bbclassglobal_bbclassrecipe_bbclass_bbclass_type.py diff --git a/layerindex/migrations/0048_bbclassglobal_bbclassrecipe_bbclass_bbclass_type.py b/layerindex/migrations/0048_bbclassglobal_bbclassrecipe_bbclass_bbclass_type.py new file mode 100644 index 0000000..dba7927 --- /dev/null +++ b/layerindex/migrations/0048_bbclassglobal_bbclassrecipe_bbclass_bbclass_type.py @@ -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, + ), + ), + ] diff --git a/layerindex/models.py b/layerindex/models.py index 676f05f..c52927f 100644 --- a/layerindex/models.py +++ b/layerindex/models.py @@ -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): - url = self.layerbranch.file_url(os.path.join('classes', "%s.bbclass" % self.name)) + # 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) -- 2.34.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#62233): https://lists.yoctoproject.org/g/yocto/message/62233 Mute This Topic: https://lists.yoctoproject.org/mt/103903654/21656 Group Owner: yocto+ow...@lists.yoctoproject.org Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-