aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/media_types
diff options
context:
space:
mode:
authorJessica Tallon <jessica@megworld.co.uk>2014-10-09 19:20:13 +0100
committerJessica Tallon <jessica@megworld.co.uk>2014-10-09 19:20:13 +0100
commited48454558a91961b6e03fc51b8a4bf785d48d1e (patch)
tree792294c842fe5643a2d8f66be366805f621d4ece /mediagoblin/media_types
parent9a1fc423ac298c2ddf078d91ea1302c135285781 (diff)
parentc0434db46910e891313495b5ae94cbbe1dd08058 (diff)
downloadmediagoblin-ed48454558a91961b6e03fc51b8a4bf785d48d1e.tar.lz
mediagoblin-ed48454558a91961b6e03fc51b8a4bf785d48d1e.tar.xz
mediagoblin-ed48454558a91961b6e03fc51b8a4bf785d48d1e.zip
Merge branch 'location'
Add Location model which holds textual, geolocation coordiantes or postal addresses. This migrates data off Image model metadata onto the general Location model. It also adds the ability for location to be set on MediaEntry, User, MediaComment and Collection models. The geolocation plugin has been updated so that the location can be displayed in more general places rather than explicitely on the MediaEntry view. If GPS coordiantes are set for the User the profile page will also have the OSM provided by the geolocation plugin.
Diffstat (limited to 'mediagoblin/media_types')
-rw-r--r--mediagoblin/media_types/image/migrations.py56
-rw-r--r--mediagoblin/media_types/image/models.py4
-rw-r--r--mediagoblin/media_types/image/processing.py4
3 files changed, 58 insertions, 6 deletions
diff --git a/mediagoblin/media_types/image/migrations.py b/mediagoblin/media_types/image/migrations.py
index f54c23ea..4af8f298 100644
--- a/mediagoblin/media_types/image/migrations.py
+++ b/mediagoblin/media_types/image/migrations.py
@@ -13,5 +13,61 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import json
+
+from sqlalchemy import MetaData, Column, ForeignKey
+
+from mediagoblin.db.migration_tools import RegisterMigration, inspect_table
+
MIGRATIONS = {}
+
+@RegisterMigration(1, MIGRATIONS)
+def remove_gps_from_image(db):
+ """
+ This will remove GPS coordinates from the image model to put them
+ on the new Location model.
+ """
+ metadata = MetaData(bind=db.bind)
+ image_table = inspect_table(metadata, "image__mediadata")
+ location_table = inspect_table(metadata, "core__locations")
+ media_entires_table = inspect_table(metadata, "core__media_entries")
+
+ # First do the data migration
+ for row in db.execute(image_table.select()):
+ fields = {
+ "longitude": row.gps_longitude,
+ "latitude": row.gps_latitude,
+ "altitude": row.gps_altitude,
+ "direction": row.gps_direction,
+ }
+
+ # Remove empty values
+ for k, v in fields.items():
+ if v is None:
+ del fields[k]
+
+ # No point in adding empty locations
+ if not fields:
+ continue
+
+ # JSONEncoded is actually a string field just json.dumped
+ # without the ORM we're responsible for that.
+ fields = json.dumps(fields)
+
+ location = db.execute(location_table.insert().values(position=fields))
+
+ # now store the new location model on Image
+ db.execute(media_entires_table.update().values(
+ location=location.inserted_primary_key[0]
+ ).where(media_entires_table.c.id==row.media_entry))
+
+ db.commit()
+
+ # All that data has been migrated across lets remove the fields
+ image_table.columns["gps_longitude"].drop()
+ image_table.columns["gps_latitude"].drop()
+ image_table.columns["gps_altitude"].drop()
+ image_table.columns["gps_direction"].drop()
+
+ db.commit()
diff --git a/mediagoblin/media_types/image/models.py b/mediagoblin/media_types/image/models.py
index b2ea3960..02040ec2 100644
--- a/mediagoblin/media_types/image/models.py
+++ b/mediagoblin/media_types/image/models.py
@@ -39,10 +39,6 @@ class ImageData(Base):
width = Column(Integer)
height = Column(Integer)
exif_all = Column(JSONEncoded)
- gps_longitude = Column(Float)
- gps_latitude = Column(Float)
- gps_altitude = Column(Float)
- gps_direction = Column(Float)
DATA_MODEL = ImageData
diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py
index a941e560..e0ddfe87 100644
--- a/mediagoblin/media_types/image/processing.py
+++ b/mediagoblin/media_types/image/processing.py
@@ -27,6 +27,7 @@ import argparse
import six
from mediagoblin import mg_globals as mgg
+from mediagoblin.db.models import Location
from mediagoblin.processing import (
BadMediaFail, FilenameBuilder,
MediaProcessor, ProcessingManager,
@@ -235,8 +236,7 @@ class CommonImageProcessor(MediaProcessor):
self.entry.media_data_init(exif_all=exif_all)
if len(gps_data):
- for key in list(gps_data.keys()):
- gps_data['gps_' + key] = gps_data.pop(key)
+ Location.create({"position": gps_data}, self.entry)
self.entry.media_data_init(**gps_data)