[Mpuls-commits] r2425 - wasko/branches/2.0/jmdweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Apr 20 11:23:01 CEST 2010


Author: torsten
Date: 2010-04-20 11:23:00 +0200 (Tue, 20 Apr 2010)
New Revision: 2425

Modified:
   wasko/branches/2.0/jmdweb/lib/search.py
Log:
* jmdweb/lib/search.py (CaseSearch.get_where): Add searching for dates


Modified: wasko/branches/2.0/jmdweb/lib/search.py
===================================================================
--- wasko/branches/2.0/jmdweb/lib/search.py	2010-04-20 08:40:34 UTC (rev 2424)
+++ wasko/branches/2.0/jmdweb/lib/search.py	2010-04-20 09:23:00 UTC (rev 2425)
@@ -32,6 +32,7 @@
 
 from mpulsweb.lib.security import hasRole
 from mpulsweb.lib.search import CaseSearch as CaseBaseSearch
+from mpulsweb.model.phase import PhaseFactory 
 
 SEARCH_WHERE = """
       %s
@@ -40,13 +41,6 @@
       AND %s
       AND %s
       AND %s
-      AND %s
-      AND %s
-      AND %s
-      AND %s
-      AND %s
-      AND %s
-      AND %s
 """
 
 log = logging.getLogger(__name__)
@@ -76,7 +70,7 @@
                   and "m.bearbeiter_id = %s" % options.get('editor') or "TRUE")
 
         #Phases
-        phases = 'TRUE' #default
+        phases = 'FALSE' #default
         if phaseslist:
             phases = ('m.id in'
                       ' (SELECT id from master_tbl_view WHERE phase in (%s))'
@@ -92,98 +86,31 @@
                                        % field
                                        for field in self.match_fields)))
 
-        needle_expr = needle_expr % fields
-        ee = "TRUE"
-
-        #
-        # WASKOSPECIFIC or at least depending on concrete naming of fields.
-        #
-
-        # Geschlecht
-        gender = (options.get('gender')
-                  and "m.geschlecht = %s" % options.get('gender') or "TRUE")
-
-        branch = (options.get('branch')
-                  and "b.filiale = '%s'" % options.get('branch') or "TRUE")
-        fkz = (options.get('fkz')
-               and "m.fkz = '%s'" % options.get('fkz') or "TRUE")
-
-        #Identify bad cases
-        bad_query = []
-
-        INCONSISTENCY_TYPE_QUERY = {} # remove this
-
-        for type_id in bad_types:
-            query = INCONSISTENCY_TYPE_QUERY.get(str(type_id))
-            if query:
-                bad_query.append(query)
-        if len(bad_query) > 0:
-            bad = "(%s)" % " OR ".join(bad_query)
-        else:
-            bad = 'TRUE'
-
-        # This is a convinience option to ignore older cases in the
-        # inconsistency search
-        if options.get('only_cases_after'):
-            only_cases_after = ("coalesce(erstgespraech, now()) > '%s'"
-                                % options.get('only_cases_after'))
-        else:
-            only_cases_after = 'TRUE'
-
-        #Build timeinterval
+        #Dates
         time_interval = "TRUE"
-        if (options.get('interval_start_date')
-            and options.get('interval_end_date')):
-            interval_start_field = options.get('interval_start_field',
-                                               "erstgespraech")
-            interval_end_field = options.get('interval_end_field',
-                                             "datum_cm_ende")
-            interval_start_date = options.get('interval_start_date',
-                                              "1970-01-01")
-            d = datetime.today()
-            interval_end_date = options.get('interval_end_date',
-                                            d.strftime('%Y-%m-%d'))
-            fields = {'start_field': interval_start_field,
-                      'start_date': interval_start_date,
-                      'end_field': interval_end_field,
-                      'end_date': interval_end_date}
-            if interval_start_date != '1970-01-01':
-                time_interval =("(coalesce(%(start_field)s, '1970-01-01'::date)"
-                                " <= '%(end_date)s'::date"
-                                " AND (coalesce(%(end_field)s, now())"
-                                       " >= '%(start_date)s'::date))" % fields)
+        if (options.get('sdate') and options.get('edate')):
+            sd = options.get('sdate')
+            ed = options.get('edate')
+            time_interval_str = []
+            phasepairs = PhaseFactory().build()
+            for p in phasepairs:
+                log.debug(p)
+                sp = p.getStart()
+                ep = p.getEnd()
+                time_interval_str.append('''
+                    (m.phase IN (%s, %s) 
+                    AND (%s::date <= '%s'::date)
+                    AND (coalesce(%s, now())::date >= '%s'::date))
+                ''' % (sp.id, ep.id, sp.datefield, ed, ep.datefield, sd))
+            if -1 in phaseslist:
+                time_interval_str.append("(m.phase = -1)")
+            time_interval = "(%s)" % "OR".join(time_interval_str)
 
-        #Migration
-        migration = "TRUE"
-        if options.get('migration'):
-            if options.get('migration') == '1':
-                migration = ("(nat_muspra not in (18, -1, -3)"
-                             " or nat_staat not in (1, -1, -3)"
-                             " or vater_land not in (29, -1, -3)"
-                             " or mutter_land not in (29, -1, -3))")
-            elif options.get('migration') == '0':
-                migration = ("(nat_muspra = 18 and nat_staat = 1"
-                             " and vater_land = 29 and mutter_land = 29)")
-            elif options.get('migration') == '-1':
-                migration = ("(not (nat_muspra not in (18,-1, -3)"
-                                  " or nat_staat not in (1, -1,-3)"
-                                  " or vater_land not in (29, -1, -3)"
-                                  " or mutter_land not in (29, -1, -3))"
-                                  " and not (nat_muspra = 18 and nat_staat = 1"
-                                           " and vater_land = 29"
-                                           " and mutter_land = 29))")
-            elif options.get('migration') == '2':
-                # FIXME: This case is WASKO specific.  It used to search
-                # cases that were incorrectly imported so that the
-                # missing information can be corrected manually.
-                # wasko/issue344
-                migration = ("(nat_staat = 2"
-                             " and (vater_staat != 2 or mutter_staat != 2))")
+        needle_expr = needle_expr % fields
 
         return SEARCH_WHERE % (needle_expr,
                                ",".join([str(x) for x in allowed_states]),
-                               ee, allowed_viewer, editor, gender,
-                               time_interval, phases, branch, fkz, bad,
-                               only_cases_after, migration)
+                               allowed_viewer, editor,
+                               time_interval, phases)
 
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list