From 715979d08fda346465243d3352f4d28e9de010cb Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 12 Apr 2017 04:50:57 +0200 Subject: [PATCH] Multiple fixes in fields --- paramecio/citoplasma/datetime.py | 175 ++---------------- paramecio/cromosoma/extrafields/datefield.py | 16 +- paramecio/cromosoma/extrafields/imagefield.py | 28 +-- 3 files changed, 47 insertions(+), 172 deletions(-) diff --git a/paramecio/citoplasma/datetime.py b/paramecio/citoplasma/datetime.py index 7a66d50..3a1e855 100644 --- a/paramecio/citoplasma/datetime.py +++ b/paramecio/citoplasma/datetime.py @@ -7,48 +7,6 @@ from bottle import hook from paramecio.citoplasma.sessions import get_session from os import environ -#t=datetime.utcnow() - -#format_date(t, locale='es_ES') - -#format_time(t, locale='es_ES') - -# eastern = get_timezone('Europe/Madrid') - -# format_time(t, locale='es_ES', tzdata=eastern) -# 20141112030455 - -# format_datetime(t, "yyyyLLddhhmmss") - -# format_datetime(t, "yyyyLLddhhmmss", tzinfo=eastern - -# class datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None) - -# Is saved in format_datetime utc with utcnow if the field is clear. - -# format_datetime(t, locale="es_ES", tzinfo=eastern) - -# Next convert to - -# Change - -#os.environ['TZ'] = 'America/New_York' - -#time.tzset() - -#>>> time.timezone -#-3600 - -#>>> int(time.time()) -#1451356872 - -#>>> time.mktime((2015, 12, 29, 12, 25, 36, 0, 1, 0)) -#1451384736.0 - -# strftime - -#time.gmtime() -#time.struct_time(tm_year=2015, tm_mon=12, tm_mday=30, tm_hour=2, tm_min=6, tm_sec=56, tm_wday=2, tm_yday=364, tm_isdst=0) sql_format_time='YYYYMMDDHHmmss' @@ -224,16 +182,6 @@ def format_datetime(format_time, timeform, func_utc_return): if timestamp: - #offset=time.timezone - - #timestamp=func_utc_return(timestamp, offset) - - # Return utc - - #time_set=func_utc_return(timestamp) - - #return time.strftime(format_time, time_set) - t=func_utc_return(timestamp) return t.format(format_time) @@ -266,6 +214,19 @@ def format_fulldate(timeform): return format_datetime(format_date_txt+' '+format_time_txt, timeform, sum_utc) +def format_local_time(timeform): + + return format_datetime(format_time_txt, timeform, no_utc) + +def format_local_date(timeform): + + return format_datetime(format_date_txt, timeform, no_utc) + +def format_local_fulldate(timeform): + + return format_datetime(format_date_txt+' '+format_time_txt, timeform, no_utc) + + #Input is utc timestamp, return local arrow object def sum_utc(timestamp): @@ -296,111 +257,7 @@ def substract_utc(timestamp): return t +def no_utc(timestamp): + + return arrow.get(timestamp) -""" -if hasattr(config, 'timezone'): - timezone=config.timezone - -tzutc=get_timezone('UTC') - -tz=get_timezone(timezone) - -# In utc - -def timenow(): - - t=datetime.utcnow() - - return format_datetime(t, "yyyyLLddHHmmss", tzutc) - -def timegmt(time, tzc=None): - - if tzc==None: - tzc=tz - - year, month, day, hour, minute, second=obtain_fields_time(time) - - t=datetime(year, month, day, hour, minute, second) - - return format_datetime(t, "yyyyLLddHHmmss", tzutc) - -#In utc - -def normalize_time(year, month, day, hour, minute, second, tz=None): - - try: - - t=datetime(year, month, day, hour, minute, second) - - return format_datetime(t, "yyyyLLddHHmmss", tzutc) - - except ValueError: - - return timenow() - -def obtain_fields_time(time): - - #year, month, day, hour, minute, second=time - - year=int(time[:4]) - - month=int(time[4:6]) - - day=int(time[6:8]) - - hour=int(time[8:10]) - - minute=int(time[10:12]) - - second=int(time[12:14]) - - return year, month, day, hour, minute, second - -# In the format of tzinfo - -def format_tztime(time, tzc=None): - - if tzc==None: - tzc=tz - - year, month, day, hour, minute, second=obtain_fields_time(time) - - t=datetime(year, month, day, hour, minute, second) - - return format_datetime(t, format_time, tzinfo=tzc) - -def format_tzdate(time, tzc=None): - - if tzc==None: - tzc=tz - - year, month, day, hour, minute, second=obtain_fields_time(time) - - t=datetime(year, month, day, hour, minute, second) - - return format_datetime(t, format_date, tzinfo=tzc) - -def local_to_utc(date, tzc=None): - - if tzc==None: - tzc=tz - - year, month, day, hour, minute, second=obtain_fields_time(date) - - t=datetime(year, month, day, hour, minute, second, tzinfo=get_timezone('Europe/Madrid')) - print(t) - #timestamp=int(time.mktime((year, month, day, hour, minute, second, 0, 1, 0))) - - #timezone_sum=time.timezone - - #timestamp-=timezone_sum - - print(format_datetime(t, "yyyyLLddHHmmss", tzinfo=tzutc)) - - # return timenow() -def obtain_timezone(timezone): - - return get_timezone(timezone) - - -""" diff --git a/paramecio/cromosoma/extrafields/datefield.py b/paramecio/cromosoma/extrafields/datefield.py index d5d0396..0467211 100644 --- a/paramecio/cromosoma/extrafields/datefield.py +++ b/paramecio/cromosoma/extrafields/datefield.py @@ -3,9 +3,21 @@ from paramecio.citoplasma import datetime class DateField(PhangoField): + def __init__(self, name, size=255, required=False): + + super().__init__(name, size, required) + + self.utc=True + def check(self, value): - value=datetime.local_to_gmt(value) + if self.utc: + + value=datetime.local_to_gmt(value) + + elif not datetime.obtain_timestamp(value, True): + + return False if value==False: @@ -17,4 +29,4 @@ class DateField(PhangoField): def show_formatted(self, value): - return datetime.format_date(value) \ No newline at end of file + return datetime.format_date(value) diff --git a/paramecio/cromosoma/extrafields/imagefield.py b/paramecio/cromosoma/extrafields/imagefield.py index 3ca680f..2e19c28 100644 --- a/paramecio/cromosoma/extrafields/imagefield.py +++ b/paramecio/cromosoma/extrafields/imagefield.py @@ -53,7 +53,7 @@ class ImageField(CharField): field_file=self.name+'_file' #if not change - + if not field_file in files_uploaded: if value=='': @@ -71,7 +71,10 @@ class ImageField(CharField): for arr_image in cur: if arr_image[self.name]!='': - os.remove(arr_image[self.name]) + try: + os.remove(arr_image[self.name]) + except: + pass #if arr_image[self.name]!=save_file and arr_image[self.name]!='': @@ -82,7 +85,7 @@ class ImageField(CharField): return '' else: - + value=os.path.basename(value) return self.save_folder+'/'+value @@ -102,24 +105,26 @@ class ImageField(CharField): self.error=True - self.txt_error='Error, file not exists' + self.txt_error='Error, file not have a valid format' return "" - + real_width=im.size[0] real_height=im.size[1] - + if self.sizes: + if 'maximum' in self.sizes: - if self.sizes.size['maximum'][0]