当前位置: 首页>>代码示例>>Python>>正文


Python biz.ExpressionParser类代码示例

本文整理汇总了Python中pyasm.biz.ExpressionParser的典型用法代码示例。如果您正苦于以下问题:Python ExpressionParser类的具体用法?Python ExpressionParser怎么用?Python ExpressionParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ExpressionParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: init

    def init(my):

        list_item_table = ''
        my.full_item_list = []
        if my.kwargs.has_key( 'list_item_table' ):
            list_item_table = my.kwargs.get( 'list_item_table' )
            expr = '@SOBJECT(MMS/%s)' % list_item_table
            parser = ExpressionParser()
            my.full_item_list = parser.eval(expr)

        my.el_name = ''
        if my.kwargs.has_key( 'element_name' ):
            my.el_name = my.kwargs.get( 'element_name' )

        my.input_el_name = ''
        if my.kwargs.has_key( 'input_element_to_find' ):
            my.input_el_name = my.kwargs.get( 'input_element_to_find' )

        my.col_to_match = ''
        if my.kwargs.has_key( 'column_to_match_value' ):
            my.col_to_match = my.kwargs.get( 'column_to_match_value' )

        my.col_for_label = ''
        if my.kwargs.has_key( 'column_for_label' ):
            my.col_for_label = my.kwargs.get( 'column_for_label' )

        my.select_element = HtmlElement('select')
开发者ID:2gDigitalPost,项目名称:tactic_src,代码行数:27,代码来源:smart_select_wdg.py

示例2: get_group_bottom_wdg

    def get_group_bottom_wdg(my, sobjects):

        expression = my.get_option("group_bottom")
        if not expression:
            return None

        # parse the expression
        my.vars = my.get_vars()

        parser = ExpressionParser()
        result = parser.eval(expression, sobjects=sobjects, vars=my.vars)

        format_str = my.kwargs.get("display_format")
        if format_str:
            from tactic.ui.widget import FormatValueWdg

            format_wdg = FormatValueWdg(format=format_str, value=result)
            result = format_wdg
        else:
            result = str(result)

        div = DivWdg()
        div.add(result)
        div.add_style("text-align: right")
        # div.add_class( "spt_%s_expr_bottom" % (my.get_name()) )

        # add a listener
        # for sobject in sobjects:
        #    if sobject.is_insert():
        #        continue
        #
        #    if my.enable_eval_listener:
        #        my.add_js_expression(div, sobject, expression)

        return div
开发者ID:raidios,项目名称:TACTIC,代码行数:35,代码来源:expression_element_wdg.py

示例3: get_mail_users

    def get_mail_users(my, column):
        # mail groups
        recipients = set()

        expr = my.notification.get_value(column, no_exception=True)
        if expr:
            sudo = Sudo()
            # Introduce an environment that can be reflected
            env = {
                'sobject': my.sobject
            }

            #if expr.startswith("@"):
            #    logins = Search.eval(expr, list=True, env_sobjects=env)
            #else:
            parts = expr.split("\n")

            # go through each login and evaluate each
            logins = []
            for part in parts:
                if part.startswith("@") or part.startswith("{"):
                    results = Search.eval(part, list=True, env_sobjects=env)
                    # clear the container after each expression eval
                    ExpressionParser.clear_cache()
                    # these can just be login names, get the actual Logins
                    if results:
                        if isinstance(results[0], basestring):
                            login_sobjs = Search.eval("@SOBJECT(sthpw/login['login','in','%s'])" %'|'.join(results),  list=True)
                        
                            login_list = SObject.get_values(login_sobjs, 'login')
                            
                            for result in results:
                                # the original result could be an email address already
                                if result not in login_list:
                                    logins.append(result)
                                
                            if login_sobjs:
                                logins.extend( login_sobjs )
                        else:
                            logins.extend(results)

                elif part.find("@") != -1:
                    # this is just an email address
                    logins.append( part )
                elif part:
                    # this is a group
                    group = LoginGroup.get_by_code(part)
                    if group:
                        logins.extend( group.get_logins() )

            del sudo
        else:
            notification_id = my.notification.get_id()
            logins = GroupNotification.get_logins_by_id(notification_id)

        for login in logins:
            recipients.add(login) 

        return recipients
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:59,代码来源:email_handler.py

