Browse Source

Panorama inherit from ReferencePoint

Baptiste Jonglez 10 years ago
parent
commit
98c46dcc75
2 changed files with 94 additions and 27 deletions
  1. 65 0
      panorama/migrations/0002_auto_20150304_1729.py
  2. 29 27
      panorama/models.py

+ 65 - 0
panorama/migrations/0002_auto_20150304_1729.py

@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import django.core.validators
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('panorama', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='panorama',
+            name='altitude',
+        ),
+        migrations.RemoveField(
+            model_name='panorama',
+            name='id',
+        ),
+        migrations.RemoveField(
+            model_name='panorama',
+            name='latitude',
+        ),
+        migrations.RemoveField(
+            model_name='panorama',
+            name='longitude',
+        ),
+        migrations.RemoveField(
+            model_name='panorama',
+            name='name',
+        ),
+        migrations.AddField(
+            model_name='panorama',
+            name='referencepoint_ptr',
+            field=models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, default=None, serialize=False, to='panorama.ReferencePoint'),
+            preserve_default=False,
+        ),
+        migrations.AlterField(
+            model_name='panorama',
+            name='image',
+            field=models.ImageField(upload_to='pano', verbose_name='image'),
+            preserve_default=True,
+        ),
+        migrations.AlterField(
+            model_name='referencepoint',
+            name='latitude',
+            field=models.FloatField(help_text='In degrees', verbose_name='latitude', validators=[django.core.validators.MinValueValidator(-90), django.core.validators.MaxValueValidator(90)]),
+            preserve_default=True,
+        ),
+        migrations.AlterField(
+            model_name='referencepoint',
+            name='longitude',
+            field=models.FloatField(help_text='In degrees', verbose_name='longitude', validators=[django.core.validators.MinValueValidator(-180), django.core.validators.MaxValueValidator(180)]),
+            preserve_default=True,
+        ),
+        migrations.AlterField(
+            model_name='referencepoint',
+            name='name',
+            field=models.CharField(help_text='Name of the point', max_length=255, verbose_name='name'),
+            preserve_default=True,
+        ),
+    ]

+ 29 - 27
panorama/models.py

@@ -15,6 +15,7 @@ EARTH_RADIUS = 6371009
 
 
 class Point(models.Model):
+    """Geographical point, with altitude."""
     latitude = models.FloatField(verbose_name="latitude", help_text="In degrees",
                                  validators=[MinValueValidator(-90),
                                              MaxValueValidator(90)])
@@ -74,9 +75,34 @@ class Point(models.Model):
 
 
 @python_2_unicode_compatible
-class Panorama(Point):
+class ReferencePoint(Point):
+    """Reference point, to be used"""
     name = models.CharField(verbose_name="name", max_length=255,
-                            help_text="Name of the panorama")
+                            help_text="Name of the point")
+
+    def to_dict(self):
+        """Useful to pass information to the javascript code as JSON"""
+        return {"id": self.id,
+                "name": self.name,
+                "latitude": self.latitude,
+                "longitude": self.longitude,
+                "altitude": self.altitude}
+
+    def to_dict_extended(self, point):
+        """Same as above, but also includes information relative
+        to the given point: bearing, azimuth, distance."""
+        d = self.to_dict()
+        d['distance'] = self.line_distance(point)
+        d['bearing'] = point.bearing(self)
+        d['elevation'] = point.elevation(self)
+        return d
+    
+    def __str__(self):
+        return "Reference point : " + self.name
+
+
+@python_2_unicode_compatible
+class Panorama(ReferencePoint):
     loop = models.BooleanField(default=False, verbose_name="360° panorama",
                                help_text="Whether the panorama loops around the edges")
     image = models.ImageField(verbose_name="image", upload_to="pano")
@@ -111,28 +137,4 @@ class Panorama(Point):
         return ret
 
     def __str__(self):
-        return self.name
-
-
-@python_2_unicode_compatible
-class ReferencePoint(Point):
-    name = models.CharField(verbose_name="name", max_length=255,
-                            help_text="Name of the reference point")
-
-    def to_dict(self):
-        """Useful to pass information to the javascript code as JSON"""
-        return {"id": self.id,
-                "name": self.name,
-                "latitude": self.latitude,
-                "longitude": self.longitude,
-                "altitude": self.altitude}
-
-    def to_dict_extended(self, point):
-        """Same as above, but also includes information relative
-        to the given point: bearing, azimuth, distance."""
-        d = self.to_dict()
-        d['distance'] = self.line_distance(point)
-        return d
-    
-    def __str__(self):
-        return self.name
+        return "Panorama : " + self.name