diff --git a/.gitignore b/.gitignore index 52ab86c0586ebebcea79f86edd99498afcc47b4c..956e5d469f086ee0f5c716f04963dbb7728948a7 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 1355c8c76397f1ce95cbb58285b4975410231b50..256f5c3e873e1b3f74eb0c2e68b224f60bbe2de8 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 ab43acbac00611efd4414e1bee36d2a32cd97eea..e406624c82b0f8f8930b327c965ece04e3146777 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 8f10a9f19e19cc2e7d8563e24657d65072282921..47f4d2a221b4f33ad13e7b20448efc1e2c8af616 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 15aa21216c3c3548b2a82d614fa234d92bfe348c..0bb90b611e671a2fb98fccc21b988d53fc103305 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 8f30f2e2803978494d99804fdbadef80b6c378b4..98dc8b7a81cde4f46f4d636455014d537afdd5ba 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