##############################################################################
#
# Copyright (c) 2003
# Santi Camps Taltavull <scamps@users.sourceforge.net>
# Csok Tibor <csokt@users.sourceforge.net>
# All Rights Reserved.
#
# This Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# This Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this Library; see the file LICENSE. If not,
# write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. or visit http://www.gnu.org
#
##############################################################################
"""
An ZetadbZpt is an extended Zope Page Template, with some additional
bindings to work with databases, and to add internacionalitzation
Here there are also some descendats with usefull default functionallity
"""
from zetadb_bindings import ZetadbBindings
from zetadb_context_utils import zetadb_utils_get_application, zetadb_utils_get_manager, \
zetadb_utils_find_manager, zetadb_utils_get_path, zetadb_current_version
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate, manage_addPageTemplateForm
from string import lower, replace
from urllib import quote
from time import strftime
import os, re
class ZetadbZpt(ZetadbBindings, ZopePageTemplate):
""" Main class """
meta_type = "zetadb zpt"
manage_options = ZopePageTemplate.manage_options
# Extended list of bindings
_default_bindings = {'name_subpath': 'traverse_subpath',
'name_gettext': '_',
'name_request': 'clear_request',
'name_html_quote': 'html_quote',
'name_url_quote': 'url_quote'}
def __init__(self, id, body = ''):
""" Initializes an ZetadbZpt objects """
ZopePageTemplate.__init__(self, id, body)
self.__version__ = zetadb_current_version
self._creation_time = strftime('%Y%m%d%H%M%S')
self._modification_time = self._creation_time
def write(self, text):
""" Default write action, plus remember modification time """
self._modification_time = strftime('%Y%m%d%H%M%S')
self.ZCacheable_invalidate()
ZopePageTemplate.inheritedAttribute('write')(self, text)
def is_modified(self):
""" Returns true if the creation time is
different that modification time, false otherwise """
if long(self._modification_time) - long(self._creation_time) > 5:
return 1
else:
return 0
def __call__ (self, *args, **kw):
""" Change the language on the fly """
context = self._getContext()
if (context.REQUEST.has_key('language')):
context.REQUEST.SESSION['__language__'] = context.REQUEST['language']
if not(context.REQUEST.SESSION.has_key('__language__')):
app = zetadb_utils_get_application(self)
if app is not None:
context.REQUEST.SESSION['__language__'] = str(app.default_language)
return ZopePageTemplate.__call__(self, *args, **kw)
def pt_render(self, source=0, extra_context={}):
""" Render this Page Template, and after that, translate additional strings """
content = ZopePageTemplate.pt_render(self, source, extra_context)
# Translate additional strings (i.e. in javascript)
_ = self._get_translator()
r = []
pattern = '_\s*\(\s*(\'.*?[^\\\\]\'|\".*?[^\\\\]\")\s*\)'
regex = re.compile(pattern, re.DOTALL)
r.extend([ x[1:-1] for x in re.findall(regex, content) ])
for message in r:
content = replace(content, '_(\'' + message + '\')', _(message))
content = replace(content, '_(\"' + message + '\")', _(message))
return content
def get_translatable_content (self):
""" Returns a string with all the content in this
object that should be translated. Yes a no are
added to be boolean values translable"""
result = str(self._text) + " _('yes') _('no') _('Any') "
if (self.title is not None) and (self.title != ''):
result += "_('" + str(self.title) + "') "
return result
def zetadb_update_version (self):
""" Updates an older versions of the object
to current version """
if not(hasattr(self, '__version__')) or (self.__version__ <= '0.8.2'):
bindings = self.getBindingAssignments()._asgns
if bindings.has_key('name_db'):
del bindings['name_db']
if bindings.has_key('name_table_name'):
del bindings['name_table_name']
if bindings.has_key('name_fields'):
del bindings['name_fields']
if bindings.has_key('name_pk'):
del bindings['name_pk']
self.getBindingAssignments()._asgns = bindings
self._p_changed = 1
def zetadb_zpt_get_field_size (self, field, db):
""" Calculate the display size of one field. Depending on the field
properties, it returns the maxlenght, the width and the height
to be displayed
"""
field_db = db.zetadb_db_get_fields(field['table_name'], field['field_name'])[0]
scale = field_db['scale']
length = maxlength = field_db['length']
height = 1
if (length >= 25) and (length <= 100):
width = int(length * 2/3)
elif (length > 100):
width = 80
height = divmod(length, 80)[0]
if height > 5:
height = 5
else:
width = length + 1
if (scale > 0):
maxlength = width = length + scale + 2
return maxlength, width, height
def _head_start(self):
result = """<html>\n"""
result += """<head>\n"""
result += """ <link rel="stylesheet"\n tal:attributes="href here/styles.css/absolute_url">\n"""
result += """ <title tal:content="python:_(test(template.title=='', here.title, template.title))"></title>\n"""
result += """ <script language="javascript"\n"""
result += """ tal:attributes="src here/common_js/absolute_url">\n"""
result += """ </script>\n"""
return result
def _title_toolbar(self, manager, form_name):
result = """ <tr>\n"""
result += """ <th tal:content="python:_(test(template.title=='', here.title, template.title))"></th>\n"""
result += """ </tr>\n"""
if hasattr(manager, 'toolbar'):
result += """ <tr>\n"""
result += """ <td class="container">\n"""
result += """%s\n""" % manager.toolbar.zetadb_toolbar_get_html(manager, form_name)
result += """ </td>\n"""
result += """ </tr>\n"""
return result
def _view_field(self, db, field, url_pk=None):
result = ""
if url_pk:
result += """ <td tal:attributes="class python:test(path('repeat/record/even'),'TDEven', 'TDOdd')">\n"""
result += """ <a tal:attributes="href python:%s"\n""" % url_pk
if field['boolean']:
result += """ tal:content="python:test((record.%s is None), '', '_(\\'' + str(record.%s) + '\\')')">\n""" % (field['field_name'], field['field_name'])
else:
result += """ tal:content="python:str(record.%s)">\n""" % field['field_name']
result += """ </a>\n"""
else:
if field['boolean']:
result += """ <td tal:attributes="class python:test(path('repeat/record/even'),'TDEven', 'TDOdd')" tal:content="python:test((record.%s is None), '', '_(\\'' + str(record.%s) + '\\')')">\n""" % (field['field_name'], field['field_name'])
else:
maxlength, width, height = self.zetadb_zpt_get_field_size(field, db)
if (height > 1):
result += """ <td tal:attributes="class python:test(path('repeat/record/even'),'TDEven', 'TDOdd')" tal:content="structure python:html_quote(str(record.%s)).replace(chr(10),'<br>')">\n""" % field['field_name']
else:
result += """ <td tal:attributes="class python:test(path('repeat/record/even'),'TDEven', 'TDOdd')" tal:content="structure record/%s">\n""" % field['field_name']
result += """ </td>\n"""
return result
def _detail_link(self, app, field):
ref_manager = zetadb_utils_find_manager(app, field['ref_table']['table'])
if ref_manager is None:
ref_manager = zetadb_utils_find_manager(app.aq_parent, field['ref_table']['table'])
if ref_manager is None:
raise "ZetadbError", "You should create a manager for table " + field['ref_table']['table'] + " before (it's needed to be referenced)"
ref_path = zetadb_utils_get_path(app, ref_manager, python_format=1)
ref_path += ".filter_action.absolute_url() + '?program_filter=' + url_quote("
first = 1
for f in field['ref_table']['fields'].keys():
if not(first):
ref_path += "'##'+"
ref_path += "'%s#@=#@'+str(record.%s)+'#@and'" % (f, field['ref_table']['fields'][f])
first = 0
ref_path += ")"
result = """ <td tal:attributes="class python:test(path('repeat/record/even'),'TDEven', 'TDOdd')">\n"""
result += """ <a class="link" target="right_bottom" \n"""
result += """ tal:attributes="href python:%s">\n""" % ref_path
result += """ _('click here')\n"""
result += """ </a>\n"""
result += """ </td>\n"""
return result
def _view_foreign_key_field(self, app, field, url_pk=None):
fk_manager = zetadb_utils_find_manager(app, field['foreign_key']['ref_table'])
if fk_manager is None:
fk_manager = zetadb_utils_find_manager(app.aq_parent, field['foreign_key']['ref_table'])
if fk_manager is None:
raise "ZetadbError", "You should create a manager for table " + field['foreign_key']['ref_table'] + " before (it's needed to use foreign keys)"
fk_path = zetadb_utils_get_path(app, fk_manager, python_format=1)
result = """ <td tal:attributes="class python:test(path('repeat/record/even'),'TDEven', 'TDOdd')">\n"""
result += """ <span tal:define="params python:clear_request({"""
for f in field['foreign_key']['fields'].keys():
result += """'%s': record.%s, """ % (field['foreign_key']['fields'][f], f)
result += """})" \n"""
result += """ tal:repeat="fk_record python:%s.select_action(params)">\n""" % fk_path
if url_pk:
result += """ <a tal:attributes="href python:%s"\n""" % url_pk
result += """ tal:content="fk_record/%s">\n""" % field['field_show']
result += """ </a>\n"""
else:
result += """ <span tal:replace="fk_record/%s"></span>\n """ % field['field_show']
result += """ </span>\n"""
result += """ </td>\n"""
return result
def _read_only_field(self, app, db, field, url_pk=None):
if (field['foreign_key'] is None) or (field['field_show'] == 'itself'):
if field['type'] != 'ref_table':
result = self._view_field(db, field, url_pk)
else:
result = self._detail_link(app, field)
else:
result = self._view_foreign_key_field(app, field, url_pk)
return result
def manage_addPageTemplate(self, id, title=None, text=None, REQUEST=None, submit=None):
"""Add a ZetadbZpt with optional file content."""
id = str(id)
if REQUEST is None:
self._setObject(id, ZetadbZpt(id, text))
ob = getattr(self, id)
if title:
ob.pt_setTitle(title)
return ob
else:
file = REQUEST.form.get('file')
headers = getattr(file, 'headers', None)
if headers is None or not file.filename:
zpt = ZetadbZpt(id)
else:
zpt = ZetadbZpt(id, file)
self._setObject(id, zpt)
try: u = self.DestinationURL()
except: u = REQUEST['URL1']
if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
REQUEST.RESPONSE.redirect(u+'/manage_main')
return ''
class ZetadbZptBlank(ZetadbZpt):
""" Class with default blank page """
def __init__(self, id):
result = """<html>\n"""
result += """<head>\n"""
result += """ <link rel="stylesheet"\n"""
result += """ tal:attributes="href here/styles.css/absolute_url"> \n"""
result += """</head>\n"""
result += """<body>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptTopFrame(ZetadbZpt):
""" Class with default top frame """
def __init__(self, id):
result = """<html>\n"""
result += """<head>\n"""
result += """</head>\n"""
result += """<frameset rows="40,*" frameborder="yes">\n"""
result += """ <frame name="top" marginwidth="0" marginheight="0" scrolling="no"\n"""
result += """ frameborder="yes" src="index_top">\n"""
result += """ <frame name="main" marginwidth="5" marginheight="5" scrolling="auto"\n"""
result += """ frameborder="yes" src="blank" >\n"""
result += """</frameset>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptTopIndex(ZetadbZpt):
""" Class with default top index """
def __init__(self, id):
result = """<html>\n"""
result += """<head>\n"""
result += """ <link rel="stylesheet" tal:attributes="href here/styles.css/absolute_url"> \n"""
result += """\n"""
result += """ <script language="javascript">\n"""
result += """ function change_application(o_form) {\n"""
result += """ window.parent.frames['main'].location = o_form.app.options[o_form.app.selectedIndex].value;\n"""
result += """ }\n"""
result += """ </script>\n"""
result += """</head>\n"""
result += """<body>\n"""
result += """ <form>\n"""
result += """ <table border="0">\n"""
result += """ <tr>\n"""
result += """ <td>\n"""
result += """ <select name="app" OnChange="change_application(this.form)">\n"""
result += """ <span tal:repeat="app_id python:here.zetadb_fw_get_applications()" tal:omit-tag="">\n"""
result += """ <option tal:condition="python:here.has_access(here, app_id)" \n"""
result += """ tal:attributes="value app_id" \n"""
result += """ tal:content="python:here[app_id].title_or_id()"></option>\n"""
result += """ </span>\n"""
result += """ </select>\n"""
result += """ <input type="button" value="OK" OnClick="change_application(this.form)">\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptRightFrame(ZetadbZpt):
""" Class with default right frame """
def __init__(self, id, manager):
result = """<html>\n"""
result += """<head>\n"""
result += """</head>\n"""
result += """<frameset rows="60%,40%" frameborder="yes">\n"""
result += """ <frame name="right_top" marginwidth="5" marginheight="5" scrolling="auto"\n"""
result += """ frameborder="yes" src="index_right">\n"""
result += """ <frame name="right_bottom" marginwidth="5" marginheight="5" scrolling="auto"\n"""
result += """ frameborder="yes" src="blank" >\n"""
result += """</frameset>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptMenuIndex(ZetadbZpt):
""" Class with default menu index_html """
def __init__(self, id):
result = """<html>\n"""
result += """<head>\n"""
result += """</head>\n"""
result += """<frameset cols="20%,80%" frameborder="yes">\n"""
result += """ <frame name="left" marginwidth="5" marginheight="5" scrolling="auto"\n"""
result += """ frameborder="yes" src="main_menu">\n"""
result += """ <frame name="right" marginwidth="5" marginheight="5" scrolling="auto"\n"""
result += """ frameborder="yes" src="blank" >\n"""
result += """</frameset>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptDefaultMainMenu(ZetadbZpt):
""" Class with firstly created default main menu """
def __init__(self, id):
result = """<html>\n"""
result += """<head>\n"""
result += """ <link rel="stylesheet" \n"""
result += """ tal:attributes="href here/styles.css/absolute_url">\n"""
result += """</head>\n"""
result += """<body>\n"""
result += """\n"""
result += """<table width="100%" border="0" cellspacing="0" class="border">\n"""
result += """<tr>\n"""
result += """ <th>_("Main Menu")</th>\n"""
result += """</tr>\n"""
result += """<tr>\n"""
result += """<td tal:define="global current_group string:''" class="container">\n"""
result += """ <table border="0" cellspacing="0" cellpadding="1">\n"""
result += """ <tr>\n"""
result += """ <td colspan=3> </td>\n"""
result += """ </tr>\n"""
result += """ <tr>\n"""
result += """ <td> </td>\n"""
result += """ <td class="normal">\n"""
result += """ <img tal:attributes="src here/images/folder.png/absolute_url" border="0"> \n"""
result += """ </td>\n"""
result += """ <td class="title" colspan="2">\n"""
result += """ _("Tables")\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ <tr tal:repeat="item python:here.aq_parent.objectValues(['zetadb table manager'])">\n"""
result += """ <td> </td>\n"""
result += """ <td class="normal">\n"""
result += """ <img tal:attributes="src here/images/divider.png/absolute_url" border="0">\n"""
result += """ </td>\n"""
result += """ <td class="normal">\n"""
result += """ <img tal:attributes="src here/images/page.png/absolute_url" \n"""
result += """ border="0"> \n"""
result += """ </td>\n"""
result += """ <td class="normal">\n"""
result += """ <a href="./menuitem/" title="_('Menu element')"\n"""
result += """ tal:attributes="href item/absolute_url; title item/title_or_id"\n"""
result += """ onmouseover="window.status='_('Menu element')'; return true;"\n"""
result += """ onmouseout="window.status=''; return true;"\n"""
result += """ target="right"\n"""
result += """ tal:content="item/title_or_id">\n"""
result += """ _("Menu element")\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """</td>\n"""
result += """</tr>\n"""
result += """</table>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptMainMenu(ZetadbZpt):
""" Class with default main menu """
def __init__(self, id, menu):
items = menu.zetadb_menu_get_items()
result = """<html>\n"""
result += """<head>\n"""
result += """ <link rel="stylesheet" \n"""
result += """ tal:attributes="href here/styles.css/absolute_url">\n"""
result += """</head>\n"""
result += """<body>\n"""
result += """\n"""
result += """<table width="100%" border="0" cellspacing="0" class="border">\n"""
result += """<tr>\n"""
result += """ <th>_("Main Menu")</th>\n"""
result += """</tr>\n"""
result += """<tr>\n"""
result += """<td tal:define="global current_group string:''" class="container">\n"""
result += """ <table border="0" cellspacing="0" cellpadding="1">\n"""
for item in items:
if item['item_type'] == 'group':
result += """ <tr>\n"""
result += """ <td colspan=3> </td>\n"""
result += """ </tr>\n"""
result += """ <tr>\n"""
result += """ <td> </td>\n"""
result += """ <td class="normal">\n"""
result += """ <img tal:attributes="src here/images/folder.png/absolute_url" border="0"> \n"""
result += """ </td>\n"""
result += """ <td class="title" colspan="2">\n"""
result += """ _('%s') \n""" % item['item_title']
result += """ </td>\n"""
result += """ </tr>\n"""
else:
result += """ <tr>\n"""
result += """ <td> </td>\n"""
result += """ <td class="normal">\n"""
result += """ <img tal:attributes="src here/images/divider.png/absolute_url" border="0">\n"""
result += """ </td>\n"""
result += """ <td class="normal">\n"""
result += """ <img tal:attributes="src here/images/page.png/absolute_url" \n"""
result += """ border="0"> \n"""
result += """ </td>\n"""
result += """ <td class="normal">\n"""
result += """ <a href="./menuitem/" title="_('%s')"\n""" % item['item_title']
result += """ tal:attributes="href here/../%s/absolute_url"\n""" % item['item_name']
result += """ onmouseover="window.status='_('%s')'; return true;"\n""" % item['item_title']
result += """ onmouseout="window.status=''; return true;"\n"""
result += """ target="right">\n"""
result += """ _("%s")\n""" % item['item_title']
result += """ </a>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """</td>\n"""
result += """</tr>\n"""
result += """</table>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptList(ZetadbZpt):
""" Class with a default list form --- MODIFIED MSB """
def __init__(self, id, manager):
fields = manager.zetadb_man_get_fields(ref_tables = 1)
app = zetadb_utils_get_application(manager)
db = manager.zetadb_man_get_zetadb_database()
table_name = manager.zetadb_man_get_table_name()
# We will begin to support Zope 2.7 using standard SESSION object
session_name = "SESSION['zetadb']['%s']" % str(table_name).upper()
rows_per_page = manager.zetadb_man_get_rows_per_page()
result = self._head_start()
result += """</head>\n"""
result += """<body tal:define="all_records here/select_action;\n"""
result += """ start python:request.%s['start_row'];\n""" % session_name
result += """ records_found python:modules['ZTUtils'].Batch(all_records, size=%s, start=start);\n""" % str(rows_per_page)
result += """ previous python:records_found.previous;\n"""
result += """ next python:records_found.next">\n"""
result += """ <table border="0" cellspacing="0" width="100%">\n"""
result += self._title_toolbar(manager, 'list_form')
result += """ <tr>\n"""
result += """ <td class="container">\n"""
result += """ <form>\n"""
result += """ <table class="TableList">\n"""
result += """ <tr class="TRHead" tal:condition="python:(len(records_found)>0)">\n"""
num_fields = 0
for field in fields:
if field['field_list'] == 1:
num_fields = num_fields + 1;
result += """ <td class="TDHead">\n"""
if field['type'] != 'ref_table':
result += """ <a class="TDa" tal:define="order_by python:here.order_by_action('%s')" \n""" % field['field_name']
result += """ tal:attributes="href python:'list_form?order_by='+order_by+'&start:int=0'">\n"""
result += """ _('%s') \n""" % field['field_title']
result += """ </a>\n"""
else:
result += """ _('%s') \n""" % field['field_title']
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ <tr tal:repeat="record records_found" \n"""
result += """ tal:attributes="class python:test(path('repeat/record/even'),'TREven', 'TROdd')">\n"""
pkey = manager.zetadb_man_get_primary_key()
url_pk = """'view_form?'"""
for field_name in pkey:
url_pk += """+'%s='+str(record.%s)+'&'""" % (field_name, field_name)
for field in fields:
if field['field_list'] == 1:
result += self._read_only_field(app, db, field, url_pk)
result += """ </tr>\n"""
result += """ <tr tal:condition="python:(len(records_found)==0)">\n"""
result += """ <td class="TDHead" colspan="%s">\n""" % str((num_fields*2)-2)
result += """ <br>_('There is no %s fullfilling your search criteria')<br> """ % manager.zetadb_man_get_plural_name()
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptView(ZetadbZpt):
""" Class with a default view form """
def __init__(self, id, manager):
app = zetadb_utils_get_application(manager)
db = manager.zetadb_man_get_zetadb_database()
fields = manager.zetadb_man_get_fields(ref_tables = 1)
pk = manager.zetadb_man_get_primary_key()
result = self._head_start()
result += """ <script language="javascript">\n"""
result += """ function js_edit_action() {\n"""
result += """ document.zetadb_form.action = "edit_form";\n"""
result += """ document.zetadb_form.submit();\n"""
result += """ }\n"""
result += """ </script>\n"""
result += """</head>\n"""
result += """<body>\n"""
result += """ <form name="zetadb_form" method="post">\n"""
result += """ <table class="TableView">\n"""
result += self._title_toolbar(manager, 'view_form')
result += """ <tr class="TVRHead">\n"""
result += """ <td class="TVDHead">\n"""
result += """ <table class="TableView" \n"""
result += """ tal:repeat="record here/select_action">\n"""
for field in fields:
if field['field_name'] in pk:
result += """ <input type="hidden" \n"""
result += """ name="%s" \n""" % field['field_name']
result += """ tal:attributes="value record/%s">\n """ % field['field_name']
if field['field_view'] == 1:
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">\n"""
result += """ _('%s'):\n """ % field['field_title']
result += """ </td>\n"""
result += self._read_only_field(app, db, field)
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptInsert(ZetadbZpt):
""" Class with a default insert form """
def __init__(self, id, manager):
db = manager.zetadb_man_get_zetadb_database()
fields = manager.zetadb_man_get_fields()
result = self._head_start()
result += """ <script language="javascript"> \n"""
result += """ function submit_form(f) {\n"""
for field in fields:
if (field['field_insert'] == 1) and \
((field['foreign_key'] is None) or (field['field_show'] == 'itself')) and \
not(field['boolean']):
if field['not_null']:
maxlength, width, height = self.zetadb_zpt_get_field_size(field, db)
if (height > 1):
result += """ if (f['%s:text'].value == '') { \n""" % field['field_name']
else:
result += """ if (f['%s'].value == '') { \n""" % field['field_name']
result += """ alert("_('The field') _('%s') _('is mandatory')"); \n""" % field['field_title']
result += """ return false; \n"""
result += """ } \n"""
if field['numeric']:
result += """ if (f.%s.value != '') { \n""" % field['field_name']
result += """ if (isNaN(f.%s.value)) { \n""" % field['field_name']
result += """ alert("_('The field') _('%s') _('should be numeric')"); \n""" % field['field_title']
result += """ return false; \n"""
result += """ } \n"""
result += """ } \n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """ </script>\n"""
result += """</head>\n"""
result += """<body>\n"""
result += """<table class="TableView">\n"""
result += self._title_toolbar(manager, 'insert_form')
result += """ <tr>\n"""
result += """ <td class="container">\n"""
result += """ <form name="zetadb_form" method="post" action="insert_action">\n"""
result += """ <table class="TableView">\n"""
for field in fields:
if field['field_insert'] == 1:
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">_('%s'):</td>\n""" % field['field_title']
result += """ <td class="TVDOddL">\n"""
if (field['foreign_key'] is None) or (field['field_show'] == 'itself'):
if not(field['boolean']):
maxlength, width, height = self.zetadb_zpt_get_field_size(field, db)
if (height > 1):
result += """ <textarea name="%s:text" cols="%s" rows="%s" \n""" % (field['field_name'], str(width), str(height))
result += """ onchange="set_changed()" class="W350"></textarea>\n"""
else:
result += """ <input type="text" \n"""
result += """ name="%s" \n""" % field['field_name']
result += """ maxlength="%s" \n""" % str(maxlength)
result += """ onchange="set_changed()" \n"""
result += """ size="%s" class="W350">\n""" % str(width)
else:
result += """ <input type="checkbox" value="1" """
result += """ onchange="set_changed()" """
result += """ name="%s"> \n""" % field['field_name']
else:
# We should find the referenced table zetadb manager
app = zetadb_utils_get_application(manager)
fk_manager = zetadb_utils_find_manager(app, field['foreign_key']['ref_table'])
if fk_manager is None:
fk_manager = zetadb_utils_find_manager(app.aq_parent, field['foreign_key']['ref_table'])
if fk_manager is None:
raise "ZetadbError", "You should create a manager for table " + field['foreign_key']['ref_table'] + " before (it's needed to use foreign keys)"
fk_path = zetadb_utils_get_path(app, fk_manager, python_format=1)
fk_field = field['foreign_key']['fields'][field['field_name']]
result += """ <select name="%s" onchange="set_changed()" class="W350">\n""" % field['field_name']
result += """ <span tal:repeat="fk_record python:here.select_master_action(%s)" tal:omit-tag="">\n """ % fk_path
result += """ <option tal:content="fk_record/%s" \n""" % field['field_show']
result += """ tal:attributes="value fk_record/%s">\n""" % fk_field
result += """ </option>\n"""
result += """ </span>\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">\n"""
result += """ \n"""
result += """ </td>\n"""
result += """ <td class="TVDOddL">\n"""
result += """ <input type="button" tal:attributes="value python:_('Save')" \n"""
result += """ onclick="submit_form(this.form)"> \n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """ </td>\n"""
result += """</tr>\n"""
result += """</table>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptEdit(ZetadbZpt):
""" Class with a default edit form """
def __init__(self, id, manager):
app = zetadb_utils_get_application(manager)
db = manager.zetadb_man_get_zetadb_database()
fields = manager.zetadb_man_get_fields(ref_tables = 1)
pk = manager.zetadb_man_get_primary_key()
result = self._head_start()
result += """ <script language="javascript"> \n"""
result += """ function submit_form(f) {\n"""
for field in fields:
if field['field_edit'] == 1 and \
((field['foreign_key'] is None) or (field['field_show'] == 'itself')) and \
not(field['boolean']) and (field['type'] != 'ref_table'):
if field['not_null']:
maxlength, width, height = self.zetadb_zpt_get_field_size(field, db)
if (height > 1):
result += """ if (f['%s:text'].value == '') { \n""" % field['field_name']
else:
result += """ if (f['%s'].value == '') { \n""" % field['field_name']
result += """ alert("_('The field') _('%s') _('is mandatory')"); \n""" % field['field_title']
result += """ return false; \n"""
result += """ } \n"""
if field['numeric']:
result += """ if (f.%s.value != '') { \n""" % field['field_name']
result += """ if (isNaN(f.%s.value)) { \n""" % field['field_name']
result += """ alert("_('The field') _('%s') _('should be numeric')"); \n""" % field['field_title']
result += """ return false; \n"""
result += """ } \n"""
result += """ } \n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """ </script>"""
result += """</head>\n"""
result += """<body>\n"""
result += """<form name="zetadb_form" method="post" action="edit_action">\n"""
result += """ <table class="TableView">\n"""
result += self._title_toolbar(manager, 'edit_form')
result += """ <tr>\n"""
result += """ <td class="container">\n"""
result += """ <table class="TableView" \n"""
result += """ tal:repeat="record here/select_action">\n"""
for field in fields:
if (field['field_name'] in pk):
result += """ <input type="hidden" name="old_pk_%s" \n""" % field['field_name']
result += """ tal:attributes="value record/%s">\n""" % field['field_name']
if field['field_edit'] != 1:
result += """ <input type="hidden" name="%s" \n""" % field['field_name']
result += """ tal:attributes="value record/%s">\n""" % field['field_name']
if field['field_edit'] == 1:
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">\n"""
result += """ _('%s'):\n""" % field['field_title']
result += """ </td>\n"""
if field['field_edit_ro'] == 1:
result += self._read_only_field(app, db, field)
result += """ <td class="TVDOdd">\n"""
result += """ <input type="hidden"\n"""
result += """ name="%s" class="W350"\n""" % field['field_name']
result += """ tal:attributes="value record/%s">\n""" % field['field_name']
result += """ </td>\n"""
elif (field['foreign_key'] is None) or (field['field_show'] == 'itself'):
if not(field['boolean']):
if field['type'] != 'ref_table':
result += """ <td class="TVDOddL">\n"""
maxlength, width, height = self.zetadb_zpt_get_field_size(field, db)
if (height > 1):
result += """ <textarea name="%s:text" cols="%s" rows="%s" \n""" % (field['field_name'], str(width), str(height))
result += """ onchange="set_changed()" class="W350"\n"""
result += """ tal:content="record/%s"></textarea> \n""" % field['field_name']
else:
result += """ <input type="text" \n"""
result += """ name="%s" \n""" % field['field_name']
result += """ maxlength="%s" \n""" % str(maxlength)
result += """ size="%s" class="W350"\n""" % str(width)
result += """ onchange="set_changed()" \n"""
result += """ tal:attributes="value record/%s">\n""" % field['field_name']
result += """ </td>\n"""
else:
result += self._detail_link(app, field)
else:
result += """ <td class="TVDOddL">\n"""
result += """ <input type="checkbox" value="1" \n"""
result += """ name="%s" \n""" % field['field_name']
result += """ onchange="set_changed()" \n"""
result += """ tal:condition="python:record.%s!='yes'"> \n""" % field['field_name']
result += """ <input type="checkbox" value="1" \n"""
result += """ onchange="set_changed()" \n"""
result += """ name="%s" checked \n""" % field['field_name']
result += """ tal:condition="python:record.%s=='yes'"> \n""" % field['field_name']
result += """ </td>\n"""
else:
# We should find the referenced table zetadb manager
app = zetadb_utils_get_application(manager)
fk_manager = zetadb_utils_find_manager(app, field['foreign_key']['ref_table'])
if fk_manager is None:
fk_manager = zetadb_utils_find_manager(app.aq_parent, field['foreign_key']['ref_table'])
if fk_manager is None:
raise "ZetadbError", "You should create a manager for table " + field['foreign_key']['ref_table'] + " before (it's needed to use foreign keys)"
fk_path = zetadb_utils_get_path(app, fk_manager, python_format=1)
fk_field = field['foreign_key']['fields'][field['field_name']]
result += """ <td class="TVDOddL">\n"""
result += """ <select onchange="set_changed()" name="%s" class="W350">\n""" % field['field_name']
result += """ <option selected \n"""
result += """ tal:repeat="fk_record python:here.select_master_action(%s)" \n""" % fk_path
result += """ tal:content="fk_record/%s" \n""" % field['field_show']
result += """ tal:attributes="value fk_record/%s;\n""" % fk_field
result += """ selected python:test((record.%s==fk_record.%s), 'selected', nothing)">\n""" % (field['field_name'], fk_field)
result += """ </option>\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">\n"""
result += """ \n"""
result += """ </td>\n"""
result += """ <td class="TVDOddL">\n"""
result += """ <input type="button" tal:attributes="value python:_('Save')" \n"""
result += """ onclick="submit_form(this.form)"> \n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptSearch(ZetadbZpt):
""" Class with a default search form """
def __init__(self, id, manager):
db = manager.zetadb_man_get_zetadb_database()
fields = manager.zetadb_man_get_fields()
result = self._head_start()
result += """ <script language="javascript"> \n"""
result += """ function submit_form(f) {\n"""
for field in fields:
if (field['field_search'] == 1) and \
((field['foreign_key'] is None) or (field['field_show'] == 'itself')) and \
not(field['boolean']):
if field['numeric']:
result += """ if (f.%s.value != '') { \n""" % field['field_name']
result += """ if (isNaN(f.%s.value)) { \n""" % field['field_name']
result += """ alert("_('The field') _('%s') _('should be numeric')"); \n""" % field['field_title']
result += """ return false; \n"""
result += """ } \n"""
result += """ } \n"""
result += """\n"""
result += """ var array_conditions = new Array();\n"""
result += """ var j = 0;\n"""
result += """ \n"""
result += """ for (i=0; i<f.elements.length; i++) {\n"""
result += """ element = f.elements[i];\n"""
result += """ if ((element.name != "") && (element.value != "") && (element.value != "%") && (element.value != "*") ) {\n"""
result += """ var element_name = element.name;\n"""
result += """ if (element_name.indexOf(':') > 0) element_name = element_name.split(':')[0];\n"""
result += """ array_conditions[j] = element_name + '#@like#@' + element.value + '#@and';\n"""
result += """ j++;\n"""
result += """ }\n"""
result += """ }\n"""
result += """ f = document.search_form;\n"""
result += """ f.search_criteria.value = array_conditions.join('##');\n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """ </script>\n"""
result += """</head>\n"""
result += """<body>\n"""
result += """<table class="TableView">\n"""
result += self._title_toolbar(manager, 'search_form')
result += """ <tr>\n"""
result += """ <td class="container">\n"""
result += """ <form name="search_form" method="get" action="filter_action">\n"""
result += """ <input type="hidden" name="search_criteria">\n"""
result += """ </form>\n"""
result += """ <form name="just_to_display">\n"""
result += """ <table class="TableView">\n"""
for field in fields:
if field['field_search'] == 1:
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">_('%s'):</td>\n""" % field['field_title']
result += """ <td class="TVDOddL">\n"""
if (field['foreign_key'] is None) or (field['field_show'] == 'itself'):
if not(field['boolean']):
maxlength, width, height = self.zetadb_zpt_get_field_size(field, db)
if (height > 1):
result += """ <textarea name="%s:text" cols="%s" rows="%s" class="W350"></textarea>\n""" % (field['field_name'], str(width), str(height))
else:
result += """ <input type="text" \n"""
result += """ name="%s" class="W350" \n""" % field['field_name']
result += """ maxlength="%s" \n""" % str(maxlength)
result += """ size="%s">\n""" % str(width)
else:
result += """ <select name="%s" class="W350"> \n""" % field['field_name']
result += """ <option value="">_('Any')</option>\n"""
result += """ <option value="1">_('Yes')</option>\n"""
result += """ <option value="0">_('No')</option>\n"""
result += """ </select>\n"""
else:
# We should find the referenced table zetadb manager
app = zetadb_utils_get_application(manager)
fk_manager = zetadb_utils_find_manager(app, field['foreign_key']['ref_table'])
if fk_manager is None:
fk_manager = zetadb_utils_find_manager(app.aq_parent, field['foreign_key']['ref_table'])
if fk_manager is None:
raise "ZetadbError", "You should create a manager for table " + field['foreign_key']['ref_table'] + " before (it's needed to use foreign keys)"
fk_path = zetadb_utils_get_path(app, fk_manager, python_format=1)
fk_field = field['foreign_key']['fields'][field['field_name']]
result += """ <select name="%s" class="W350">\n""" % field['field_name']
result += """ <option value="%">Any\n"""
result += """ <span tal:repeat="fk_record python:here.select_master_action(%s)" tal:omit-tag="">\n """ % fk_path
result += """ <option tal:content="fk_record/%s" \n""" % field['field_show']
result += """ tal:attributes="value fk_record/%s">\n""" % fk_field
result += """ </option>\n"""
result += """ </span>\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ <tr class="TVROdd">\n"""
result += """ <td class="TVDOdd">\n"""
result += """ \n"""
result += """ </td>\n"""
result += """ <td class="TVDOddL">\n"""
result += """ <input type="button" tal:attributes="value python:_('Send')" \n"""
result += """ onclick="submit_form(this.form)"> \n"""
result += """ <input type="button" tal:attributes="value python:_('Advanced Search')" \n"""
result += """ onclick="javascript:document.location='search_advanced_form'"> \n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """ </td>\n"""
result += """</tr>\n"""
result += """</table>\n"""
result += """</body>\n"""
result += """</html>\n"""
ZetadbZpt.__init__(self, id, str(result))
class ZetadbZptAdvancedSearch(ZetadbZpt):
""" Class with a default advanced search form """
def __init__(self, id, manager):
fields = manager.zetadb_man_get_fields(ref_tables = 0)
table_name = manager.zetadb_man_get_table_name()
# We will begin to support Zope 2.7 using standard SESSION object
session_name = "SESSION['zetadb']['%s']" % str(table_name).upper()
result = self._head_start()
result += """ <script language="javascript">\n"""
result += """ function js_save_condition(condition, situation) {\n"""
result += """ f = document.forms[0];\n"""
result += """ if (f.value.value == '') {\n"""
result += """ alert("_('You should put some value')");\n"""
result += """ return;\n"""
result += """ }\n"""
result += """ array_conditions = f.search_criteria.value.split("##");\n"""
result += """ for (i=0; i<array_conditions.length; i++) \n"""
result += """ if (array_conditions[i] == condition) break;\n"""
result += """\n"""
result += """ if (situation == 'editing')\n"""
result += """ array_conditions[i] = f.field.value + "#@" + f.operator.value + "#@" + f.value.value + "#@" + f.connector.value; \n"""
result += """ if (situation == 'adding_after') {\n"""
result += """ if (condition == '')\n"""
result += """ array_conditions[i] = f.field.value + "#@" + f.operator.value + "#@" + f.value.value + "#@" + f.connector.value; \n"""
result += """ else\n"""
result += """ array_conditions[i] = array_conditions[i] + "##" + f.field.value + "#@" + f.operator.value + "#@" + f.value.value + "#@" + f.connector.value; \n"""
result += """ }\n"""
result += """ f.search_criteria.value = array_conditions.join("##");\n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """\n"""
result += """\n"""
result += """ function js_add_condition(condition) {\n"""
result += """ f = document.forms[0];\n"""
result += """ f.adding_after.value = condition;\n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """\n"""
result += """ function js_edit_condition(condition) {\n"""
result += """ f = document.forms[0];\n"""
result += """ f.condition_edited.value = condition;\n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """\n"""
result += """ function js_delete_condition(condition) {\n"""
result += """ f = document.forms[0];\n"""
result += """ array_conditions = f.search_criteria.value.split("##");\n"""
result += """ for (i=0; i<array_conditions.length; i++) \n"""
result += """ if (array_conditions[i] == condition) break;\n"""
result += """\n"""
result += """ delete(array_conditions[i])\n"""
result += """ f.search_criteria.value = "";\n"""
result += """ for (i=0; i<array_conditions.length; i++) {\n"""
result += """ if (array_conditions[i]) {\n"""
result += """ if (f.search_criteria.value == "")\n"""
result += """ f.search_criteria.value = array_conditions[i];\n"""
result += """ else\n"""
result += """ f.search_criteria.value = '##' + f.search_criteria.value\n"""
result += """ }\n"""
result += """ }\n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """ \n"""
result += """ function js_form_submit(f) {\n"""
result += """ f.action = "filter_action";\n"""
result += """ f.submit();\n"""
result += """ }\n"""
result += """ </script>\n"""
result += """</head>\n"""
result += """<body tal:define="search_criteria request/search_criteria | python:request.%s.get('search_criteria', '');\n""" % session_name
result += """ condition_edited request/condition_edited | python:'';\n"""
result += """ adding_after request/adding_after | python:''">\n"""
result += """<table class="TableView">\n"""
result += self._title_toolbar(manager, 'search_advanced_form')
result += """ <tr>\n"""
result += """ <td class="container">\n"""
result += """ <form name="zetadb_form" method="post" action="">\n"""
result += """ <input type="hidden" name="search_criteria" \n"""
result += """ tal:attributes="value search_criteria">\n"""
result += """ <input type="hidden" name="condition_edited">\n"""
result += """ <input type="hidden" name="adding_after">\n"""
result += """\n"""
result += """ <table class="TableSearch">\n"""
result += """ <tr class="TSROdd">\n"""
result += """ <td colspan=5 class="title">\n"""
result += """ _('Current search criteria'):\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """\n"""
result += """ <span tal:repeat="cond_tmp python:search_criteria.split('##')" tal:omit-tag="">\n"""
result += """\n"""
result += """ <span tal:condition="python:(condition_edited!=cond_tmp and cond_tmp!='')"\n"""
result += """ tal:omit-tag="">\n"""
result += """ <tr tal:define="field python:cond_tmp.split('#@')[0];\n"""
result += """ operator python:cond_tmp.split('#@')[1];\n"""
result += """ value python:cond_tmp.split('#@')[2];\n"""
result += """ connector python:cond_tmp.split('#@')[3]">\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <a tal:content="field"\n"""
result += """ tal:attributes="href python:'javascript:js_edit_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <a tal:content="operator"\n"""
result += """ tal:attributes="href python:'javascript:js_edit_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <a tal:content="value"\n"""
result += """ tal:attributes="href python:'javascript:js_edit_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <a tal:content="connector"\n"""
result += """ tal:attributes="href python:'javascript:js_edit_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <a tal:attributes="href python:'javascript:js_add_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ <img src="images/new.png" border=0\n"""
result += """ alt="_('Add Condition after this one')"\n"""
result += """ title="_('Add Condition after this one')" \n"""
result += """ onmouseover="window.status='_('Add Condition after this one')'"\n"""
result += """ onmouseout="window.status=''">\n"""
result += """ </a>\n"""
result += """ <a tal:attributes="href python:'javascript:js_delete_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ <img src="images/delete.png" border=0\n"""
result += """ alt="_('Delete Condition')"\n"""
result += """ title="_('Delete Condition')" \n"""
result += """ onmouseover="window.status='_('Delete Condition')'"\n"""
result += """ onmouseout="window.status=''">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </span>\n"""
result += """\n"""
result += """ <span tal:condition="python:(condition_edited!='' and cond_tmp==condition_edited)"\n"""
result += """ tal:omit-tag="">\n"""
result += """ <tr tal:define="field python:cond_tmp.split('#@')[0];\n"""
result += """ operator python:cond_tmp.split('#@')[1];\n"""
result += """ value python:cond_tmp.split('#@')[2];\n"""
result += """ connector python:cond_tmp.split('#@')[3]">\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <select name="field">\n"""
for field in fields:
if (field['field_search'] == 1):
result += """ <option value="%s" \n""" % field['field_name']
result += """ tal:attributes="selected python:test(field=='%s','selected',nothing)">\n""" % field['field_name']
result += """ _('%s')\n""" % field['field_title']
result += """ </option>\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <select name="operator">\n"""
result += """ <option value="="\n"""
result += """ tal:attributes="selected python:test(operator=='=','selected',nothing)">\n"""
result += """ =\n"""
result += """ </option>\n"""
result += """ <option value="<>"\n"""
result += """ tal:attributes="selected python:test(operator=='<>','selected',nothing)">\n"""
result += """ <>\n"""
result += """ </option>\n"""
result += """ <option value=">"\n"""
result += """ tal:attributes="selected python:test(operator=='>','selected',nothing)">\n"""
result += """ >\n"""
result += """ </option>\n"""
result += """ <option value=">="\n"""
result += """ tal:attributes="selected python:test(operator=='>=','selected',nothing)">\n"""
result += """ >=\n"""
result += """ </option>\n"""
result += """ <option value="<"\n"""
result += """ tal:attributes="selected python:test(operator=='<','selected',nothing)">\n"""
result += """ <\n"""
result += """ </option>\n"""
result += """ <option value="<="\n"""
result += """ tal:attributes="selected python:test(operator=='<=','selected',nothing)">\n"""
result += """ <=\n"""
result += """ </option>\n"""
result += """ <option value="like"\n"""
result += """ tal:attributes="selected python:test(operator=='like','selected',nothing)">\n"""
result += """ contains\n"""
result += """ </option>\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <input type="text" name="value" size=20 \n"""
result += """ tal:attributes="value value">\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd"> \n"""
result += """ <select name="connector">\n"""
result += """ <option value="and" \n"""
result += """ tal:attributes="selected python:test(connector=='and','selected',nothing)">\n"""
result += """ And\n"""
result += """ </option>\n"""
result += """ <option value="or"\n"""
result += """ tal:attributes="selected python:test(connector=='or','selected',nothing)">\n"""
result += """ Or\n"""
result += """ </option>\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <a tal:attributes="href python:'javascript:js_save_condition(\\'' + str(cond_tmp) + '\\', \\'editing\\')'">\n"""
result += """ <img src="images/save.png" border=0\n"""
result += """ alt="_('Save Condition')"\n"""
result += """ title="_('Save Condition')" \n"""
result += """ onmouseover="window.status='_('Save Condition')'"\n"""
result += """ onmouseout="window.status=''">\n"""
result += """ </a>\n"""
result += """ <a tal:attributes="href python:'javascript:js_add_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ <img src="images/new.png" border=0\n"""
result += """ alt="_('Add Condition after this one')"\n"""
result += """ title="_('Add Condition after this one')" \n"""
result += """ onmouseover="window.status='_('Add Condition after this one')'"\n"""
result += """ onmouseout="window.status=''">\n"""
result += """ </a>\n"""
result += """ <a tal:attributes="href python:'javascript:js_delete_condition(\\'' + str(cond_tmp) + '\\')'">\n"""
result += """ <img src="images/delete.png" border=0\n"""
result += """ alt="_('Delete Condition')"\n"""
result += """ title="_('Delete Condition')" \n"""
result += """ onmouseover="window.status='_('Delete Condition')'"\n"""
result += """ onmouseout="window.status=''">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </span>\n"""
result += """\n"""
result += """\n"""
result += """ <span tal:condition="python:((condition_edited=='' and adding_after==cond_tmp and cond_tmp!='') or (search_criteria==''))"\n"""
result += """ tal:omit-tag="">\n"""
result += """ <tr class="TSROdd">\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <select name="field">\n"""
for field in fields:
if (field['field_search'] == 1):
result += """ <option value="%s">_('%s')\n""" % (field['field_name'], field['field_title'])
result += """ </select>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <select name="operator">\n"""
result += """ <option value="=">=\n"""
result += """ <option value="<>"><>\n"""
result += """ <option value=">">>\n"""
result += """ <option value=">=">>=\n"""
result += """ <option value="<"><\n"""
result += """ <option value="<="><=\n"""
result += """ <option value="like">contains\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <input type="text" name="value" size=20 value="">\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <select name="connector">\n"""
result += """ <option value="and">And\n"""
result += """ <option value="or">Or\n"""
result += """ </select>\n"""
result += """ </td>\n"""
result += """ <td class="TSDOdd">\n"""
result += """ <a tal:attributes="href python:'javascript:js_save_condition(\\'' + str(cond_tmp) + '\\', \\'adding_after\\')'">\n"""
result += """ <img src="images/save.png" border=0\n"""
result += """ alt="_('Save Condition')"\n"""
result += """ title="_('Save Condition')" \n"""
result += """ onmouseover="window.status='_('Save Condition')'"\n"""
result += """ onmouseout="window.status=''">\n"""
result += """ </a>\n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </span> \n"""
result += """ </span>\n"""
result += """\n"""
result += """ <tr class="TSROdd">\n"""
result += """ <td colspan="5" class="TSDOdd">\n"""
result += """ <input type="button" tal:attributes="value python:_('Send')" \n"""
result += """ onclick="js_form_submit(this.form)"\n"""
result += """ onmouseover="window.status='_('Send the search using current criteria')'"\n"""
result += """ onmouseout="window.status=''"\n"""
result += """ title="_('Send the search using current criteria')"> \n"""
result += """ </td>\n"""
result += """ </tr>\n"""
result += """ </table>\n"""
result += """ </form>\n"""
result += """ </td>\n"""
result += """</tr>\n"""
result += """</table>\n"""
result += """</body>\n"""
ZetadbZpt.__init__(self, id, str(result))