changeset 5401:ff11b178f152

Fix searchValue and mark a field where a string is found as handled
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 25 Mar 2013 12:19:40 +0100
parents acc34bf0d5b2
children 1564ca2cb224
files flys-backend/contrib/shpimporter/buildings.py flys-backend/contrib/shpimporter/importer.py
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/buildings.py	Mon Mar 25 15:41:16 2013 +0100
+++ b/flys-backend/contrib/shpimporter/buildings.py	Mon Mar 25 12:19:40 2013 +0100
@@ -62,9 +62,13 @@
                 return BUILDING_KINDS["pegel"]
 
         # Now it gets ugly when we search all attributes
-        if self.searchValue(feat, "^br[ueü]{0,2}cke[n]{0,1}$"):
+        ret = self.searchValue(feat, "^br[ueü]{0,2}cke[n]{0,1}$")
+        if ret:
+            self.handled(ret)
             return BUILDING_KINDS["brücken"]
-        if self.searchValue(feat, "^wehr[e]{0,1}$"):
+        ret = self.searchValue(feat, "^wehr[e]{0,1}$")
+        if ret:
+            self.handled(ret)
             return BUILDING_KINDS["wehre"]
 
         return BUILDING_KINDS["sonstige"]
--- a/flys-backend/contrib/shpimporter/importer.py	Mon Mar 25 15:41:16 2013 +0100
+++ b/flys-backend/contrib/shpimporter/importer.py	Mon Mar 25 12:19:40 2013 +0100
@@ -47,12 +47,15 @@
 
     def searchValue(self, feat, regex):
         """
-        Searches for a value that matches regx in all attribute
+        Searches for a value that matches regex in all attribute
         fields of a feature.
+
+        @returns the name of the field where a match was found or None
         """
         for val in feat.items():
-            match = re.match(regex, val, re.IGNORECASE)
-            return match != None
+            match = re.match(regex, feat.items()[val], re.IGNORECASE)
+            if match:
+                return val
 
     def searchField(self, regex):
         """

http://dive4elements.wald.intevation.org