Add mirror detail URLs to JSON output (#71)

* Add mirror detail URLs to JSON output

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>

* Bump mirror details JSON version to 4

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
This commit is contained in:
Johannes Löthberg 2017-12-30 04:26:23 +01:00 committed by Angel Velásquez
parent 176456e485
commit 860a0511a0
2 changed files with 12 additions and 1 deletions

View File

@ -3,6 +3,7 @@
from urlparse import urlparse
from django.core.exceptions import ValidationError
from django.contrib.sites.models import Site
from django.db import models
from django.db.models.signals import pre_save
from django_countries.fields import CountryField
@ -46,6 +47,10 @@ def downstream(self):
def get_absolute_url(self):
return '/mirrors/%s/' % self.name
def get_full_url(self, proto='https'):
domain = Site.objects.get_current().domain
return '%s://%s%s' % (proto, domain, self.get_absolute_url())
class MirrorProtocol(models.Model):
protocol = models.CharField(max_length=10, unique=True)
@ -111,6 +116,10 @@ def clean(self):
def get_absolute_url(self):
return '/mirrors/%s/%d/' % (self.mirror.name, self.pk)
def get_full_url(self, proto='https'):
domain = Site.objects.get_current().domain
return '%s://%s%s' % (proto, domain, self.get_absolute_url())
class MirrorRsync(models.Model):
# max length is 40 chars for full-form IPv6 addr + subnet

View File

@ -27,6 +27,7 @@ def default(self, obj):
data['country'] = unicode(country.name)
data['country_code'] = country.code
data['isos'] = obj.mirror.isos
data['details'] = obj.get_full_url()
return data
if isinstance(obj, MirrorProtocol):
return unicode(obj)
@ -91,7 +92,8 @@ def mirror_details_json(request, name):
status_info = get_mirror_statuses(mirror_id=mirror.id,
show_all=authorized)
data = status_info.copy()
data['version'] = 3
data['version'] = 4
data['details'] = mirror.get_full_url()
if authorized and request.user.has_perm('mirror.change_mirror'):
data['admin_email'] = mirror.admin_email
data['alternate_email'] = mirror.alternate_email