Skip to content
Snippets Groups Projects
Commit 9fb268b3 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

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
parent b07befab
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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.
......
......@@ -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'
......
......@@ -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.
......
......@@ -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.
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment