From 9fb268b3cec9b0fd5d31483afb6936996f03b4de Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <legac@cppm.in2p3.fr> Date: Sun, 11 Nov 2012 20:10:53 +0100 Subject: [PATCH] Add the helper functions git_id and git_create_id. Add the method repr_url in Selector. rename the module report.py as selector.py --- .gitignore | 2 + buildVersion.py | 3 ++ modules/plugin_dbui/__init__.py | 4 +- modules/plugin_dbui/helper.py | 45 +++++++++++++++++++ .../plugin_dbui/{report.py => selector.py} | 22 +++++++++ static/plugin_dbui/CHANGELOG | 1 + 6 files changed, 76 insertions(+), 1 deletion(-) rename modules/plugin_dbui/{report.py => selector.py} (93%) diff --git a/.gitignore b/.gitignore index 52ab86c0..956e5d46 100755 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,7 @@ private/ sessions/ static/plugin_dbui/dbui-debug.js static/plugin_dbui/dbui-min.js +static/plugin_extjs/ +static/plugin_mathjax/ uploads/ web2py.plugin.dbui.*.w2p diff --git a/buildVersion.py b/buildVersion.py index 1355c8c7..256f5c3e 100755 --- a/buildVersion.py +++ b/buildVersion.py @@ -153,6 +153,9 @@ def set_version(version): fi.close() subprocess.call(["vim", CHANGELOG]) + # cleaning + os.remove("%s~" % CHANGELOG ) + def web2py(): """Produce the binary file for the web2py plugin. diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index ab43acba..e406624c 100755 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -50,9 +50,11 @@ from storemodifier import AddStore, StoreModifier from helper import (as_list, decode_field, encode_field, + get_create_id, get_field_validators, get_file_paths, get_foreign_field, + get_id, get_language, get_plugin_path, get_reference_paths, @@ -69,7 +71,7 @@ from helper import (as_list, rows_serializer) from mapper import map_default, map_tabpanel from navtree import Node -from report import Selector +from selector import Selector from viewportmodifier import ViewportModifier UNDEF = 'undefined' diff --git a/modules/plugin_dbui/helper.py b/modules/plugin_dbui/helper.py index 8f10a9f1..47f4d2a2 100644 --- a/modules/plugin_dbui/helper.py +++ b/modules/plugin_dbui/helper.py @@ -65,6 +65,25 @@ def encode_field(*args): return ''.join([el[0].upper()+el[1:].lower() for el in args if len(el)]) +def get_create_id(table, **kwargs): + """Helper function to find the id of a row identified by + a set of field value pairs. + + If the row does not exits it is created using fields, values pairs. + Return the integer id of the row. + + table + gluon.dal.Table + + """ + id = get_id(table, **kwargs) + + if id == None: + id = table.insert(**kwargs) + + return id + + def get_field_validators(field): """Helper function returning ExtJS configuration parameters to handle database gluon.dal.Field validators on the client side. @@ -187,6 +206,32 @@ def get_foreign_field(field): return None +def get_id(table, **kwargs): + """Helper function to find the id of a row identified by + a set of field value pairs. + + Return the integer id or None if the row does not exist. + + table + gluon.dal.Table + + """ + query = None + for k, v in kwargs.iteritems(): + el = table[k] == v + + if query: + query = query & (el) + else: + query = el + + row = table(query) + if row: + return row.id + + return None + + def get_language(): """Helper method returning the application language compliant with the ExtJS local file name. diff --git a/modules/plugin_dbui/report.py b/modules/plugin_dbui/selector.py similarity index 93% rename from modules/plugin_dbui/report.py rename to modules/plugin_dbui/selector.py index 15aa2121..0bb90b61 100644 --- a/modules/plugin_dbui/report.py +++ b/modules/plugin_dbui/selector.py @@ -70,6 +70,7 @@ class Selector(Storage): self._ext_field = extfield self._extension = None self._extra_queries = [] + self._tablename = table._tablename # Decode the current request for key in current.request.vars: @@ -243,6 +244,27 @@ class Selector(Storage): return query + def repr_url(self): + """URL string corresponding to the current request. + + """ + vars = [] + + tablename = self._tablename + tablename = tablename[0].upper() + tablename[1:] + + for (k, v) in current.request.vars.iteritems(): + if k.startswith(tablename) and len(v): + vars.append("%s=%s" % (k, v)) + + t = (current.request.env.http_host, + current.request.env.path_info, + '&'.join(vars)) + + url = "http://%s%s?%s" % t + return url + + def select(self, table, **kwargs): """Select the record of the table according to the selector constraints and to the extra queries. diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG index 8f30f2e2..98dc8b7a 100644 --- a/static/plugin_dbui/CHANGELOG +++ b/static/plugin_dbui/CHANGELOG @@ -17,6 +17,7 @@ HEAD - add a converter to_panelWithUrlSelector. - New controller for software version plugin_dbui/versions. - Add modifiers persistency. + - Add helper function get_create_id and get_id 0.4.8.2 (Jul 2012) - Consolidation version -- GitLab