當前位置: 首頁>>代碼示例>>Python>>正文


Python common.SPTDate類代碼示例

本文整理匯總了Python中pyasm.common.SPTDate的典型用法代碼示例。如果您正苦於以下問題:Python SPTDate類的具體用法?Python SPTDate怎麽用?Python SPTDate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SPTDate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: convert_value

    def convert_value(self, col_type, value):
        if col_type == 'timecode':
            timecode = TimeCode(timecode=value)
            value = timecode.get_frames()
        elif col_type in ["time", "timestamp"]:

            from pyasm.common import SPTDate
            if not value:
                value = ""
            elif not SPTDate.has_timezone(value):
                timezone = PrefSetting.get_value_by_key('timezone')
                if timezone:
                    value = SPTDate.add_timezone(value, timezone)
                else:
                    value = SPTDate.add_local_timezone(value)
        elif col_type in ["float", "integer"]:
            if isinstance(value, basestring):
                value = value.replace(",", "")
                if value.startswith("$"):
                    value = value.lstrip("$")

            try:
                if not value:
                    value = None
                elif col_type == "float":
                    value = float(value)
                else:
                    value = int(value)
            except:
                raise UserException("[%s] must a number." % value)
        return value
開發者ID:mincau,項目名稱:TACTIC,代碼行數:31,代碼來源:edit_wdg_action.py

示例2: main

def main(server=None, input=None):
    """
    The main function of the custom script. The entire script was copied
    and pasted into the body of the try statement in order to add some
    error handling. It's all legacy code, so edit with caution.

    :param server: the TacticServerStub object
    :param input: a dict with data like like search_key, search_type, sobject, and update_data
    :return: None
    """
    if not input:
        input = {}

    try:
        # CUSTOM_SCRIPT00046
        #print "UPDATE TASK SORT ESSENTIALS"
        from pyasm.common import SPTDate
        update_data = input.get('update_data')
        sobject = input.get('sobject')
        if 'twog/title' in sobject.get('search_type'):
            server.update(input.get('search_key'), {'tripwire': ''}, triggers=False)
            proj_sk = server.build_search_key('twog/proj', sobject.get('lookup_code'))
            proj_data = {}
            task_data = {}
            if 'bid_end_date' in update_data:
                proj_data['due_date'] = SPTDate.convert_to_local(update_data.get('bid_end_date'))
                task_data['bid_end_date'] = proj_data['due_date']
            if proj_data != {}:
                server.update(proj_sk, proj_data, triggers=False)
                wos = server.eval("@SOBJECT(twog/work_order['proj_code','%s'])" % sobject.get('lookup_code'))
                for wo in wos:
                    server.update(wo.get('__search_key__'), proj_data, triggers=False) 
                    if wo.get('task_code') not in [None,'']:
                        task = server.eval("@SOBJECT(sthpw/task['code','%s'])" % wo.get('task_code'))
                        if len(task) > 0:
                            task = task[0]
                            task_data['tripwire'] = ''
                            server.update(task.get('__search_key__'), task_data, triggers=False)
        elif 'twog/proj' in sobject.get('search_type'):
            wo_sk = server.build_search_key('twog/work_order', sobject.get('lookup_code'))
            wo_data = {}
            if 'bid_end_date' in update_data:
                wo_data['due_date'] = SPTDate.convert_to_local(update_data.get('bid_end_date'))
            if wo_data != {}:
                server.update(wo_sk, wo_data, triggers=False)
        #print "LEAVING UPDATE TASK SORT ESSENTIALS"
    except AttributeError as e:
        traceback.print_exc()
        print str(e) + '\nMost likely the server object does not exist.'
        raise e
    except KeyError as e:
        traceback.print_exc()
        print str(e) + '\nMost likely the input dictionary does not exist.'
        raise e
    except Exception as e:
        traceback.print_exc()
        print str(e)
        raise e
開發者ID:2gDigitalPost,項目名稱:custom,代碼行數:58,代碼來源:update_task_sort_essentials.py

