Allow usage URL to point to a file within the repository

This means the usage URL can point to a file whose contents may be
different per branch (e.g. a README file).

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2013-03-04 23:34:30 +00:00
parent 354e368aa2
commit 3f967cf751
3 changed files with 16 additions and 2 deletions

View File

@ -79,7 +79,7 @@
<p>
{% if layeritem.usage_url %}
<span class="label label-info">
<a href="{{ layeritem.usage_url }}">Setup information</a>
<a href="{{ layerbranch.get_usage_url }}">Setup information</a>
</span>
{% endif %}
{% if layeritem.mailing_list_url %}

View File

@ -117,6 +117,13 @@ class EditLayerForm(forms.ModelForm):
val(url)
return url
def clean_usage_url(self):
usage = self.cleaned_data['usage_url'].strip()
if usage.startswith('http'):
val = URLValidator(verify_exists=False)
val(usage)
return usage
class EditNoteForm(forms.ModelForm):
class Meta:

View File

@ -44,7 +44,7 @@ class LayerItem(models.Model):
vcs_web_url = models.URLField('Repository web interface URL', blank=True, help_text='URL of the web interface for browsing the repository, if any')
vcs_web_tree_base_url = models.CharField('Repository web interface tree base URL', max_length=200, blank=True, help_text='Base URL for the web interface for browsing directories within the repository, if any')
vcs_web_file_base_url = models.CharField('Repository web interface file base URL', max_length=200, blank=True, help_text='Base URL for the web interface for viewing files (blobs) within the repository, if any')
usage_url = models.URLField('Usage web page URL', blank=True, help_text='URL of a web page with more information about the layer and how to use it, if any')
usage_url = models.CharField('Usage web page URL', max_length=200, blank=True, help_text='URL of a web page with more information about the layer and how to use it, if any (or path to file within repository)')
mailing_list_url = models.URLField('Mailing list URL', blank=True, help_text='URL of the info page for a mailing list for discussing the layer, if any')
class Meta:
@ -132,6 +132,13 @@ class LayerBranch(models.Model):
def test_file_url(self):
return self.file_url('conf/layer.conf')
def get_usage_url(self):
usage_url = self.layer.usage_url
if usage_url.startswith('http'):
return usage_url
else:
return self.file_url(usage_url)
def __unicode__(self):
return "%s: %s" % (self.layer.name, self.branch.name)