Fixes in datetime and admin home

This commit is contained in:
Antonio de la Rosa 2016-05-26 05:26:33 +02:00
parent f5adbc376a
commit 7c11620287
3 changed files with 79 additions and 24 deletions

View file

@ -129,34 +129,64 @@ def checkdatetime(y, m, d, h, mi, s):
except: except:
return False return False
# Obtain the actual time in local or gmt # Get the localtime
def now(gmt=False): def now(utc=False):
actual=datetime.today() 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) final_date=local_to_gmt(final_date)
return 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) y, m, d, h, mi, s=format_timedata(timeform)
if checkdatetime(y, m, d, h, mi, s): 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); #return mktime($h, $mi, $s, $m, $d, $y);
else: else:
return False 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: if timestamp:
@ -174,30 +204,41 @@ def format_datetime(format_time, timestamp, func_utc_return):
return False return False
# This method parse local time to gmt
def local_to_gmt(timeform): def local_to_gmt(timeform):
return format_datetime(sql_format_time, timeform, time.gmtime) 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): 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): 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): 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) return get_timezone(timezone)
""" """

View file

@ -449,19 +449,29 @@ class WebModel:
if (self.name_field_id not in fields_selected): if (self.name_field_id not in fields_selected):
fields_selected.append(self.name_field_id) fields_selected.append(self.name_field_id)
def del_row_id(row): 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: else:
def del_row_id(row): def del_row_id(row):
pass pass
cursor=self.select(fields_selected, raw_query) cursor=self.select(fields_selected, raw_query)
results=OrderedDict() results=[] #OrderedDict()
for row in cursor: for row in cursor:
results[row[self.name_field_id]]=row results.append(row)
del_row_id(results[row[self.name_field_id]])
del_row_id(results)
cursor.close() cursor.close()

View file

@ -43,9 +43,13 @@ ${HeaderHTML.header_home()|n}
<div class="menu_title">${lang('admin', 'applications', 'Applications')}</div> <div class="menu_title">${lang('admin', 'applications', 'Applications')}</div>
% for module in menu: % for module in menu:
% if type(menu[module]).__name__=='list': % 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: % else:
<div class="father_admin">${menu[module]}</div> % if menu[module]!="":
<div class="father_admin">${menu[module]}</div>
% endif
% endif % endif
% endfor % endfor
</div> </div>