diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-17 20:27:46 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-17 20:27:46 +0100 |
commit | 078256898d02833ba39ed5041c6fce930e6fb32d (patch) | |
tree | acb883e0710a9ff3f2f8e6a8ed94a533b20acc73 | |
parent | 04a7e46a79a05800ddf55e87bd8862faa5f12486 (diff) | |
download | Chimère-078256898d02833ba39ed5041c6fce930e6fb32d.tar.bz2 Chimère-078256898d02833ba39ed5041c6fce930e6fb32d.zip |
Manage the creation of height and width filed in upgrade script
-rwxr-xr-x | chimere/scripts/upgrade.py | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/chimere/scripts/upgrade.py b/chimere/scripts/upgrade.py index 463834d..a17007b 100755 --- a/chimere/scripts/upgrade.py +++ b/chimere/scripts/upgrade.py @@ -13,7 +13,7 @@ from django.db import connection, transaction cursor = connection.cursor() -from main.models import Area, Route +from main.models import Area, Marker, Route, Icon from django.contrib.gis.geos import LineString # early versions before 0.1: urn field doesn't exist for area @@ -32,9 +32,10 @@ def slugfy(text, separator): ret = re.sub(" +", separator, ret) return ret.strip() -query = """SELECT a.attname AS field FROM pg_class c, pg_attribute a - WHERE c.relname = 'main_area' AND a.attnum > 0 AND a.attrelid = c.oid - AND a.attname='urn';""" +QUERY_CHECK_FIELD = """SELECT a.attname AS field FROM pg_class c, pg_attribute a + WHERE c.relname = '%s' AND a.attnum > 0 AND a.attrelid = c.oid + AND a.attname='%s';""" +query = QUERY_CHECK_FIELD % ('main_area', 'urn') cursor.execute(query) transaction.commit_unless_managed() @@ -128,6 +129,33 @@ for area in areas: if changed: print " * projections of areas corrected" +# changement from version 1.0 to 1.1: version of django 1.2 +# create specific height and width for image fields + +for cls, attr in ((Icon, "image"), (Marker, "picture"), + (Route, "picture")): + table = cls._meta.db_table + query = QUERY_CHECK_FIELD % (table, 'width') + cursor.execute(query) + transaction.commit_unless_managed() + + row = cursor.fetchone() + if not row: + query_update = "ALTER TABLE "+table+" ADD COLUMN width integer" + cursor.execute(query_update) + transaction.commit_unless_managed() + query_update = "ALTER TABLE "+table+" ADD COLUMN height integer" + cursor.execute(query_update) + transaction.commit_unless_managed() + for obj in cls.objects.all(): + image = getattr(obj, attr) + if not image: + continue + obj.width = image.width + obj.height = image.height + obj.save() + print " * height and width of " + table + " corrected" + # early versions before 0.1: save route with wrong SRID # only errors with default SRID is managed adapt the script for your SRID @@ -146,3 +174,4 @@ for route in routes: route.save() if changed: print " * projections of routes corrected" + |