示例3: convert_value

 def convert_value(my, col_type, value):
     if col_type == 'timecode':
         timecode = TimeCode(timecode=value)
         value = timecode.get_frames()
     elif col_type in ["time", "timestamp"]:
         from pyasm.common import SPTDate
         if not SPTDate.has_timezone(value):
             value = SPTDate.add_local_timezone(value)
     elif col_type in ["float", "integer"]:
         if isinstance(value, basestring):
             value = value.replace(",", "")
     return value
開發者ID:pombredanne,項目名稱:TACTIC,代碼行數:12,代碼來源:edit_wdg_action.py

示例4: get_timezone_value

 def get_timezone_value(my, value):
     '''given a datetime value, try to convert to timezone specified in the widget.
        If not specified, use the My Preferences time zone'''
     timezone = my.get_option('timezone')
     if not timezone:
         timezone = PrefSetting.get_value_by_key('timezone')
     
     if timezone in ["local", '']:
         value = SPTDate.convert_to_local(value)
     else:
         value = SPTDate.convert_to_timezone(value, timezone)
     
     return value
開發者ID:0-T-0,項目名稱:TACTIC,代碼行數:13,代碼來源:base_table_element_wdg.py

示例5: fix_date

def fix_date(date):
    # This is needed due to the way Tactic deals with dates (using timezone info), post v4.0
    return_date = ''
    date_obj = SPTDate.convert_to_local(date)
    if date_obj not in [None, '']:
        return_date = date_obj.strftime("%Y-%m-%d  %H:%M")
    return return_date
開發者ID:2gDigitalPost,項目名稱:custom,代碼行數:7,代碼來源:common_functions.py

示例6: accesshandler

def accesshandler(request):

    cookies = Cookie.get_cookies(request)

    # if login ticket cookie does not exist, then deny
    if not cookies.has_key('login_ticket'):
        # just refuse access
        return apache.HTTP_FORBIDDEN

    ticket = cookies['login_ticket'].value
    if not ticket:
        return apache.HTTP_FORBIDDEN

    server = TacticServerStub.get(protocol='local')
    expr = "@SOBJECT(sthpw/ticket['ticket','%s'])" % ticket
    sobject = server.eval(expr, single=True)
    now = SPTDate.now()
    expiry = sobject.get("expiry")
    if expiry and expiry < str(now):
        return apache.HTTP_FORBIDDEN

    request.add_common_vars()
    path = str(request.subprocess_env['REQUEST_URI'])
    if path == None:
        return apache.HTTP_FORBIDDEN


    # FIXME: find some mechanism which is more acceptable ... like /icons
    #if path.find("_icon_") != -1:
    #    return apache.OK

    return apache.OK
開發者ID:0-T-0,項目名稱:TACTIC,代碼行數:32,代碼來源:asset_security.py

示例7: init_data

    def init_data(my):

        sobject = my.get_current_sobject()
        value = sobject.get_value(my.due_date_col)
        if not value:
            my.mode = ""
            return

        status = sobject.get_value("status")

        due_date = parser.parse(value)

        # get today's date
        from pyasm.common import SPTDate
        today = SPTDate.start_of_today()

        # get the difference
        delta = due_date - today
        diff = delta.days


        if diff < 0:
            if status.lower() in ["approved", "complete", "done"]:
                mode = "done"
            else:
                mode = "critical"
        elif diff >= 0 and diff < 1:
            mode = "today"
        else:
            mode = "due"
        
        my.mode = mode
        my.diff = diff
開發者ID:nuxping,項目名稱:TACTIC,代碼行數:33,代碼來源:statistic_wdg.py

示例8: get_display

    def get_display(my):

        top = DivWdg()

        value = my.get_value()
        widget_type = my.get_option("type")
        if widget_type in ['integer', 'float', 'timecode', 'currency']:
            top.add_style("float: right")
            my.justify = "right"

        elif widget_type in ['date','time']:
            name = my.get_name()
            if value and not SObject.is_day_column(name):
                value = SPTDate.convert_to_local(value)
                value = str(value)

        else:
            top.add_style("float: left")
            my.justify = "left"
        top.add_style("padding-right: 3px")

        top.add_style("min-height: 15px")

        format = my.get_option('format')
        value = my.get_format_value( value, format )

        top.add(value)

        return top
開發者ID:jayvdb,項目名稱:TACTIC,代碼行數:29,代碼來源:format_element_wdg.py