示例4: cache

    def cache(self):

        # get the value from cache
        from pyasm.biz import ExpressionParser
        parser = ExpressionParser()
        logins = parser.eval("@SOBJECT(sthpw/login)")

        self.attrs[self.key] = logins
开发者ID:mincau,项目名称:TACTIC,代码行数:8,代码来源:cache.py

示例5: get_message

    def get_message(my):
        search_type_obj = my.sobject.get_search_type_obj()
        title = search_type_obj.get_title()
        subject = my.get_subject()
        notification_message = my.notification.get_value("message")
        if notification_message:
            # parse it through the expression
            sudo = Sudo()
            parser = ExpressionParser()
            snapshot = my.input.get('snapshot')
            env_sobjects = {}

            # turn prev_data and update_data from input into sobjects
            prev_data = SearchType.create("sthpw/virtual")
            id_col = prev_data.get_id_col()

            if id_col:
                del prev_data.data[id_col]

            prev_dict = my.input.get("prev_data")
            if prev_dict:
                for name, value in prev_dict.items():
                    if value != None:
                        prev_data.set_value(name, value)


            update_data = SearchType.create("sthpw/virtual")
            id_col = update_data.get_id_col()

            if id_col:
                del update_data.data[id_col]

            update_dict = my.input.get("update_data")
            if update_dict:
                for name, value in update_dict.items():
                    if value != None:
                        update_data.set_value(name, value)



            if snapshot:

                env_sobjects = {
                'snapshot': snapshot
            }


            env_sobjects['prev_data'] = prev_data
            env_sobjects['update_data'] = update_data

            notification_message  = parser.eval(notification_message, my.sobject, env_sobjects=env_sobjects, mode='string')
            del sudo
            return notification_message

        message = "%s %s" % (title, my.sobject.get_name())
        message = '%s\n\nReport from transaction:\n%s\n' % (message, subject)
        return message
开发者ID:0-T-0,项目名称:TACTIC,代码行数:57,代码来源:email_handler.py

示例6: get_item_div

    def get_item_div(self, sobject):
        ''' get the item div the sobject'''
        top = DivWdg()
        top.add_style("padding: 3px 2px")
        top.add_class("spt_drop_item")
        top.add_class("SPT_DROP_ITEM")


        item_div = DivWdg()
        top.add(item_div, "item_div")
        item_div.add_style("text-overflow: ellipsis")
        item_div.add_style("white-space: nowrap")
        item_div.add_style("width: 80%")
        item_div.add_attr('title','Click to remove')
        item_div.add_style("display", "inline-block")
        item_div.add_style("vertical-align", "top")
        item_div.add_style("overflow", "hidden")


        icon_div = DivWdg()
        top.add(icon_div)
        icon = IconWdg(icon="BS_REMOVE")
        icon_div.add(icon)
        icon_div.add_behavior( {
            'type': 'click_up',
            #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)'''
            'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)'''
        } )
        icon.add_style("opacity: 0.3")
        icon_div.add_class("hand")
        icon_div.add_style("display", "inline-block")
        icon_div.add_style("vertical-align", "top")
        #icon_div.add_border()


        #self.menu.set_over(item_div, event="mousein")
        #self.menu.set_out(top, event="mouseleave")


        # set this as the place for the display value to go
        item_div.add_class("spt_drop_display_value")

        add_icon = True
        ExpressionParser.clear_cache()
        if sobject:
            if add_icon:
                self._add_icon(sobject, item_div)

            if self.display_expr:
                display_value = Search.eval(self.display_expr, sobjects = sobject, single=True)
            else:
                display_value = sobject.get_display_value()
            if isinstance(display_value, list):
                display_value = display_value[0]
            item_div.add( display_value )
            self.values.append( SearchKey.get_by_sobject(sobject) )
        return top
开发者ID:mincau,项目名称:TACTIC,代码行数:57,代码来源:drop_element_wdg.py

示例7: get_subject

 def get_subject(my):
     subject = my.notification.get_value("subject",no_exception=True)
     if subject:
         # parse it through the expression
         sudo = Sudo()
         parser = ExpressionParser()
         subject  = parser.eval(subject, my.sobject, mode='string')
         del sudo
     else:
         subject = '%s - %s' %(my.sobject.get_update_description(), my.command.get_description())
     return subject
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:11,代码来源:email_handler.py

