From 52d57c4905444c52dff78120f0cea3e381e573c8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 23 Nov 2012 18:32:32 +0100 Subject: Fix dynamic evaluation of categories --- chimere/tests.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'chimere/tests.py') diff --git a/chimere/tests.py b/chimere/tests.py index a865d9b..5fd9f55 100644 --- a/chimere/tests.py +++ b/chimere/tests.py @@ -32,7 +32,11 @@ def areas_setup(): available=True, upper_left_corner='SRID=4326;POINT(-3 47.5)', lower_right_corner='SRID=4326;POINT(-2.5 47)') - return [area_1, area_2] + area_3 = Area.objects.create(name='area 3', urn='area-3', order=3, + available=True, + upper_left_corner='SRID=4326;POINT(-1.5 1.5)', + lower_right_corner='SRID=4326;POINT(1.5 -1.5)') + return [area_1, area_2, area_3] def subcategory_setup(): category = Category.objects.create(name='Main category', @@ -85,6 +89,21 @@ def marker_setup(sub_categories=[]): markers.append(marker_3) return markers +def route_setup(sub_categories=[]): + if not sub_categories: + sub_categories = subcategory_setup() + current_date = datetime.datetime.now() + routes = [] + route_1 = Route.objects.create(name="Route 1", status='A', + has_associated_marker=False, route='SRID=4326;LINESTRING(-1 1, 1 -1)') + route_1.categories.add(sub_categories[0]) + routes.append(route_1) + route_2 = Route.objects.create(name="Route 2", status='A', + has_associated_marker=False, route='SRID=4326;LINESTRING(0 0, 2 2)') + route_2.categories.add(sub_categories[1]) + routes.append(route_2) + return routes + class ImporterTest: def test_get(self): nb_by_cat = {} @@ -310,11 +329,15 @@ class AreaAdminFormTest(TestCase): class DynamicCategoryTest(TestCase): def setUp(self): self.areas = areas_setup() - self.markers = marker_setup() + subcategories = subcategory_setup() + self.markers = marker_setup(subcategories) + self.routes = route_setup(subcategories) def test_dynamic_evaluation(self): cats = self.areas[0].getCategories(status='A', filter_available=True) self.assertEqual(len(cats), 1) + cats = self.areas[2].getCategories(status='A', filter_available=True) + self.assertEqual(len(cats), 2) class NewsTest(TestCase): def setUp(self): -- cgit v1.2.3 From 8bcca56ce043e0e4312315d69e436935e28ad9dc Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 23 Nov 2012 21:25:27 +0100 Subject: Fix route rapprochement: prevent delete of associated marker --- chimere/admin.py | 19 ++++++++++++++++--- chimere/models.py | 2 +- chimere/tests.py | 32 +++++++++++++++++++++++++++++--- chimere/views.py | 4 +++- 4 files changed, 49 insertions(+), 8 deletions(-) (limited to 'chimere/tests.py') diff --git a/chimere/admin.py b/chimere/admin.py index 4e175aa..8fe2b77 100644 --- a/chimere/admin.py +++ b/chimere/admin.py @@ -112,9 +112,21 @@ def managed_modified(modeladmin, request, queryset): if request.POST.get('rapprochement'): couple = [(item, item_ref)] if hasattr(item, 'associated_marker'): - couple.append((item.associated_marker, item_ref.associated_marker)) - for it, it_ref in couple: - for k in request.POST: + couple.append((item.associated_marker.all()[0], + item_ref.associated_marker.all()[0])) + updated_keys = request.POST + updated_keys.pop('action') + updated_keys.pop('rapprochement') + updated_keys.pop('index') + updated_keys.pop('_selected_action') + for idx, cpl in enumerate(couple): + it, it_ref = cpl + # don't copy geometry of associated items + if idx: + for k in ('route', 'point'): + if k in updated_keys: + updated_keys.pop(k) + for k in updated_keys: if not request.POST[k]: continue if hasattr(it_ref, k): @@ -124,6 +136,7 @@ def managed_modified(modeladmin, request, queryset): for val in getattr(it, k).all(): c_value.add(val) else: + setattr(it_ref, k, getattr(it, k)) it_ref.save() elif k.startswith('property_'): try: diff --git a/chimere/models.py b/chimere/models.py index 8420255..065f7e9 100644 --- a/chimere/models.py +++ b/chimere/models.py @@ -960,7 +960,7 @@ def route_post_save(sender, **kwargs): marker_fields = [f.attname for f in Marker._meta.fields] route_fields = [f.attname for f in Route._meta.fields] marker_dct = dict([(k, getattr(instance, k)) for k in marker_fields - if k in route_fields and k not in ('id', 'ref_item_id')]) + if k in route_fields and k not in ('id', 'ref_item_id')]) marker_dct['point'] = "SRID=%d;POINT(%f %f)" % (instance.route.srid, instance.route[0][0], instance.route[0][1]) marker, created = Marker.objects.get_or_create(route=instance, diff --git a/chimere/tests.py b/chimere/tests.py index 5fd9f55..0bfd830 100644 --- a/chimere/tests.py +++ b/chimere/tests.py @@ -95,7 +95,7 @@ def route_setup(sub_categories=[]): current_date = datetime.datetime.now() routes = [] route_1 = Route.objects.create(name="Route 1", status='A', - has_associated_marker=False, route='SRID=4326;LINESTRING(-1 1, 1 -1)') + has_associated_marker=True, route='SRID=4326;LINESTRING(-1 1, 1 -1)') route_1.categories.add(sub_categories[0]) routes.append(route_1) route_2 = Route.objects.create(name="Route 2", status='A', @@ -358,13 +358,15 @@ class NewsTest(TestCase): class RapprochementTest(TestCase): def setUp(self): self.areas = areas_setup() - self.markers = marker_setup() + self.subcategories = subcategory_setup() + self.markers = marker_setup(self.subcategories) + self.routes = route_setup(self.subcategories) self.adminuser = User.objects.create_superuser('admin', 'admin@test.com', 'pass') self.client.login(username='admin', password='pass') - def test_managed_modified(self): + def test_managed_modified_markers(self): ref_marker = self.markers[0] new_vals = {'name':"Marker 1 - modified", 'point':GEOSGeometry('SRID=4326;POINT(-4 48)')} @@ -384,6 +386,30 @@ class RapprochementTest(TestCase): for k in new_vals: self.assertEqual(getattr(ref_marker, k), new_vals[k]) + def test_managed_modified_routes(self): + ref_route = self.routes[0] + new_vals = {'name':"Route 1 - modified", + 'route':GEOSGeometry('SRID=4326;LINESTRING(1 1,2 2)')} + values = {'status':'M', 'ref_item':ref_route, + 'has_associated_marker':True} + values.update(new_vals) + modified_route = Route.objects.create(**values) + modified_route.categories.add(self.subcategories[1]) + response = self.client.post('/admin/chimere/route/', + data={'action':['managed_modified'], + 'index':0, 'rapprochement':1, + 'name':1, 'route':1, 'categories':1, + '_selected_action':[unicode(ref_route.pk)] + }) + ref_route = Route.objects.get(pk=ref_route.pk) + self.assertEqual(Route.objects.filter(ref_item=ref_route, + status='M').count(), 0) + self.assertEqual(ref_route.name, new_vals['name']) + self.assertEqual(ref_route.route.wkt, new_vals['route'].wkt) + self.assertEqual(ref_route.categories.all()[0], self.subcategories[1]) + self.assertEqual(ref_route.associated_marker.all()[0].name, + ref_route.name) + class RouteTest(TestCase): def setUp(self): self.subcategories = subcategory_setup() diff --git a/chimere/views.py b/chimere/views.py index 99ecc89..db63809 100644 --- a/chimere/views.py +++ b/chimere/views.py @@ -187,7 +187,6 @@ def get_edit_page(redirect_url, item_cls, item_form, init_item.submiter_session_key == \ request.session.session_key): inst = init_item - form = item_form(request.POST, request.FILES, instance=inst, subcategories=listed_subcats) formset_multi = multimediafile_formset(request.POST, request.FILES, @@ -206,6 +205,9 @@ def get_edit_page(redirect_url, item_cls, item_form, item.ref_item = ref_item if item.pk != ref_item.pk: item.status = 'M' + if hasattr(ref_item, 'has_associated_marker'): + item.has_associated_marker = \ + ref_item.has_associated_marker elif not item.ref_item: # initialisation item.ref_item = item -- cgit v1.2.3 From 1b30395108ad1d9dd42e286ca04e534fa928e679 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 24 Nov 2012 00:31:44 +0100 Subject: Add W3C georss support --- chimere/tests.py | 7 +++++-- chimere/tests/data_license | 1 + chimere/tests/eqs7day-M5.xml | 42 +++++++++++++++++++++++++++++++++++++++++ chimere/tests/georss.xml | 21 --------------------- chimere/tests/georss_simple.xml | 21 +++++++++++++++++++++ chimere/utils.py | 17 +++++++++++------ 6 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 chimere/tests/data_license create mode 100644 chimere/tests/eqs7day-M5.xml delete mode 100644 chimere/tests/georss.xml create mode 100644 chimere/tests/georss_simple.xml (limited to 'chimere/tests.py') diff --git a/chimere/tests.py b/chimere/tests.py index 0bfd830..1622923 100644 --- a/chimere/tests.py +++ b/chimere/tests.py @@ -208,10 +208,13 @@ class GeoRSSImporterTest(TestCase, ImporterTest): def setUp(self): subcategory_1, subcategory_2 = subcategory_setup() importer1 = Importer.objects.create(importer_type='RSS', - source=test_dir_path+'tests/georss.xml') + source=test_dir_path+'tests/georss_simple.xml') importer1.categories.add(subcategory_1) + importer2 = Importer.objects.create(importer_type='RSS', + source=test_dir_path+'tests/eqs7day-M5.xml') + importer2.categories.add(subcategory_2) - self.marker_importers = [(importer1, 1)] + self.marker_importers = [(importer1, 1), (importer2, 32)] class FeedsTest(TestCase): def setUp(self): diff --git a/chimere/tests/data_license b/chimere/tests/data_license new file mode 100644 index 0000000..bee3231 --- /dev/null +++ b/chimere/tests/data_license @@ -0,0 +1 @@ +eqs7day-M5.xml is a georss feed from the website http://www.usgs.gov/ published under the US public domain diff --git a/chimere/tests/eqs7day-M5.xml b/chimere/tests/eqs7day-M5.xml new file mode 100644 index 0000000..47c12b7 --- /dev/null +++ b/chimere/tests/eqs7day-M5.xml @@ -0,0 +1,42 @@ + + + + USGS M 5+ Earthquakes + Real-time, worldwide earthquake list for the past 7 days + http://earthquake.usgs.gov/earthquakes/ + U.S. Geological Survey + Fri, 23 Nov 2012 23:21:31 GMT + Fri, 23 Nov 2012 20:50:48 GMTM 5.0, Solomon IslandsNovember 23, 2012 20:50:48 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dxgz.php-10.7326162.77875pastday32.00 kmusc000dxgz + Fri, 23 Nov 2012 20:21:28 GMTM 5.3, near the east coast of Honshu, JapanNovember 23, 2012 20:21:28 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dxfu.php38.2123141.82655pastday47.00 kmusc000dxfu + Fri, 23 Nov 2012 04:52:39 GMTM 5.2, Luzon, PhilippinesNovember 23, 2012 04:52:39 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dx8j.php14.0515120.75575pastday199.70 kmusc000dx8j + Fri, 23 Nov 2012 00:40:19 GMTM 5.0, Molucca SeaNovember 23, 2012 00:40:19 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dx7p.php1.6378125.86435pastday57.50 kmusc000dx7p + Thu, 22 Nov 2012 22:44:31 GMTM 5.0, southeast of the Loyalty IslandsNovember 22, 2012 22:44:31 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dx70.php-22.3513174.04935pastweek35.30 kmusc000dx70 + Thu, 22 Nov 2012 18:01:15 GMTM 5.0, southern Sumatra, IndonesiaNovember 22, 2012 18:01:15 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dx58.php-4.5417102.85495pastweek77.80 kmusc000dx58 + Thu, 22 Nov 2012 13:07:05 GMTM 5.6, Salta, ArgentinaNovember 22, 2012 13:07:05 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dx1i.php-22.6657-63.48805pastweek459.10 kmusc000dx1i + Thu, 22 Nov 2012 09:09:31 GMTM 5.0, Bali region, IndonesiaNovember 22, 2012 09:09:31 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dwzh.php-8.9069115.15275pastweek73.80 kmusc000dwzh + Thu, 22 Nov 2012 05:21:49 GMTM 5.2, Komandorskiye Ostrova, Russia regionNovember 22, 2012 05:21:49 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dwta.php54.0864168.30125pastweek30.00 kmusc000dwta + Wed, 21 Nov 2012 22:52:28 GMTM 5.2, offshore Libertador O'Higgins, ChileNovember 21, 2012 22:52:28 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dwl3.php-33.9846-72.01185pastweek9.80 kmusc000dwl3 + Wed, 21 Nov 2012 21:36:22 GMTM 5.9, offshore Libertador O'Higgins, ChileNovember 21, 2012 21:36:22 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dwip.php-34.0163-72.01725pastweek15.70 kmusc000dwip + Wed, 21 Nov 2012 18:16:36 GMTM 5.1, offshore Libertador O'Higgins, ChileNovember 21, 2012 18:16:36 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dwbj.php-33.9622-72.14225pastweek9.70 kmusc000dwbj + Wed, 21 Nov 2012 17:42:37 GMTM 5.0, near the east coast of Honshu, JapanNovember 21, 2012 17:42:37 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dwai.php38.4991141.73535pastweek37.30 kmusc000dwai + Wed, 21 Nov 2012 16:46:37 GMTM 5.4, south of Sumbawa, IndonesiaNovember 21, 2012 16:46:37 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dw8j.php-11.3754117.93005pastweek9.90 kmusc000dw8j + Wed, 21 Nov 2012 01:18:40 GMTM 5.0, New Britain region, Papua New GuineaNovember 21, 2012 01:18:40 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dvz8.php-5.9033151.70745pastweek8.40 kmusc000dvz8 + Tue, 20 Nov 2012 17:08:59 GMTM 5.2, Taiwan regionNovember 20, 2012 17:08:59 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dvkl.php22.4104121.42105pastweek11.40 kmusc000dvkl + Tue, 20 Nov 2012 16:23:24 GMTM 5.4, offshore Libertador O'Higgins, ChileNovember 20, 2012 16:23:24 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dvj3.php-33.9579-72.31635pastweek15.40 kmusc000dvj3 + Tue, 20 Nov 2012 15:27:59 GMTM 5.0, Molucca SeaNovember 20, 2012 15:27:59 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dvi3.php0.8083126.05395pastweek9.90 kmusc000dvi3 + Mon, 19 Nov 2012 17:54:08 GMTM 5.4, PakistanNovember 19, 2012 17:54:08 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000duzz.php30.453967.53945pastweek14.10 kmusc000duzz + Mon, 19 Nov 2012 16:45:50 GMTM 5.2, offshore Libertador O'Higgins, ChileNovember 19, 2012 16:45:50 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000duxx.php-33.9382-72.18185pastweek10.00 kmusc000duxx + Mon, 19 Nov 2012 10:55:08 GMTM 5.2, New Britain region, Papua New GuineaNovember 19, 2012 10:55:08 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000duuj.php-5.8731151.64495pastweek10.00 kmusc000duuj + Mon, 19 Nov 2012 10:15:54 GMTM 5.1, New Britain region, Papua New GuineaNovember 19, 2012 10:15:54 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dutx.php-5.9073151.70665pastweek12.80 kmusc000dutx + Mon, 19 Nov 2012 10:09:46 GMTM 5.0, south of Java, IndonesiaNovember 19, 2012 10:09:46 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000duty.php-9.5383108.24285pastweek34.90 kmusc000duty + Mon, 19 Nov 2012 09:44:34 GMTM 5.8, New Britain region, Papua New GuineaNovember 19, 2012 09:44:34 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000duti.php-5.7339151.60635pastweek10.10 kmusc000duti + Mon, 19 Nov 2012 04:09:27 GMTM 5.1, east of the South Sandwich IslandsNovember 19, 2012 04:09:27 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000durc.php-59.3483-18.30985pastweek6.50 kmusc000durc + Sun, 18 Nov 2012 20:01:26 GMTM 5.1, Mindanao, PhilippinesNovember 18, 2012 20:01:26 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dunk.php6.0242125.88425pastweek126.10 kmusc000dunk + Sat, 17 Nov 2012 18:43:52 GMTM 5.3, West Chile RiseNovember 17, 2012 18:43:52 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dubt.php-37.0202-94.96675pastweek10.80 kmusc000dubt + Sat, 17 Nov 2012 18:12:21 GMTM 5.4, West Chile RiseNovember 17, 2012 18:12:21 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000dub9.php-37.1596-94.96805pastweek10.10 kmusc000dub9 + Sat, 17 Nov 2012 09:06:26 GMTM 5.1, southeast of the Loyalty IslandsNovember 17, 2012 09:06:26 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000du6f.php-22.2351171.64325pastweek115.10 kmusc000du6f + Sat, 17 Nov 2012 05:29:45 GMTM 5.0, Fiji regionNovember 17, 2012 05:29:45 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000du4e.php-20.2516-178.44185pastweek583.80 kmusc000du4e + Sat, 17 Nov 2012 05:12:56 GMTM 6.1, Tonga regionNovember 17, 2012 05:12:56 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000du43.php-18.3108-172.37416pastweek9.80 kmusc000du43 + Sat, 17 Nov 2012 02:51:24 GMTM 5.7, VanuatuNovember 17, 2012 02:51:24 GMThttp://earthquake.usgs.gov/earthquakes/recenteqsww/Quakes/usc000du3a.php-15.0263167.42605pastweek128.40 kmusc000du3a + + diff --git a/chimere/tests/georss.xml b/chimere/tests/georss.xml deleted file mode 100644 index 8697f16..0000000 --- a/chimere/tests/georss.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - Earthquakes - International earthquake observation labs - - 2005-12-13T18:30:02Z - - Dr. Thaddeus Remor - tremor@quakelab.edu - - urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6 - - M 3.2, Mona Passage - - urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a - 2005-08-17T07:02:32Z - We just had a big one. - 45.256 -71.92 - - diff --git a/chimere/tests/georss_simple.xml b/chimere/tests/georss_simple.xml new file mode 100644 index 0000000..8697f16 --- /dev/null +++ b/chimere/tests/georss_simple.xml @@ -0,0 +1,21 @@ + + + Earthquakes + International earthquake observation labs + + 2005-12-13T18:30:02Z + + Dr. Thaddeus Remor + tremor@quakelab.edu + + urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6 + + M 3.2, Mona Passage + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2005-08-17T07:02:32Z + We just had a big one. + 45.256 -71.92 + + diff --git a/chimere/utils.py b/chimere/utils.py index 1877441..ed41a04 100644 --- a/chimere/utils.py +++ b/chimere/utils.py @@ -569,17 +569,22 @@ class GeoRSSManager(ImportManager): if feed['bozo']: return (0, 0, _(u"RSS feed is not well formed")) for item in feed['items']: - if "georss_point" not in item and 'georss_line' not in item: + if "georss_point" not in item and 'georss_line' not in item \ + and not ("geo_lat" in item and "geo_long" in item): continue cls = None dct = {'origin':self.importer_instance.origin, 'license':self.importer_instance.license} - if 'georss_point' in item: + if 'georss_point' in item or "geo_lat" in item: cls = Marker - try: - y, x = item['georss_point'].split(' ') - except ValueError: - continue + if 'georss_point' in item: + try: + y, x = item['georss_point'].split(' ') + except ValueError: + continue + else: + y = item['geo_lat'] + x = item['geo_long'] dct['point'] = 'SRID=4326;POINT(%s %s)' % (x, y) for k in ['description', 'summary', 'value']: if k in item: -- cgit v1.2.3