mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
Add ability to store extra URLs to be displayed for comparison recipes
Add a structure that lets you define a template URL per layer to be shown per comparison recipe. For example, you could use this to define a URL template to link to the upstream summary page for the package (e.g. Fedora's page for the acl package is at https://apps.fedoraproject.org/packages/acl, so you would use https://apps.fedoraproject.org/packages/%pn% as the template and then this would be shown for every package). Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
fb2907a5d8
commit
383d043f1e
|
@ -196,6 +196,7 @@ admin.site.register(Distro, DistroAdmin)
|
|||
admin.site.register(BBAppend, BBAppendAdmin)
|
||||
admin.site.register(BBClass, BBClassAdmin)
|
||||
admin.site.register(Patch)
|
||||
admin.site.register(LayerRecipeExtraURL)
|
||||
admin.site.register(RecipeChangeset, RecipeChangesetAdmin)
|
||||
admin.site.register(ClassicRecipe, ClassicRecipeAdmin)
|
||||
admin.site.register(PythonEnvironment)
|
||||
|
|
26
layerindex/migrations/0018_layerrecipeextraurl.py
Normal file
26
layerindex/migrations/0018_layerrecipeextraurl.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.12 on 2018-05-15 04:10
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('layerindex', '0017_classicrecipe_needs_attention'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='LayerRecipeExtraURL',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(help_text='Name to display for link', max_length=50)),
|
||||
('url', models.CharField(help_text='Template for URL to link to (macros: %pn% %pv% %branch% %actual_branch%)', max_length=255, verbose_name='URL')),
|
||||
('layer', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='layerindex.LayerItem')),
|
||||
],
|
||||
options={'verbose_name': 'Layer Recipe Extra URL'},
|
||||
),
|
||||
]
|
|
@ -11,6 +11,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.core.validators import URLValidator
|
||||
from django.db.models.signals import pre_save
|
||||
from django.dispatch import receiver
|
||||
from collections import namedtuple
|
||||
import os.path
|
||||
import re
|
||||
import posixpath
|
||||
|
@ -180,6 +181,27 @@ class LayerItem(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class LayerRecipeExtraURL(models.Model):
|
||||
layer = models.ForeignKey(LayerItem)
|
||||
name = models.CharField(max_length=50, help_text='Name to display for link')
|
||||
url = models.CharField('URL', max_length=255, help_text='Template for URL to link to (macros: %pn% %pv% %branch% %actual_branch%)')
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Layer Recipe Extra URL"
|
||||
|
||||
def render_url(self, recipe):
|
||||
url = self.url
|
||||
url = url.replace('%pn%', recipe.pn)
|
||||
url = url.replace('%pv%', recipe.pv)
|
||||
url = url.replace('%branch%', recipe.layerbranch.branch.name)
|
||||
url = url.replace('%actual_branch%', recipe.layerbranch.actual_branch)
|
||||
return url
|
||||
|
||||
def __str__(self):
|
||||
return '%s - %s' % (self.layer.name, self.name)
|
||||
|
||||
|
||||
class YPCompatibleVersion(models.Model):
|
||||
name = models.CharField('Yocto Project Version', max_length=25, unique=True, help_text='Name of this Yocto Project compatible version (e.g. "2.0")')
|
||||
description = models.TextField(blank=True)
|
||||
|
@ -437,6 +459,12 @@ class Recipe(models.Model):
|
|||
else:
|
||||
return None
|
||||
|
||||
def extra_urls(self):
|
||||
ExtraURL = namedtuple('ExtraURL', 'name url')
|
||||
for item in self.layerbranch.layer.layerrecipeextraurl_set.all():
|
||||
eu = ExtraURL(name=item.name, url=item.render_url(self))
|
||||
yield eu
|
||||
|
||||
def __str__(self):
|
||||
return os.path.join(self.filepath, self.filename)
|
||||
|
||||
|
|
|
@ -85,6 +85,18 @@
|
|||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% if recipe.extra_urls %}
|
||||
<tr>
|
||||
<th>Extra links</th>
|
||||
<td>
|
||||
<ul class="unstyled">
|
||||
{% for extra_url in recipe.extra_urls %}
|
||||
<li><a href="{{ extra_url.url }}">{{ extra_url.name }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user