示例8: get_display

    def get_display(my):
        filter_data = FilterData.get_from_cgi()
        values = filter_data.get_values("custom", "year")

        year = 0
        for value in values:
            if value:
                try:
                    year = int(value)
                except:
                    pass
        if not year:
            date = Date()
            year = int(date.get_year())

        sobject = my.get_current_sobject()
        id = sobject.get_id()

        column = my.get_option("column")
        month = int( my.get_option('month') )

        end_year = year
        end_month = month + 1
        if end_month > 12:
            end_month = 1
            end_year += 1



        search_type = 'MMS/personal_time_log'

        if year:

            search = Search(search_type)
            search.add_filter('login_id', id)
            search.add_filter('work_performed_date', '%s-%0.2d-01' % (year,month), '>')
            search.add_filter('work_performed_date', '%s-%0.2d-01' % (end_year,end_month), '<')

            sobjects = search.get_sobjects()
        else:
            sobjects = []


        if sobjects:
            parser = ExpressionParser()
            sum = parser.eval("@SUM(%s.%s)" % (search_type,column),sobjects=sobjects)
        else:
            sum = 0

        div = DivWdg()
        div.add(sum)
        return div
开发者ID:0-T-0,项目名称:TACTIC,代码行数:52,代码来源:yearly_report_wdg.py

示例9: get_display

    def get_display(my):
        sobject = my.get_current_sobject()
        expression = my.get_option("expression")

        parser = ExpressionParser()
        value = parser.eval(expression, sobject)

        div = DivWdg()
        div.add_style("text-align: center")
        if value == False:
            div.add( IconWdg("XXX", IconWdg.DOT_GREEN) )
        else:
            div.add( IconWdg("YYY", IconWdg.DOT_RED) )

        return div
开发者ID:funic,项目名称:TACTIC,代码行数:15,代码来源:table_element_wdg.py

示例10: get_message

    def get_message(my):
        search_type_obj = my.sobject.get_search_type_obj()
        title = search_type_obj.get_title()
        subject = my.get_subject()
        notification_message = my.notification.get_value("message")
        if notification_message:
            # parse it through the expression
            sudo = Sudo()
            parser = ExpressionParser()

            notification_message  = parser.eval(notification_message, my.sobject, mode='string')
            del sudo
            return notification_message

        message = "%s %s" % (title, my.sobject.get_name())
        message = '%s\n\nReport from transaction:\n%s\n' % (message, subject)
        return message
开发者ID:blezek,项目名称:TACTIC,代码行数:17,代码来源:email_handler.py

示例11: get_bottom_wdg

    def get_bottom_wdg(my):

        my.init_kwargs()

        sobjects = my.sobjects
        # ignore the first 2 (edit and insert) if it's on the old TableLayoutWdg
        if my.get_layout_wdg().get_layout_version() == '1':
            sobjects = sobjects[2:]
        
        if not sobjects:
            return None


        expression = my.get_option("bottom")
        if not expression:
            return None

        # parse the expression
        my.vars = my.get_vars()
 
        parser = ExpressionParser()
        result = parser.eval(expression, sobjects=sobjects, vars=my.vars)

        format_str = my.kwargs.get("display_format")
        if format_str:
            from tactic.ui.widget import FormatValueWdg
            format_wdg = FormatValueWdg(format=format_str, value=result)
            result = format_wdg
        else:
            result = str(result)

        div = DivWdg()
        div.add(result)
        div.add_style("text-align: right")
        div.add_class( "spt_%s_expr_bottom" % (my.get_name()) )

        # add a listener
        for sobject in sobjects:
            if sobject.is_insert():
                continue
            if my.enable_eval_listener:
                my.add_js_expression(div, sobject, expression)

        return div
开发者ID:0-T-0,项目名称:TACTIC,代码行数:44,代码来源:expression_element_wdg.py

示例12: get_item_div

    def get_item_div(my, sobject):
        ''' get the item div the sobject'''
        top = DivWdg()
        top.add_style("padding: 3px 2px")
        top.add_attr('title','Click to remove')
        # FIXME: put this here for now
        top.add_behavior( {
            'type': 'click_up',
            #'cbjs_action': '''spt.dg_table_action.sobject_drop_remove(evt,bvr)'''
            'cbjs_action': '''spt.drop.sobject_drop_remove(evt,bvr)'''
        } )

        top.add_class("spt_drop_item")
        top.add_class("SPT_DROP_ITEM")

        item_div = DivWdg()
        item_div.add_class("hand")
        item_div.add_style("float: clear")
        top.add(item_div, "item_div")


        #my.menu.set_over(item_div, event="mousein")
        #my.menu.set_out(top, event="mouseleave")


        # set this as the place for the display value to go
        item_div.add_class("spt_drop_display_value")

        add_icon = True
        ExpressionParser.clear_cache()
        if sobject:
            if add_icon:
                my._add_icon(sobject, item_div)

            if my.display_expr:
                display_value = Search.eval(my.display_expr, sobjects = sobject, single=True)
            else:
                display_value = sobject.get_display_value()
            if isinstance(display_value, list):
                display_value = display_value[0]
            item_div.add( display_value )
            my.values.append( SearchKey.get_by_sobject(sobject) )
        return top
