本文整理汇总了Python中pyasm.search.Search.add_id_filter方法的典型用法代码示例。如果您正苦于以下问题:Python Search.add_id_filter方法的具体用法?Python Search.add_id_filter怎么用?Python Search.add_id_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.search.Search
的用法示例。
在下文中一共展示了Search.add_id_filter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: postprocess
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def postprocess(self):
web = WebContainer.get_web()
value = web.get_form_value( self.get_input_name() )
if not value:
return
# get all fo the sobjects from the search keys
instance_type = self.get_option("instance_type")
# path is used for self-relating in an instance table
src_path = self.get_option("path")
#src_sobject = self.sobject
search = Search(self.sobject.get_search_type())
search.add_id_filter(self.sobject.get_id())
src_sobject = search.get_sobject()
# this is passed in from EditCmd in insert mode
parent_key = self.get_option('parent_key')
# in some rare cases we have project as the parent_key
if parent_key and self.is_insert and 'sthpw/project' not in parent_key:
# this is the parent
dst_sobject = SearchKey.get_by_search_key(parent_key)
# add all the new sobjects
#instances = dst_sobject.get_related_sobject(instance_type)
instance = SearchType.create(instance_type)
instance.add_related_connection(src_sobject, dst_sobject, src_path=src_path)
instance.commit()
示例2: do_search
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def do_search(my):
'''this widget has its own search mechanism'''
web = WebContainer.get_web()
# get the sobject that is to be edited
id = my.search_id
# if no id is given, then create a new one for insert
search = None
sobject = None
search_type_base = SearchType.get(my.search_type).get_base_key()
if my.mode == "insert":
sobject = SearchType.create(my.search_type)
my.current_id = -1
# prefilling default values if available
value_keys = web.get_form_keys()
if value_keys:
for key in value_keys:
value = web.get_form_value(key)
sobject.set_value(key, value)
else:
search = Search(my.search_type)
# figure out which id to search for
if web.get_form_value("do_edit") == "Edit/Next":
search_ids = web.get_form_value("%s_search_ids" %search_type_base)
if search_ids == "":
my.current_id = id
else:
search_ids = search_ids.split("|")
next = search_ids.index(str(id)) + 1
if next == len(search_ids):
next = 0
my.current_id = search_ids[next]
last_search = Search(my.search_type)
last_search.add_id_filter( id )
my.last_sobject = last_search.get_sobject()
else:
my.current_id = id
search.add_id_filter( my.current_id )
sobject = search.get_sobject()
if not sobject and my.current_id != -1:
raise EditException("No SObject found")
# set all of the widgets to contain this sobject
my.set_sobjects( [sobject], search )
示例3: execute
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def execute(my):
web = WebContainer.get_web()
# get the input names
input_names = web.get_form_value(SerialStatusWdg.STATUS_CMD_INPUT).split('|')
values = []
for input_name in input_names:
value = web.get_form_value(input_name)
if value:
values.append(web.get_form_value(input_name))
# FIXME: HARDCODED Value for status column!!!!
column = "status"
for value in values:
# get the sobject to be updated
search_type,id,status = value.split("|")
search = Search(search_type)
search.add_id_filter(id)
my.sobject = search.get_sobject()
status_attr = my.sobject.get_attr(column)
cur_status = status_attr.get_current_process()
if cur_status == status:
continue
status_attr.set_status(status)
update_column = 'time_update'
if update_column in my.sobject.get_attr_names():
my.sobject.set_value(update_column, Sql.get_timestamp_now(), quoted=False)
my.sobject.commit()
# if this is successful, the store it in the status_log
status_log = SObjectFactory.create("sthpw/status_log")
status_log.set_value("login", Environment.get_user_name() )
status_log.set_value("search_type", search_type)
status_log.set_value("search_id", id)
#status_log.set_value("status", "%s to %s" % (cur_status, status) )
status_log.commit()
status_log.set_value("from_status", cur_status)
status_log.set_value("to_status", status)
# Call the finaled trigger
Trigger.call(my, status)
示例4: execute
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def execute(self):
web = WebContainer.get_web()
search_type = web.get_form_value("search_type")
search_id = web.get_form_value("search_id")
# check if item is already in the clipboard
search = Search("sthpw/clipboard")
search.add_filter("search_type", search_type)
search.add_filter("search_id", search_id)
search.add_filter("category", "select")
if search.get_count():
# if is already selected then remove.
item = search.get_sobject()
item.delete()
search = Search(search_type)
search.add_id_filter(search_id)
sobject = search.get_sobject()
search_type_obj = sobject.get_search_type_obj()
self.description = "Removed %s '%s' from clipboard" % (search_type_obj.get_title(), sobject.get_code() )
else:
search = Search(search_type)
search.add_id_filter(search_id)
sobject = search.get_sobject()
search_type_obj = sobject.get_search_type_obj()
clipboard = SearchType.create("sthpw/clipboard")
clipboard.set_value("search_type", search_type)
clipboard.set_value("search_id", search_id)
#TODO: set project_code as well
clipboard.set_value("category", "select")
clipboard.set_user()
clipboard.commit()
self.description = "Added %s '%s' to clipboard" % (search_type_obj.get_title(), sobject.get_code() )
示例5: init
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def init(my):
WebContainer.register_cmd("pyasm.widget.AnnotateCbk")
sobject = my.get_current_sobject()
if not sobject:
if not my.__dict__.has_key("search_type"):
web = WebContainer.get_web()
my.search_type = web.get_form_value("search_type")
my.search_id = web.get_form_value("search_id")
if not my.search_type:
my.add("No search type")
return
search = Search(my.search_type)
search.add_id_filter(my.search_id)
sobject = search.get_sobject()
my.add("<h3>Design Review: Annotation</h3>")
table = TableWdg(my.search_type)
table.set_sobject(sobject)
my.add(table)
url = WebContainer.get_web().get_widget_url()
url.set_option("widget", "AnnotateWdg")
url.set_option("search_type", my.search_type)
url.set_option("search_id", my.search_id)
src = url.to_string()
my.add("<h3>Click on image to add an annotation</h3>")
my.add("The annotation will be located where you clicked on the image")
my.add( """
<iframe id="annotate_frame" scrolling="no" src="%s" style='width: 800; height: 450; margin-left: 30px; border: none;">
WARNING: iframes are not supported
</iframe>
""" % src )
示例6: _execute_single
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def _execute_single(my, code, name=None):
# only do actions if the edit button has been pressed
from pyasm.web import WebContainer
web = WebContainer.get_web()
no_commit = (web.get_form_value("sobject_commit") == 'false')
sobject = None
if my.search_key:
sobject = SearchKey.get_by_search_key(my.search_key)
# this is needed for action handler below
my.search_type = sobject.get_search_type()
else:
# get the search type and search id
my.search_type = web.get_form_value("search_type")
if my.search_type == "":
raise EditCmdException( "Search type not found" )
search_id = web.get_form_value("search_id")
if search_id == "":
raise EditCmdException( "Search id not found" )
# get the search object based on these parameters
if search_id == "" or search_id == "-1":
sobject = SearchType.create(my.search_type)
else:
search = Search(my.search_type)
search.add_id_filter( search_id )
sobject = search.get_sobject()
# there has to be an sobject to edit
if sobject == None:
raise EditCmdException("No sobject found with search type [%s] and id [%s]" % (my.search_type, search_id) )
action_handlers = my._get_action_handlers()
# set the sobject for each action handler
for action_handler in action_handlers:
action_handler.set_sobject(sobject)
if action_handler.check():
if my.parent_key:
action_handler.set_option('parent_key', my.parent_key)
if my.connect_key:
action_handler.set_option('connect_key', my.connect_key)
action_handler.execute()
# set the parent, if there is one and it's in insert
if sobject.is_insert() and my.parent_key:
sobject.add_relationship(my.parent_key)
if sobject.is_insert():
action = "Inserted"
else:
action = "Updated"
# before we commit, we set what got changed in the info
update_data = sobject.update_data
for key, value in update_data.items():
# don't include None
if value != None:
my.info[key] = value
if code:
sobject.set_value("code", code)
# only fill in a new with the passed in name if it has been
# specified
if name:
sobject.set_value("name", name)
# commit the changes unless told not to.
# NOTE: this prevents any connections to be made
if not no_commit:
try:
if sobject.is_insert():
is_insert = True
else:
is_insert = False
sobject.commit()
# only connect on insert
if is_insert and my.connect_key and my.connect_key != "__NONE__":
sobject.connect(my.connect_key, "task")
except SqlException, e:
msg = "An error was encountered adding this item. The error reported was [%s]" % e
raise SqlException(msg)
# ask the sobject for the description
my.add_description( sobject.get_update_description() )
示例7: _execute_single
# 需要导入模块: from pyasm.search import Search [as 别名]
# 或者: from pyasm.search.Search import add_id_filter [as 别名]
def _execute_single(self, code, name=None):
# only do actions if the edit button has been pressed
from pyasm.web import WebContainer
web = WebContainer.get_web()
no_commit = (web.get_form_value("sobject_commit") == 'false')
sobject = None
if self.search_key:
sobject = SearchKey.get_by_search_key(self.search_key)
if not sobject:
raise TacticException('This search key [%s] no longer exists.'%self.search_key)
# this is needed for action handler below
self.search_type = sobject.get_search_type()
elif self.sobject:
sobject = self.sobject
self.search_type = sobject.get_search_type()
else:
# get the search type and search id
self.search_type = web.get_form_value("search_type")
if self.search_type == "":
raise EditCmdException( "Search type not found" )
search_id = web.get_form_value("search_id")
# get the search object based on these parameters
if search_id == "" or search_id == "-1":
sobject = SearchType.create(self.search_type)
else:
search = Search(self.search_type)
search.add_id_filter( search_id )
sobject = search.get_sobject()
# there has to be an sobject to edit
if sobject == None:
raise EditCmdException("No sobject found with search type [%s] and id [%s]" % (self.search_type, search_id) )
action_handlers = self._get_action_handlers()
# set the sobject for each action handler
for action_handler in action_handlers:
action_handler.set_sobject(sobject)
if action_handler.check():
if self.parent_key:
action_handler.set_option('parent_key', self.parent_key)
if self.connect_key:
action_handler.set_option('connect_key', self.connect_key)
action_handler.execute()
# set the parent, if there is one and it's in insert
if sobject.is_insert() and self.parent_key:
sobject.add_relationship(self.parent_key)
if sobject.is_insert():
action = "Inserted"
else:
action = "Updated"
# before we commit, we set what got changed in the info
update_data = sobject.update_data
for key, value in update_data.items():
# don't include None
if value != None:
self.info[key] = value
if code:
sobject.set_value("code", code)
# only fill in a new with the passed in name if it has been
# specified
if name:
sobject.set_value("name", name)
for key, value in self.extra_data.items():
sobject.set_value(key, value)
# commit the changes unless told not to.
# NOTE: this prevents any connections to be made
if not no_commit:
try:
if sobject.is_insert():
is_insert = True
else:
is_insert = False
sobject.commit(triggers=self.trigger_mode)
# only connect on insert
#.........这里部分代码省略.........