Show source URLs on recipe detail page

If we're collecting this useful info we should really display it. Try to
make the link clickable if possible.

At the same time, add the layerbranch to the list display for Source
objects in the admin site.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-06-22 11:40:40 +12:00
parent 4ee5c21c37
commit bc1757abf3
2 changed files with 31 additions and 1 deletions

View File

@ -478,8 +478,23 @@ class Source(models.Model):
recipe = models.ForeignKey(Recipe)
url = models.CharField(max_length=255)
def web_url(self):
def drop_dotgit(url):
if url.endswith('.git'):
url = url[:-4]
return url
if self.url and self.url.startswith(('http', 'ftp')):
return self.url
elif self.url.startswith('git://github.com'):
return drop_dotgit('https' + self.url[3:])
elif self.url.startswith('git://git.yoctoproject.org'):
return drop_dotgit('https://git.yoctoproject.org/cgit/cgit.cgi' + self.url[26:])
elif self.url.startswith('git://git.kernel.org'):
return 'https' + self.url[3:]
return None
def __str__(self):
return '%s - %s' % (self.recipe.pn, self.url)
return '%s - %s - %s' % (self.recipe.layerbranch, self.recipe.pn, self.url)
class Patch(models.Model):

View File

@ -148,6 +148,21 @@
</tbody>
</table>
<h2>Sources</h2>
{% if recipe.source_set.exists %}
<table class="table table-striped table-bordered">
<tbody>
{% for source in recipe.source_set.all %}
<tr>
<td>{% if source.web_url %}<a href="{{ source.web_url }}">{% endif %}{{ source.url }}{% if source.web_url %}</a>{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>None</p>
{% endif %}
<h2>Patches</h2>
{% if recipe.patch_set.exists %}
<table class="table table-striped table-bordered">