开发者ID:asmboom,项目名称:TACTIC,代码行数:43,代码来源:drop_element_wdg.py

示例13: handle_sobject

    def handle_sobject(my, main_sobject, caller, notification, input):

        # TODO: deal with parents later
        parent = main_sobject.get_parent()

        snapshot = input.get('snapshot')
        env_sobjects = {}
        if snapshot:
            env_sobjects = {
                'snapshot': snapshot
            }
        
        # get the rules from the database
        rules_xml = notification.get_xml_value("rules")
        rule_nodes = rules_xml.get_nodes("rules/rule")
        is_skipped = True

        parser = ExpressionParser()
        
        # process the rules
        for rule_node in rule_nodes:
            rule = []
            group_type = Xml.get_attribute( rule_node, "group" )
            rule_key = Xml.get_attribute(rule_node, 'key')
            rule_value = Xml.get_attribute(rule_node, 'value')
            compare = Xml.get_attribute(rule_node, 'compare')

            # evaluate the expression if it exists
            expression = Xml.get_node_value(rule_node)
            if expression:
                result = parser.eval(expression, main_sobject, env_sobjects=env_sobjects)
                if not result:
                    break
                else:
                    continue

            # DEPRECATED: likely the expression complete replaces this
            # parse the rule
            if group_type == "sobject":
                if not my._process_sobject(main_sobject, rule_key, compare):
                    break
                value = main_sobject.get_value(rule_key, no_exception=True )
            elif group_type == "parent":
                if not parent or not my._process_sobject(parent, rule_key, compare):
                    break
                value = parent.get_value(rule_key, no_exception=True )
            else: # group_type == 'command'
                try:
                    value = caller.get_info(rule_key)
                except:
                    value = ''
            if not value:
                break
            
            # match the rule to the value
            p = re.compile(rule_value)
            if not p.match(value):
                print "... skipping: '%s' != %s" % (value, rule_value)
                break

        else:
            is_skipped = False


        # allow the handler to check for whether an email should be sent
        handler = my.get_email_handler(notification, main_sobject, parent, caller, input)
        if is_skipped or not handler.check_rule():
            my.add_description('Notification not sent due to failure to pass the set rules. Comment out the rules for now if you are just running email test.')
            return

        print "sending email!!!"

        # if all rules are met then get the groups for this notification
        try:
            to_users = handler.get_to()
            cc_users = handler.get_cc()
            bcc_users = handler.get_bcc()


            subject = handler.get_subject()
            if len(subject) > 60:
                subject = subject[0:60] + " ..."
            message = handler.get_message()
        except SObjectValueException, e:
            raise Exception("Error in running Email handler [%s]. %s" \
                    %(handler.__class__.__name__, e.__str__()))
开发者ID:0-T-0,项目名称:TACTIC,代码行数:86,代码来源:email_trigger.py

