本文整理汇总了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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)
示例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