Added datetime functions
This commit is contained in:
parent
f95c10a935
commit
ded04f96b0
8 changed files with 164 additions and 25 deletions
93
paramecio/citoplasma/datetime.py
Normal file
93
paramecio/citoplasma/datetime.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
from datetime import date, datetime, time
|
||||
from babel.dates import format_date, format_datetime, format_time, get_timezone, UTC
|
||||
from settings import config
|
||||
|
||||
#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
|
||||
|
||||
if hasattr(config, 'timezone'):
|
||||
timezone=config.timezone
|
||||
else:
|
||||
timezone='UTC'
|
||||
|
||||
tzutc=get_timezone('UTC')
|
||||
|
||||
tz = get_timezone(timezone)
|
||||
|
||||
# In utc
|
||||
|
||||
def timenow():
|
||||
|
||||
t=datetime.utcnow()
|
||||
|
||||
return format_datetime(t, "yyyyLLddHHmmss", tzutc)
|
||||
|
||||
#In utc
|
||||
|
||||
def normalize_time(year, month, day, hour, minute, second):
|
||||
|
||||
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):
|
||||
|
||||
#try:
|
||||
|
||||
year, month, day, hour, minute, second=obtain_fields_time(time)
|
||||
|
||||
t=datetime(year, month, day, hour, minute, second)
|
||||
|
||||
return format_datetime(t, locale="es_ES", tzinfo=tz)
|
||||
|
||||
#except:
|
||||
|
||||
# return timenow()
|
||||
|
||||
|
|
@ -5,6 +5,7 @@ from paramecio.citoplasma.mtemplates import set_flash_message
|
|||
from paramecio.cromosoma.formsutils import show_form
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
from collections import OrderedDict
|
||||
|
||||
class GenerateAdminClass:
|
||||
|
||||
|
|
@ -43,6 +44,8 @@ class GenerateAdminClass:
|
|||
self.template_insert='utils/insertform.phtml'
|
||||
|
||||
self.template_admin='utils/admin.phtml'
|
||||
|
||||
self.template_verify_delete='utils/verify_delete.phtml'
|
||||
|
||||
def show(self):
|
||||
|
||||
|
|
@ -52,13 +55,19 @@ class GenerateAdminClass:
|
|||
|
||||
GetPostFiles.get['id']=GetPostFiles.get.get('id', '0')
|
||||
|
||||
if len(self.model.forms)==0:
|
||||
|
||||
self.model.create_forms()
|
||||
|
||||
edit_forms=OrderedDict()
|
||||
|
||||
for key_form in self.arr_fields_edit:
|
||||
edit_forms[key_form]=self.model.forms[key_form]
|
||||
|
||||
if GetPostFiles.get['op_admin']=='1':
|
||||
|
||||
post=None
|
||||
|
||||
if len(self.model.forms)==0:
|
||||
self.model.create_forms()
|
||||
|
||||
title_edit=I18n.lang('common', 'add_new_item', 'Add new item')
|
||||
|
||||
if GetPostFiles.get['id']!='0':
|
||||
|
|
@ -68,11 +77,6 @@ class GenerateAdminClass:
|
|||
if post==None:
|
||||
post={}
|
||||
|
||||
edit_forms={}
|
||||
|
||||
for key_form in self.arr_fields_edit:
|
||||
edit_forms[key_form]=self.model.forms[key_form]
|
||||
|
||||
form=show_form(post, edit_forms, self.t, False)
|
||||
|
||||
return self.t.load_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=GetPostFiles.get['id'])
|
||||
|
|
@ -106,19 +110,27 @@ class GenerateAdminClass:
|
|||
redirect(self.url)
|
||||
else:
|
||||
|
||||
form=show_form(post, self.model.forms, self.t, True)
|
||||
form=show_form(post, edit_forms, self.t, True)
|
||||
return self.t.load_template(self.template_insert, admin=self, title_edit=title_edit, form=form, model=self.model, id=GetPostFiles.get['id'])
|
||||
|
||||
|
||||
pass
|
||||
|
||||
elif GetPostFiles.get['op_admin']=='3':
|
||||
|
||||
verified=GetPostFiles.get.get('verified', '0')
|
||||
|
||||
if verified=='1':
|
||||
|
||||
if GetPostFiles.get['id']!='0':
|
||||
self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [GetPostFiles.get['id']]]
|
||||
self.model.delete()
|
||||
set_flash_message(I18n.lang('common', 'task_successful', 'Task successful'))
|
||||
redirect(self.url)
|
||||
if GetPostFiles.get['id']!='0':
|
||||
self.model.conditions=['WHERE `'+self.model.name+'`.`'+self.model.name_field_id+'`=%s', [GetPostFiles.get['id']]]
|
||||
self.model.delete()
|
||||
set_flash_message(I18n.lang('common', 'task_successful', 'Task successful'))
|
||||
redirect(self.url)
|
||||
|
||||
else:
|
||||
|
||||
return self.t.load_template(self.template_verify_delete, url=self.url, item_id=GetPostFiles.get['id'], op_admin=3, verified=1)
|
||||
|
||||
else:
|
||||
return self.t.load_template(self.template_admin, admin=self)
|
||||
|
|
|
|||
8
paramecio/citoplasma/templates/utils/verify_delete.phtml
Normal file
8
paramecio/citoplasma/templates/utils/verify_delete.phtml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<form method="get" action="${url}">
|
||||
<div class="form">
|
||||
<input type="hidden" name="id" value="${item_id}">
|
||||
<input type="hidden" name="op_admin" value="${op_admin}">
|
||||
<input type="hidden" name="verified" value="${verified}">
|
||||
<input type="submit" value="${lang('common', 'delete_item_you_sure', 'Are you sure for delete this item?')}" />
|
||||
</div>
|
||||
</form>
|
||||
Loading…
Add table
Add a link
Reference in a new issue