Fixes in datetime and admin home
This commit is contained in:
parent
f5adbc376a
commit
7c11620287
3 changed files with 79 additions and 24 deletions
|
|
@ -129,34 +129,64 @@ def checkdatetime(y, m, d, h, mi, s):
|
|||
except:
|
||||
return False
|
||||
|
||||
# Obtain the actual time in local or gmt
|
||||
# Get the localtime
|
||||
|
||||
def now(gmt=False):
|
||||
def now(utc=False):
|
||||
|
||||
actual=datetime.today()
|
||||
|
||||
final_date=actual.strftime(sql_format_time)
|
||||
# Get localtime
|
||||
|
||||
final_date=actual.strftime(sql_format_time)
|
||||
#Go to gmt
|
||||
|
||||
if utc:
|
||||
|
||||
if gmt:
|
||||
|
||||
final_date=local_to_gmt(final_date)
|
||||
|
||||
return final_date
|
||||
|
||||
# Get actual timestamp
|
||||
|
||||
def obtain_timestamp(timeform):
|
||||
def obtain_timestamp(timeform, local=False):
|
||||
|
||||
y, m, d, h, mi, s=format_timedata(timeform)
|
||||
|
||||
|
||||
if checkdatetime(y, m, d, h, mi, s):
|
||||
|
||||
return int(time.mktime((y, m, d, h, mi, s, 0, 1, 0)))
|
||||
timestamp=int(time.mktime((y, m, d, h, mi, s, 0, 0, -1)))
|
||||
|
||||
if local:
|
||||
|
||||
offset=time.altzone
|
||||
|
||||
return timestamp-offset
|
||||
|
||||
return timestamp
|
||||
|
||||
#return mktime($h, $mi, $s, $m, $d, $y);
|
||||
else:
|
||||
return False
|
||||
|
||||
def format_datetime(format_time, timestamp, func_utc_return):
|
||||
# timestamp is gmt time, convert in normal time
|
||||
|
||||
def timestamp_to_datetime(timestamp):
|
||||
|
||||
timestamp=obtain_timestamp(timestamp)
|
||||
time_set=substract_utc(timestamp)
|
||||
|
||||
return time.strftime(sql_format_time, time_set)
|
||||
|
||||
|
||||
def timestamp_to_datetime_local(timestamp):
|
||||
|
||||
time_set=time.localtime(timestamp)
|
||||
|
||||
return time.strftime(sql_format_time, time_set)
|
||||
|
||||
|
||||
def format_datetime(format_time, timeform, func_utc_return):
|
||||
|
||||
timestamp=obtain_timestamp(timeform)
|
||||
|
||||
if timestamp:
|
||||
|
||||
|
|
@ -174,30 +204,41 @@ def format_datetime(format_time, timestamp, func_utc_return):
|
|||
|
||||
return False
|
||||
|
||||
# This method parse local time to gmt
|
||||
|
||||
def local_to_gmt(timeform):
|
||||
|
||||
return format_datetime(sql_format_time, timeform, time.gmtime)
|
||||
|
||||
# time.localtime is useless, you need sum the time offset to the date
|
||||
|
||||
def gmt_to_local(timeform):
|
||||
|
||||
return format_datetime(sql_format_time, timeform, sum_utc)
|
||||
|
||||
def format_time(timeform):
|
||||
|
||||
return format_datetime(format_time_txt, timeform, time.localtime)
|
||||
return format_datetime(format_time_txt, timeform, sum_utc)
|
||||
|
||||
def format_date(timeform):
|
||||
|
||||
return format_datetime(format_date_txt, timeform, time.localtime)
|
||||
return format_datetime(format_date_txt, timeform, sum_utc)
|
||||
|
||||
def format_fulldate(timeform):
|
||||
|
||||
return format_datetime(format_date_txt+' '+format_time_txt, timeform, time.localtime)
|
||||
return format_datetime(format_date_txt+' '+format_time_txt, timeform, sum_utc)
|
||||
|
||||
def sum_utc(timestamp, offset):
|
||||
def sum_utc(timestamp):
|
||||
|
||||
offset=time.altzone
|
||||
|
||||
return timestamp+offset
|
||||
return time.localtime(timestamp-offset)
|
||||
|
||||
def substract_utc(timestamp, offset):
|
||||
def substract_utc(timestamp):
|
||||
|
||||
offset=time.altzone
|
||||
|
||||
return timestamp-offset
|
||||
return time.localtime(timestamp+offset)
|
||||
|
||||
|
||||
"""
|
||||
|
|
@ -306,4 +347,4 @@ def obtain_timezone(timezone):
|
|||
return get_timezone(timezone)
|
||||
|
||||
|
||||
"""
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -449,19 +449,29 @@ class WebModel:
|
|||
if (self.name_field_id not in fields_selected):
|
||||
fields_selected.append(self.name_field_id)
|
||||
def del_row_id(row):
|
||||
del row[self.name_field_id]
|
||||
|
||||
try:
|
||||
|
||||
index_id=row.index(self.name_field_id)
|
||||
|
||||
del row[index_id]
|
||||
|
||||
except:
|
||||
|
||||
pass
|
||||
else:
|
||||
def del_row_id(row):
|
||||
pass
|
||||
|
||||
cursor=self.select(fields_selected, raw_query)
|
||||
|
||||
results=OrderedDict()
|
||||
results=[] #OrderedDict()
|
||||
|
||||
for row in cursor:
|
||||
|
||||
results[row[self.name_field_id]]=row
|
||||
del_row_id(results[row[self.name_field_id]])
|
||||
results.append(row)
|
||||
|
||||
del_row_id(results)
|
||||
|
||||
cursor.close()
|
||||
|
||||
|
|
|
|||
|
|
@ -43,9 +43,13 @@ ${HeaderHTML.header_home()|n}
|
|||
<div class="menu_title">${lang('admin', 'applications', 'Applications')}</div>
|
||||
% for module in menu:
|
||||
% if type(menu[module]).__name__=='list':
|
||||
<a href="${make_url('admin/'+module)}">${menu[module][0]}</a>
|
||||
% if menu[module][0]!="":
|
||||
<a href="${make_url('admin/'+module)}">${menu[module][0]}</a>
|
||||
% endif
|
||||
% else:
|
||||
<div class="father_admin">${menu[module]}</div>
|
||||
% if menu[module]!="":
|
||||
<div class="father_admin">${menu[module]}</div>
|
||||
% endif
|
||||
% endif
|
||||
% endfor
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue