From 7c11620287556a0e9f5568099e8ee29e81564062 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 26 May 2016 05:26:33 +0200 Subject: [PATCH] Fixes in datetime and admin home --- paramecio/citoplasma/datetime.py | 77 ++++++++++++++----- paramecio/cromosoma/webmodel.py | 18 ++++- .../modules/admin/templates/admin/home.html | 8 +- 3 files changed, 79 insertions(+), 24 deletions(-) diff --git a/paramecio/citoplasma/datetime.py b/paramecio/citoplasma/datetime.py index 4bf2245..d8cba0a 100644 --- a/paramecio/citoplasma/datetime.py +++ b/paramecio/citoplasma/datetime.py @@ -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) -""" \ No newline at end of file +""" diff --git a/paramecio/cromosoma/webmodel.py b/paramecio/cromosoma/webmodel.py index 7264789..2b23c0d 100644 --- a/paramecio/cromosoma/webmodel.py +++ b/paramecio/cromosoma/webmodel.py @@ -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() diff --git a/paramecio/modules/admin/templates/admin/home.html b/paramecio/modules/admin/templates/admin/home.html index 1daf643..7699e9b 100644 --- a/paramecio/modules/admin/templates/admin/home.html +++ b/paramecio/modules/admin/templates/admin/home.html @@ -43,9 +43,13 @@ ${HeaderHTML.header_home()|n} % for module in menu: % if type(menu[module]).__name__=='list': - ${menu[module][0]} + % if menu[module][0]!="": + ${menu[module][0]} + % endif % else: -
${menu[module]}
+ % if menu[module]!="": +
${menu[module]}
+ % endif % endif % endfor