示例14: process_data_gather

    def process_data_gather( self, search_key, gather_specs, layout_html ):

        sobject = Search.get_by_search_key( search_key )
        for label,info in gather_specs.iteritems():

            if label == "@":
                subs_list = info.get("element_subs")
                for sub in subs_list:
                    value = sobject.get_value( sub )
                    if not value:
                        value = "&nbsp;"
                    substitution_tag = "${@.%s}" % sub
                    layout_html = layout_html.replace( substitution_tag, "%s" % value )

            elif info.get("type") == "sobject":
                expr = info.get("expr")
                expr_vars_list = info.get("expr_vars")
                if expr_vars_list:
                    for e_var in expr_vars_list:
                        bits = e_var.split("=")
                        var_name = bits[0]
                        value = sobject.get_value( bits[1].replace("@.","") )
                        expr = expr.replace( var_name, "%s" % value )
                parser = ExpressionParser()
                result = parser.eval( expr )
                if result:
                    if type(result) == types.ListType:
                        other_sobject = result[0]
                    else:
                        other_sobject = result
                    subs_list = info.get("element_subs")
                    for sub in subs_list:
                        src_col = sub
                        dst_col = sub
                        if "#" in sub:
                            sub_bits = sub.split("#")
                            src_col = sub_bits[0]
                            dst_col = sub_bits[1]
                        value = other_sobject.get_value( src_col )
                        if not value:
                            value = "&nbsp;"
                        if "_date" in dst_col:
                            value = value.split(" ")[0]
                        if "_time" in dst_col:
                            time_bits = value.split(" ")[1].split(":")
                            value = "%s:%s" % (time_bits[0], time_bits[1])
                        substitution_tag = "${%s.%s}" % (label, dst_col )
                        layout_html = layout_html.replace( substitution_tag, "%s" % value )

            elif info.get("type") == "gather_list_class":
                import_stmt = "%s as GatherClass" % info.get("import_stmt")
                exec import_stmt
                gc = GatherClass( sobject )
                item_list = gc.get_items()

                subs_list = info.get("element_subs")
                for c, item in enumerate(item_list):
                    for sub in subs_list:
                        substitution_tag = "${%s[%s].%s}" % (label, c, sub)
                        layout_html = layout_html.replace( substitution_tag, "%s" % item[ sub ] )

                max_id = info.get("max_id")
                if max_id > (len(item_list) - 1):
                    for c in range(len(item_list),max_id+1):
                        for sub in subs_list:
                            substitution_tag = "${%s[%s].%s}" % (label, c, sub)
                            layout_html = layout_html.replace( substitution_tag, "&nbsp;" )


            elif info.get("type") == "value":
                parser = ExpressionParser()
                value = parser.eval( info.get("expr"), sobject )
                if not value:
                    value = "&nbsp;"
                layout_html = layout_html.replace( "${%s}" % label, "%s" % value )

        return layout_html
开发者ID:mincau,项目名称:TACTIC,代码行数:77,代码来源:custom_print_view_wdg.py

示例15: alter_search

    def alter_search(self, search):
        if self.is_admin_flag:
            return True

        group = "search_filter"
        search_type = search.get_base_search_type()

        self.alter_search_type_search(search)
        rules = self.groups.get(group)
        if not rules:
            return


        from pyasm.biz import ExpressionParser
        parser = ExpressionParser()
        current_project = None


        # preprocess to get a list of rule that will apply
        rules_dict = {}
        for rule_item in rules.values():
            access, dct = rule_item

            rule = dct
            rule_search_type = rule.get('search_type')
            if not rule_search_type:
                print "No [search_type] defined in security rule"
                continue

            # search types must match
            if rule_search_type != search_type:
                continue

            project = rule.get('project')
           
            # to avoid infinite recursion, get the project here
            if not current_project:
                from pyasm.biz import Project
                current_project = Project.get_project_code()
            
            if project and project not in ['*', current_project]:
                continue


            column = rule.get('column')
            rules_list = rules_dict.get(column)
            if rules_list == None:
                rules_list = []
                rules_dict[column] = rules_list

            rules_list.append(rule)



        for column, rules_list in rules_dict.items():

            if len(rules_list) > 1:
                search.add_op("begin")


            for rule in rules_list:

                column = rule.get('column')
                value = rule.get('value')
               

                # If a relationship is set, then use that
                related = rule.get('related')

                sudo = Sudo()
                if related:

                    sobjects = parser.eval(related)
                    search.add_relationship_filters(sobjects)
                    del sudo
                    return


                # interpret the value
                # since the expression runs float(), we want to avoid that a number 5 being converted to 5.0
                # if we can't find @ or $
                if value.find('@') != -1 or value.find('$') != -1:
                    values = parser.eval(value, list=True)
                elif value.find("|") == -1:
                    values = value.split("|")
                else:
                    values = [value]

                op = rule.get('op')
                

                # TODO: made this work with search.add_op_filters() with the expression parser instead of this
                # simpler implementation
                if len(values) == 1:
                    if not op:
                        op = '='
                    quoted = True
                    # special case for NULL
                    if values[0] == 'NULL':
                        quoted = False
#.........这里部分代码省略.........
开发者ID:mincau,项目名称:TACTIC,代码行数:101,代码来源:access_manager.py


注:本文中的pyasm.biz.ExpressionParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。