本文整理汇总了Python中pyasm.common.Xml.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python Xml.get_value方法的具体用法?Python Xml.get_value怎么用?Python Xml.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.common.Xml
的用法示例。
在下文中一共展示了Xml.get_value方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_display
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def get_display(my):
sobject = my.get_current_sobject()
name = my.get_name()
naming = sobject.get_value(name)
if naming:
try:
xml = Xml(string=naming)
sample_name = xml.get_value("naming/@sample")
except Exception:
sample_name = naming
else:
sample_name = "<i>-- none --</i>"
return sample_name
示例2: execute
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def execute(self):
sobject = self.sobject
name = self.get_name()
web = WebContainer.get_web()
naming = web.get_form_value(name)
if not naming:
return
xml = Xml(string=naming)
sample_name = xml.get_value("naming/@sample")
parts = re.split( '[\\/._]', sample_name)
# make some adjustments based on selections
nodes = xml.get_nodes("naming/part")
for idx, node in enumerate(nodes):
type_value = web.get_form_value("type_%s" % idx)
part = parts[idx]
if not type_value:
continue
if type_value == "placeholder":
Xml.set_attribute(nodes[idx], "type", "placeholder")
Xml.set_attribute(nodes[idx], "value", part)
else:
a, b = type_value.split("/")
Xml.set_attribute(nodes[idx], "type", a)
Xml.set_attribute(nodes[idx], "name", b)
naming = xml.to_string()
sobject.set_value(name, naming)
示例3: get_widget_from_hash
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def get_widget_from_hash(cls, hash, return_none=False, force_no_index=False, kwargs={}):
from pyasm.web import DivWdg
if hash.startswith("//"):
use_top = False
hash = hash[1:]
else:
use_top = True
import re
p = re.compile("^/(\w+)")
m = p.search(hash)
if not m:
if return_none:
return None
print "Cannot parse hash[%s]" % hash
return DivWdg("Cannot parse hash [%s]" % hash)
key = m.groups()[0]
# guest user should never be able to see admin site
if key != 'login':
security = Environment.get_security()
login = security.get_user_name()
if login == "guest" and key == 'admin':
from pyasm.widget import Error403Wdg
return Error403Wdg().get_buffer_display()
sobject = cls._get_predefined_url(key, hash)
# look up the url
if not sobject:
search = Search("config/url")
search.add_filter("url", "/%s/%%"%key, "like")
search.add_filter("url", "/%s"%key)
search.add_where("or")
sobject = search.get_sobject()
if not sobject:
if return_none:
return None
return DivWdg("No Widget found for hash [%s]" % hash)
config = sobject.get_value("widget")
config = config.replace('&','&')
url = sobject.get_value("url")
url = url.strip()
# update the config value with expressions
options = Common.extract_dict(hash, url)
for name, value in options.items():
config = config.replace("{%s}" % name, value)
xml = Xml()
xml.read_string(config)
use_index, use_admin, use_sidebar = cls._get_flags(xml, sobject, force_no_index, kwargs)
if use_admin:
# use admin
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
elif use_index:
# check if there is an index
search = Search("config/url")
search.add_filter("url", "/index")
index = search.get_sobject()
# just use admin if no index page is found
if not index:
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
config = index.get_value("widget")
xml = Xml()
xml.read_string(config)
node = xml.get_node("element/display")
options.update(xml.get_node_values_of_children(node))
class_name = xml.get_value("element/display/@class")
if class_name:
options['class_name'] = class_name
# this passes the hash value to the index widget
# which must handle it accordingly
options['hash'] = hash
top = cls.build_widget(options)
return top.get_buffer_display()
#.........这里部分代码省略.........
示例4: get_widget_from_hash
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def get_widget_from_hash(cls, hash, return_none=False, force_no_index=False, kwargs={}):
from pyasm.web import DivWdg
if hash.startswith("//"):
use_top = False
hash = hash[1:]
else:
use_top = True
import re
p = re.compile("^/(\w+)")
m = p.search(hash)
if not m:
if return_none:
return None
print "Cannot parse hash[%s]" % hash
return DivWdg("Cannot parse hash [%s]" % hash)
key = m.groups()[0]
# guest user should never be able to see admin site
if key != 'login':
security = Environment.get_security()
login = security.get_user_name()
if login == "guest" and key == 'admin':
from pyasm.widget import WebLoginWdg
# HACK: if the guest access is full, the the outer form
# is not defined ... force it in here. This is because the
# top used it TopWdg and not TitleTopWdg
div = DivWdg()
div.add("<form id='form' name='form' method='post' enctype='multipart/form-data'>\n")
web_login_wdg = WebLoginWdg().get_buffer_display()
div.add(web_login_wdg)
div.add("</form>\n")
return div
sobject = cls._get_predefined_url(key, hash)
# look up the url
if not sobject:
search = Search("config/url")
search.add_filter("url", "/%s/%%"%key, "like")
search.add_filter("url", "/%s"%key)
search.add_where("or")
sobject = search.get_sobject()
if not sobject:
if return_none:
return None
return DivWdg("No Widget found for hash [%s]" % hash)
config = sobject.get_value("widget")
config = config.replace('&','&')
url = sobject.get_value("url")
url = url.strip()
# update the config value with expressions
options = Common.extract_dict(hash, url)
for name, value in options.items():
config = config.replace("{%s}" % name, value)
xml = Xml()
xml.read_string(config)
use_index, use_admin, use_sidebar = cls._get_flags(xml, sobject, force_no_index, kwargs)
# add the admin bar
security = Environment.get_security()
is_admin = security.check_access("builtin", "view_site_admin", "allow")
if is_admin and use_admin:
# use admin
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
elif use_index:
# check if there is an index
search = Search("config/url")
search.add_filter("url", "/index")
index = search.get_sobject()
# just use admin if no index page is found
if not index:
from tactic.ui.app import PageNavContainerWdg
top = PageNavContainerWdg( hash=hash, use_sidebar=use_sidebar )
return top.get_buffer_display()
config = index.get_value("widget")
xml = Xml()
xml.read_string(config)
#.........这里部分代码省略.........
示例5: execute
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def execute(my):
web = WebContainer.get_web()
# get command line options
search_type = my.kwargs.get("search_type")
assert search_type
view = my.kwargs.get("view")
if not view:
view = get_template_view()
# check if this is advanced mode
mode = web.get_form_value("custom_mode")
if not mode:
mode = 'simple'
if mode == 'xml':
config_string = web.get_form_value("config_xml")
# handle the "default" view
view = DEFAULT_VIEW
config = WidgetDbConfig.get_by_search_type(search_type, view)
if not config:
config = WidgetDbConfig.create(search_type, view)
xml = Xml()
xml.read_string(config_string)
element_name = xml.get_value("element/@name")
element_name = element_name.strip()
assert element_name
type = xml.get_value("element/@type")
if not type:
class_name = xml.get_value("element/display/@class")
if not class_name:
raise TacticException("Either a type or class name needs to be defined in config xml.")
config.append_xml_element(element_name,config_string)
config.commit_config()
# create the required columns
widget = config.get_display_widget(element_name)
columns = widget.get_required_columns()
if columns:
print "WARNING: need to create columns: ", columns
my.info['element_name'] = element_name
return
type = web.get_form_value("custom_type")
description = web.get_form_value("custom_description")
if not description:
description = "No descripton"
title = web.get_form_value("custom_title")
name = web.get_form_value("custom_name")
name = name.strip()
if not name:
raise TacticException("No name specified")
add_to_current_view = web.get_form_value("add_to_current_view")
add_to_edit_view = web.get_form_value("add_to_edit_view")
is_searchable = web.get_form_value("is_searchable")
# create the column
if type not in ['button', 'empty']:
cmd = ColumnAddCmd(search_type, name, type)
cmd.execute()
# create the type
class_name = None
options = {}
# this is actually element attrs
element_options = {}
edit_class_name = None
edit_options = {}
edit_attrs = {}
element_type = type
# Date Range is not used any more in the UI"
if type == "Date Range":
class_name = "GanttWdg"
options["start_date_column"] = "%s_start_date" % name
options["end_deate_column"] = "%s_end_date" % name
elif type == "date":
#.........这里部分代码省略.........
示例6: get_display
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def get_display(self):
top_wdg = DivWdg()
top_wdg.add_style("color: black")
top_wdg.add_style("width: 350px")
top_wdg.add_style("margin-top: 10px")
top_wdg.add_style("padding: 10px")
top_wdg.add_border()
title = DivWdg()
title.add_style("color: black")
title.add_style("margin-top: -22px")
top_wdg.add(title)
#if not self.name_string:
# title.add('No database column')
# return top_wdg
title.add("Widget Definition")
widget_types = {
'foreign_key': 'tactic.ui.table.ForeignKeyElementWdg',
'button': 'tactic.ui.table.ButtonElementWdg',
'expression': 'tactic.ui.table.ExpressionElementWdg'
}
web = WebContainer.get_web()
config_string = web.get_form_value("config_xml")
if not config_string:
config_string = '<config/>'
xml = Xml()
xml.read_string(config_string)
#print "config_string: ", config_string
# get values from the config file
element_name = xml.get_value('element/@name')
config = WidgetConfig.get(view='element',xml='<config><element>%s</element></config>' % config_string)
display_options = config.get_display_options(element_name)
title = xml.get_value('element/@title')
display_handler = xml.get_value('element/display/@class')
if not display_handler:
display_handler = 'tactic.ui.panel.TypeTableElementWdg'
widget_name = xml.get_value('element/display/@widget')
if not widget_name:
widget_name = 'custom'
custom_table = Table()
custom_table.add_style("color: black")
top_wdg.add(custom_table)
name_text = DivWdg()
name_text.add_style("color: black")
name_text.add(element_name)
custom_table.add_row()
custom_table.add_cell("Name: ")
custom_table.add_cell(name_text)
# add title
custom_table.add_row()
title_wdg = TextWdg("custom_title")
title_wdg.set_value(title)
title_wdg.add_attr("size", "50")
custom_table.add_cell( "Title: " )
custom_table.add_cell( title_wdg )
# add description
#custom_table.add_row()
#description_wdg = TextAreaWdg("custom_description")
#td = custom_table.add_cell( "Description: " )
#td.add_style("vertical-align: top")
#custom_table.add_cell( description_wdg )
type_select = SelectWdg("custom_type")
#type_select.add_empty_option("-- Select --")
type_select.set_option("values", "string|integer|float|boolean|currency|date|foreign_key|link|list|button|custom")
type_select.set_option("labels", "String(db)|Integer(db)|Float(db)|Boolean(db)|Currency(db)|Date(db)|Foreign Key|Link|List|Button|Custom")
type_select.set_value(widget_name)
#type_select.set_option("values", "string|integer|float|boolean|currency|date|link|list|foreign_key|button|empty")
#type_select.set_option("labels", "String|Integer|Float|Boolean|Currency|Date|Link|List|Foreign Key|Button|Empty")
custom_table.add_row()
td = custom_table.add_cell("Widget Type: ")
td.add_style("vertical-align: top")
td = custom_table.add_cell(type_select)
type_select.add_event("onchange", "spt.CustomProject.property_type_select_cbk(this)")
td.add(HtmlElement.br())
display_handler_text = TextWdg("display_handler")
display_handler_text.add_attr("size", "50")
#.........这里部分代码省略.........
示例7: replace_elements
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
def replace_elements(my, html_str):
"""
# NOTE: this likely is a better way to extract elements, but still
# need to find a way to inject html back into the xml
xml = Xml()
xml.read_string("<div>%s</div>" % html_str)
elements = xml.get_nodes("//element")
for element in elements:
# create a complete config
full_line_str = xml.to_string(element)
tmp_config = '''<config><tmp>%s</tmp></config>''' % full_line_str
try:
element_wdg = my.get_element_wdg(xml, my.def_config)
element_html = element_wdg.get_buffer_display()
except Exception, e:
from pyasm.widget import ExceptionWdg
element_html = ExceptionWdg(e).get_buffer_display()
xml = Xml()
try:
xml.read_string(element_html)
except Exception, e:
print "Error: ", e
xml.read_string("<h1>%s</h1>" % str(e) )
root = xml.get_root_node()
parent = xml.get_parent(element)
xml.replace_child(parent, element, root)
return xml.to_string()
"""
# a simple readline interpreter
html = Html()
full_line = []
parse_context = None
for line in html_str.split("\n"):
line2 = line.strip()
#if not parse_context and not line2.startswith('<element '):
index = line2.find('<element>')
if index == -1:
index = line2.find('<element ')
if not parse_context and index == -1:
#line = Common.process_unicode_string(line)
html.writeln(line)
continue
if index != -1:
part1 = line2[:index]
html.write(part1)
line2 = line2[index:]
full_line.append(line2)
xml = Xml()
# determine if this is valid xml
try:
# create a complete config
full_line_str = "".join(full_line)
tmp_config = '''<config><tmp>%s</tmp></config>''' % full_line_str
xml.read_string(tmp_config, print_error=False)
full_line = []
parse_context = ''
except XmlException, e:
parse_context = 'element'
#raise e
continue
try:
if Xml.get_value(xml, "config/tmp/element/@enabled") == "false":
continue
element_wdg = my.get_element_wdg(xml, my.def_config)
if element_wdg:
element_html = element_wdg.get_buffer_display()
else:
element_html = ''
except Exception, e:
from pyasm.widget import ExceptionWdg
element_html = ExceptionWdg(e).get_buffer_display()
示例8: get_widget_from_hashXX
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
#.........这里部分代码省略.........
# these show only the widget without a top
elif key == "encoded":
expression = "/encoded/{encoded}"
options = Common.extract_dict(hash, expression)
encoded = options['encoded']
import json, binascii
data = json.loads( binascii.unhexlify(encoded) )
class_name = data[0]
args = data[1]
kwargs = data[2]
widget = Common.create_from_class_path(class_name, args, kwargs)
return cls.build_widget(options)
else:
if key == "top":
kwargs["use_index"] = True
sobject = None
else:
# look up the url
search = Search("config/url")
search.add_filter("url", "/%s/%%"%key, "like")
search.add_filter("url", "/%s"%key)
search.add_where("or")
sobject = search.get_sobject()
if not sobject:
if return_none:
return None
return DivWdg("No Widget found for hash [%s]" % hash)
config = sobject.get_value("widget")
xml = Xml()
xml.read_string(config)
use_index = kwargs.get("use_index")
if use_index in [True, 'true']:
use_index = True
elif use_index in [False, 'false']:
use_index = False
use_admin = kwargs.get("use_admin")
if use_admin in [True, 'true']:
use_admin = True
elif use_admin in [False, 'false']:
use_admin = False
use_sidebar = kwargs.get("use_sidebar")
if use_sidebar in [False, 'false']:
use_sidebar = False
elif use_admin in [True, 'true']:
use_sidebar = True
if use_index is not None or use_admin is not None:
pass
elif force_no_index in [True, 'true']:
use_index = False
else:
use_index = sobject.get_value("index", no_exception=True)
if not use_index:
示例9: SObjectDefaultConfig
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
#.........这里部分代码省略.........
Xml.append_child(element, act_element)
element = self.xml.create_element("element")
Xml.set_attribute(element, "name", "publish_files")
Xml.append_child(publish, element)
dis_element = self.xml.create_element("display")
Xml.set_attribute(dis_element, "class", "UploadWdg")
# add options
option = self.xml.create_text_element('names','publish_icon|publish_main')
Xml.append_child(dis_element, option)
option = self.xml.create_text_element('required','false|true')
Xml.append_child(dis_element, option)
act_element = self.xml.create_element("action")
Xml.set_attribute(act_element, "class", "MultiUploadAction")
# add options
option = self.xml.create_text_element('names','publish_icon|publish_main')
Xml.append_child(act_element, option)
option = self.xml.create_text_element('types','icon_main|main')
Xml.append_child(act_element, option)
Xml.append_child(element, dis_element)
Xml.append_child(element, act_element)
value = self.xml.to_string()
self.xml = Xml()
self.xml.read_string(value)
def handle_columns_mode(self):
doc = self.xml.create_doc("config")
root = self.xml.get_root_node()
columns = self.get_columns()
if len(columns) == 1 and columns[0] == "id":
columns = self.get_columns(required_only=False)
# create the table
# search is a special view for SearchWdg and it should not be created
if self.view not in ['search','publish']:
if self.view.find('@') != -1:
table = self.xml.create_element('view', attrs={'name': self.view})
else:
table = self.xml.create_element(self.view)
self.xml.append_child(root, table)
for column in columns:
if column in ["_id", "id", "oid", "s_status"]:
continue
element = self.xml.create_element("element")
Xml.set_attribute(element, "name", column)
self.xml.append_child(table, element)
# add history, input and output for the load view (designed for app loading)
if self.view == 'load':
element = self.xml.create_element("element")
Xml.set_attribute(element, "name", "checkin")
self.xml.append_child(table, element)
for column in ['input', 'output']:
element = self.xml.create_element("element")
Xml.set_attribute(element, "name", column)
Xml.set_attribute(element, "edit", "false")
display_element = self.xml.create_element("display")
Xml.set_attribute(display_element, "class", "tactic.ui.cgapp.LoaderElementWdg")
self.xml.append_child(element, display_element)
stype, key = SearchType.break_up_key(self.search_type)
op1 = self.xml.create_text_element("search_type", stype)
op2 = self.xml.create_text_element("mode", column)
self.xml.append_child(display_element, op1)
self.xml.append_child(display_element, op2)
self.xml.append_child(table, element)
value = self.xml.to_string()
self.xml = Xml()
self.xml.read_string(value)
def get_type(self, element_name):
xpath = "config/%s/element[@name='%s']/@type" % (self.view,element_name)
type = self.xml.get_value(xpath)
if not type:
xpath = "config/%s/element[@name='%s']/@type" % ("definition",element_name)
type = self.xml.get_value(xpath)
return type
def get_xml(self):
return self.xml
示例10: CustomXmlWdg
# 需要导入模块: from pyasm.common import Xml [as 别名]
# 或者: from pyasm.common.Xml import get_value [as 别名]
class CustomXmlWdg(BaseTableElementWdg):
'''Creates an widget from xml
<widget name="Filter">
<display class="FilterSelectWdg">
<values>Sc01|Sc02|Sc03</values>
</display>
</widget>
'''
def __init__(self, xml_string):
self.xml_string = xml_string
self.xml = Xml(string=self.xml_string)
super(CustomXmlWdg, self).__init__()
def init(self):
self.widget_class = self.xml.get_value("widget/display/@class")
self.draw = self.xml.get_value("widget/display/@draw")
self.title = self.xml.get_value("widget/@name")
self.name = self.title
# convert the widget data
options = {}
nodes = self.xml.get_nodes("widget/display/*")
for node in nodes:
name = node.nodeName
value = Xml.get_node_value(node)
if options.has_key(name):
# turn this into an array
array = []
array.append(options.get(name))
array.append(value)
options[name] = array
else:
options[name] = value
self.options = options
self.widget = Common.create_from_class_path(self.widget_class, [self.title])
def get_child_widget_class(self):
return self.xml.get_value("widget/display/@class")
def get_child_widget(self):
return self.widget
def get_title(self):
self.widget = Common.create_from_class_path(self.widget_class, [self.title])
self.widget.options = self.options
self.widget.set_title(self.title)
self.widget.set_name(self.title)
Container.put_dict("widgets", self.title, self.widget)
index = self.get_current_index()
self.widget.set_sobjects(self.sobjects)
self.widget.set_current_index(index)
if self.draw == "false":
return ""
else:
return self.widget.get_title()
def get_display_widget(self):
return self.widget
def get_display(self):
self.widget.options = self.options
self.widget.set_title(self.title)
self.widget.set_name(self.title)
self.widget.parent_wdg = self.parent_wdg
Container.put_dict("widgets", self.title, self.widget)
index = self.get_current_index()
self.widget.set_sobjects(self.sobjects)
self.widget.set_search(self.search)
self.widget.set_current_index(index)
if self.draw == "false":
return None
else:
return self.widget