示例9: make_timestamp

        def make_timestamp():
            from pyasm.common import SPTDate

            # Makes a Timestamp for postgres
            import datetime

            now = SPTDate.convert_to_local(datetime.datetime.now())
            now = datetime.datetime.now()
            return now
開發者ID:2gDigitalPost,項目名稱:custom,代碼行數:9,代碼來源:log_history.py

示例10: main

def main(server=None, input=None):
    """
    The main function of the custom script. The entire script was copied
    and pasted into the body of the try statement in order to add some
    error handling. It's all legacy code, so edit with caution.

    :param server: the TacticServerStub object
    :param input: a dict with data like like search_key, search_type, sobject, and update_data
    :return: None
    """
    if not input:
        input = {}

    try:
        # CUSTOM_SCRIPT00049
        #print "IN SET REVENUE MONTH"
        from pyasm.common import SPTDate
        update_data = input.get('update_data')
        if 'due_date' in update_data.keys():
            if update_data.get('due_date') not in [None,'']:
                sobj = input.get('sobject')
                sk = input.get('search_key')
                if sobj.get('expected_delivery_date') in [None,''] and input.get('is_insert'):
                    server.update(sk, {'expected_revenue_month': SPTDate.convert_to_local(update_data.get('due_date')), 'expected_delivery_date': SPTDate.convert_to_local(update_data.get('due_date'))})
                elif not input.get('is_insert'):
                    do_it = True
                    if 'expected_delivery_date' in update_data.keys():
                        if update_data.get('expected_delivery_date') not in [None,'']:
                            do_it = False 
                    if do_it: 
                        server.update(sk, {'expected_revenue_month': SPTDate.convert_to_local(update_data.get('due_date')), 'expected_delivery_date': SPTDate.convert_to_local(update_data.get('due_date'))})
        #print "LEAVING SET REVENUE MONTH"
    except AttributeError as e:
        traceback.print_exc()
        print str(e) + '\nMost likely the server object does not exist.'
        raise e
    except KeyError as e:
        traceback.print_exc()
        print str(e) + '\nMost likely the input dictionary does not exist.'
        raise e
    except Exception as e:
        traceback.print_exc()
        print str(e)
        raise e
開發者ID:2gDigitalPost,項目名稱:custom,代碼行數:44,代碼來源:set_revenue_month.py

示例11: get_display

    def get_display(my):
        sobject = my.get_current_sobject()

        column =  my.kwargs.get('column')
        if column:
            name = column
        else:
            name = my.get_name()
        
        value = my.get_value(name=name)

        if sobject:
            data_type = SearchType.get_column_type(sobject.get_search_type(), name)
        else:
            data_type = 'text'

        if type(value) in types.StringTypes:
            wiki = WikiUtil()
            value = wiki.convert(value) 
        if name == 'id' and value == -1:
            value = ''

        elif data_type == "timestamp" or name == "timestamp":
	    if value == 'now':
                value = ''
            elif value:
                # This date is assumed to be GMT
                date = parser.parse(value)
                # convert to local
                if not SObject.is_day_column(name):
                    date = SPTDate.convert_to_local(date)
		try:
		   encoding = locale.getlocale()[1]		
		   value = date.strftime("%b %d, %Y - %H:%M").decode(encoding)
		except:
		   value = date.strftime("%b %d, %Y - %H:%M")

            else:
                value = ''
        else:
            if isinstance(value, Widget):
                return value
            elif not isinstance(value, basestring):
                try:
                    value + 1
                except TypeError:
                    value = str(value)
                else:
                    value_wdg = DivWdg()
                    value_wdg.add_style("float: right")
                    value_wdg.add_style("padding-right: 3px")
                    value_wdg.add( str(value) )
                    return value_wdg

        return value
開發者ID:2gDigitalPost,項目名稱:tactic_src,代碼行數:55,代碼來源:base_table_element_wdg.py

示例12: fix_date

