diff --git a/src/c3nav/api/serializers.py b/src/c3nav/api/serializers.py index 0104accb..2642e77d 100644 --- a/src/c3nav/api/serializers.py +++ b/src/c3nav/api/serializers.py @@ -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) diff --git a/src/c3nav/mapdata/migrations/0002_package_home_repo.py b/src/c3nav/mapdata/migrations/0002_package_home_repo.py new file mode 100644 index 00000000..21dfb867 --- /dev/null +++ b/src/c3nav/mapdata/migrations/0002_package_home_repo.py @@ -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'), + ), + ] diff --git a/src/c3nav/mapdata/models/package.py b/src/c3nav/mapdata/models/package.py index 5d6d20d5..1dbbe7db 100644 --- a/src/c3nav/mapdata/models/package.py +++ b/src/c3nav/mapdata/models/package.py @@ -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