add Package.home_repo

This commit is contained in:
Laura Klünder 2016-09-12 15:03:02 +02:00
parent 0f4cf9fb90
commit 558e145572
3 changed files with 29 additions and 3 deletions

View file

@ -23,7 +23,7 @@ class LevelSerializer(ModelSerializer):
class PackageSerializer(BoundsMixin, ModelSerializer):
class Meta:
model = Package
fields = ('name', 'depends')
fields = ('name', 'home_repo', 'depends')
def to_representation(self, obj):
result = super().to_representation(obj)

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.9 on 2016-09-12 13:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('mapdata', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='package',
name='home_repo',
field=models.URLField(null=True, verbose_name='URL to the home git repository'),
),
]

View file

@ -11,6 +11,7 @@ class Package(models.Model):
name = models.SlugField(_('package identifier'), primary_key=True, max_length=50,
help_text=_('e.g. de.c3nav.33c3.base'))
depends = models.ManyToManyField('Package')
home_repo = models.URLField(_('URL to the home git repository'), null=True)
bottom = models.DecimalField(_('bottom coordinate'), null=True, max_digits=6, decimal_places=2)
left = models.DecimalField(_('left coordinate'), null=True, max_digits=6, decimal_places=2)
@ -34,6 +35,9 @@ class Package(models.Model):
raise TypeError('pkg.json: depends has to be a list')
kwargs['depends'] = depends
if 'home_repo' in data:
kwargs['home_repo'] = data['home_repo']
if 'bounds' in data:
bounds = data['bounds']
if len(bounds) != 2 or len(bounds[0]) != 2 or len(bounds[1]) != 2:
@ -53,10 +57,12 @@ class Package(models.Model):
def tofile(self):
data = OrderedDict()
data['name'] = self.name
if self.bottom is not None:
data['bounds'] = ((float(self.bottom), float(self.left)), (float(self.top), float(self.right)))
if self.home_repo is not None:
data['home_repo'] = self.home_repo
if self.depends.exists():
data['depends'] = tuple(package.name for package in self.depends.all().order_by('name'))
if self.bottom is not None:
data['bounds'] = ((float(self.bottom), float(self.left)), (float(self.top), float(self.right)))
return data