def fix_date(date):
    #This is needed due to the way Tactic deals with dates (using timezone info), post v4.0
    from pyasm.common import SPTDate
    date_obj = SPTDate.convert_to_local(date)
    #return_date = ''
    #date_obj = SPTDate.convert_to_timezone(date, 'EDT')
    #print "DATE OBJ = %s" % date_obj
    #if date_obj not in [None,'']:
    #    return_date = date_obj.strftime("%Y-%m-%d  %H:%M:%S")
    #return return_date
    return date_obj
開發者ID:2gDigitalPost,項目名稱:custom,代碼行數:11,代碼來源:update_actual_starts.py

示例13: get_display

    def get_display(my):
        sobject = my.get_current_sobject()
        name = my.get_name()
        value = my.get_value()

        if sobject:
            data_type = SearchType.get_column_type(sobject.get_search_type(), name)
        else:
            data_type = 'text'

        if data_type in ["timestamp","time"] or my.name == "timestamp":
            if value == 'now':
                value = ''
            elif value:
                date = parser.parse(value)
                # we want to match what's in the db which is server local timezone
                if not SPTDate.has_timezone(value):
                    value = SPTDate.convert_to_local(value)
                #value = SPTDate.add_gmt_timezone(date)
                value = str(value)
            else:
                value = ''

        return value
開發者ID:0-T-0,項目名稱:TACTIC,代碼行數:24,代碼來源:base_table_element_wdg.py

示例14: _test_time

    def _test_time(my):
        ''' test timezone related behavior'''
        sobject = SearchType.create('sthpw/task')
        sobject.set_value('project_code','unittest')
        sobject.set_value('bid_start_date', '2014-11-11 05:00:00')
        time = sobject.get_value('bid_start_date')
        my.assertEquals(time, '2014-11-11 05:00:00')

        sobject.commit()

        time = sobject.get_value('bid_start_date')
        my.assertEquals(time, '2014-11-11 05:00:00')
        from pyasm.search import DbContainer
        sql = DbContainer.get('sthpw')
        db_value = sql.do_query('SELECT bid_start_date from task where id = %s'%sobject.get_id())
        
        # 2014-11-11 00:00:00 is actually written to the database
        my.assertEquals(db_value[0][0].strftime('%Y-%m-%d %H:%M:%S %Z'), '2014-11-11 00:00:00 ')
        
        # an sType specified without a project but with an id could be a common human error
        # but it should handle that fine
        obj1 = Search.eval('@SOBJECT(unittest/person?project=unittest["id", "%s"])'%sobject.get_id(), single=True)
        obj2= Search.eval('@SOBJECT(unittest/person?id=2["id", "%s"])'%sobject.get_id(), single=True)
        obj3 = Search.eval('@SOBJECT(sthpw/task?id=2["id", "%s"])'%sobject.get_id(), single=True)
        task = Search.eval('@SOBJECT(sthpw/task["id", "%s"])'%sobject.get_id(), single=True)

        # EST and GMT diff is 5 hours
        my.assertEquals(task.get_value('bid_start_date'), '2014-11-11 05:00:00')


        # test NOW() auto conversion
        sobj = SearchType.create('sthpw/note')
        sobj.set_value('process','TEST')
        sobj.set_value('note','123')
        my.assertEquals(sobj.get_value('timestamp'), "")
        sobj.commit()

        # this is local commited time converted back to GMT
        committed_time = sobj.get_value('timestamp')
        
        from dateutil import parser
        committed_time = parser.parse(committed_time)

        from pyasm.common import SPTDate
        now = SPTDate.now()
        diff = now - committed_time
        # should be roughly the same minute, not hours apart
        my.assertEquals(diff.seconds < 60, True)
開發者ID:0-T-0,項目名稱:TACTIC,代碼行數:48,代碼來源:biz_test.py

示例15: get_text_value

    def get_text_value(my):

        value = my.get_value()
        widget_type = my.get_option("type")
        
        if widget_type in ['date','time']:
            name = my.get_name()
            if not SObject.is_day_column(name):
                value = SPTDate.convert_to_local(value)
                value = str(value)
 
        format = my.get_option('format')
        
        if format == 'Checkbox':
            value = str(value)
        else:
            value = my.get_format_value( value, format )

       
        return value
開發者ID:jayvdb,項目名稱:TACTIC,代碼行數:20,代碼來源:format_element_wdg.py


注:本文中的pyasm.common.SPTDate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。