Fixes in datetime
This commit is contained in:
parent
36c3a9453d
commit
f50701aaee
5 changed files with 116 additions and 13 deletions
|
|
@ -87,22 +87,28 @@ def set_timezone():
|
||||||
|
|
||||||
def format_timedata(time):
|
def format_timedata(time):
|
||||||
|
|
||||||
year=int(time[:4])
|
year=0
|
||||||
|
month=0
|
||||||
month=int(time[4:6])
|
day=0
|
||||||
|
hour=0
|
||||||
day=int(time[6:8])
|
minute=0
|
||||||
|
second=0
|
||||||
hour=int(time[8:10])
|
|
||||||
|
|
||||||
minute=int(time[10:12])
|
|
||||||
|
|
||||||
second=int(time[12:14])
|
|
||||||
|
|
||||||
ampm=''
|
ampm=''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
ampm=int(time[14:16])
|
ampm=int(time[14:16])
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from bottle import hook
|
||||||
from mako.template import Template
|
from mako.template import Template
|
||||||
from mako.lookup import TemplateLookup
|
from mako.lookup import TemplateLookup
|
||||||
from paramecio.citoplasma.urls import make_url, make_media_url, make_media_url_module, add_get_parameters
|
from paramecio.citoplasma.urls import make_url, make_media_url, make_media_url_module, add_get_parameters
|
||||||
|
|
@ -17,8 +18,17 @@ env = Environment(loader=FileSystemLoader(['/path/to/templates', '/other/path'])
|
||||||
template = env.get_template('mytemplate.html')
|
template = env.get_template('mytemplate.html')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
#@hook('after_request')
|
||||||
|
#def clean_tpl_cache():
|
||||||
|
|
||||||
|
#ptemplate.clean_header_cache()
|
||||||
|
#pass
|
||||||
|
|
||||||
|
|
||||||
class ptemplate:
|
class ptemplate:
|
||||||
|
|
||||||
|
template_context=None
|
||||||
|
|
||||||
def __init__(self, module):
|
def __init__(self, module):
|
||||||
|
|
||||||
module=path.dirname(module)
|
module=path.dirname(module)
|
||||||
|
|
@ -63,7 +73,8 @@ class ptemplate:
|
||||||
HeaderHTML.css_local={}
|
HeaderHTML.css_local={}
|
||||||
HeaderHTML.js_local={}
|
HeaderHTML.js_local={}
|
||||||
|
|
||||||
def clean_header_cache(self):
|
@staticmethod
|
||||||
|
def clean_header_cache():
|
||||||
|
|
||||||
HeaderHTML.css=[]
|
HeaderHTML.css=[]
|
||||||
HeaderHTML.js=[]
|
HeaderHTML.js=[]
|
||||||
|
|
@ -140,6 +151,9 @@ class HeaderHTML:
|
||||||
for js in arr_js:
|
for js in arr_js:
|
||||||
final_js.append('<script language="Javascript" src="'+make_media_url_module('js/'+js, module)+'"></script>')
|
final_js.append('<script language="Javascript" src="'+make_media_url_module('js/'+js, module)+'"></script>')
|
||||||
|
|
||||||
|
HeaderHTML.js=[]
|
||||||
|
HeaderHTML.js_local={}
|
||||||
|
|
||||||
return "\n".join(final_js)
|
return "\n".join(final_js)
|
||||||
|
|
||||||
def css_home():
|
def css_home():
|
||||||
|
|
@ -155,6 +169,9 @@ class HeaderHTML:
|
||||||
|
|
||||||
final_css.append('<link href="'+make_media_url_module('css/'+css, module)+'" rel="stylesheet" type="text/css"/>')
|
final_css.append('<link href="'+make_media_url_module('css/'+css, module)+'" rel="stylesheet" type="text/css"/>')
|
||||||
|
|
||||||
|
HeaderHTML.css=[]
|
||||||
|
HeaderHTML.css_local={}
|
||||||
|
|
||||||
return "\n".join(final_css)
|
return "\n".join(final_css)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -229,3 +246,4 @@ def show_flash_message():
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
standard_t=ptemplate(__file__)
|
||||||
|
|
|
||||||
20
paramecio/citoplasma/templates/forms/dateform.phtml
Normal file
20
paramecio/citoplasma/templates/forms/dateform.phtml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
${add_js_home_local('jquery.min.js', 'admin')}
|
||||||
|
|
||||||
|
<input type="text" name="${form}_day" id="time_${form}_day" value="${d}" size="2" maxlength="2"/>
|
||||||
|
<input type="text" name="${form}_month" id="time_${form}_month" value="${m}" size="2" maxlength="2"/>
|
||||||
|
<input type="text" name="${form}_year" id="time_${form}_year" value="${y}" size="4" maxlength="4"/>
|
||||||
|
%if yes_time==True:
|
||||||
|
<input type="text" name="${form}_hour" id="time_${form}_hour" value="${h}" size="2" maxlength="2"/>
|
||||||
|
<input type="text" name="${form}_minute" id="time_${form}_minute" value="${min}" size="2" maxlength="2"/>
|
||||||
|
<input type="text" name="${form}_second" id="time_${form}_second" value="${s}" size="2" maxlength="2"/>
|
||||||
|
<input type="hidden" name="${form}" id="time_${form}" value="" />
|
||||||
|
% endif
|
||||||
|
|
||||||
|
<script language="javascript">
|
||||||
|
$(document).submit(function () {
|
||||||
|
|
||||||
|
$("#time_${form}").val($("#time_${form}_year").val()+$("#time_${form}_month").val()+$("#time_${form}_day").val()+$("#time_${form}_hour").val()+$("#time_${form}_minute").val()+$("#time_${form}_second").val());
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
20
paramecio/cromosoma/extrafields/datefield.py
Normal file
20
paramecio/cromosoma/extrafields/datefield.py
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
from paramecio.cromosoma.corefields import CharField
|
||||||
|
from paramecio.citoplasma import datetime
|
||||||
|
|
||||||
|
class DateField(CharField):
|
||||||
|
|
||||||
|
def check(self, value):
|
||||||
|
|
||||||
|
value=datetime.local_to_gmt(value)
|
||||||
|
|
||||||
|
if value==False:
|
||||||
|
|
||||||
|
self.error=True
|
||||||
|
self.error='Date format invalid'
|
||||||
|
return ''
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
|
def show_formatted(self, value):
|
||||||
|
|
||||||
|
return datetime.format_date(value)
|
||||||
39
paramecio/cromosoma/extraforms/dateform.py
Normal file
39
paramecio/cromosoma/extraforms/dateform.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from paramecio.cromosoma.coreforms import BaseForm
|
||||||
|
from paramecio.citoplasma.mtemplates import standard_t
|
||||||
|
from paramecio.citoplasma.datetime import format_timedata
|
||||||
|
|
||||||
|
class DateForm(BaseForm):
|
||||||
|
|
||||||
|
def __init__(self, name, value):
|
||||||
|
|
||||||
|
super().__init__(name, value)
|
||||||
|
|
||||||
|
self.yes_time=False
|
||||||
|
|
||||||
|
def form(self):
|
||||||
|
|
||||||
|
y=''
|
||||||
|
m=''
|
||||||
|
d=''
|
||||||
|
h=''
|
||||||
|
min=''
|
||||||
|
s=''
|
||||||
|
|
||||||
|
time=format_timedata(self.default_value)
|
||||||
|
|
||||||
|
if time==True:
|
||||||
|
y=int(time[0])
|
||||||
|
m=int(time[1])
|
||||||
|
d=int(time[2])
|
||||||
|
h=int(time[3])
|
||||||
|
min=int(time[4])
|
||||||
|
s=int(time[5])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return standard_t.load_template('forms/dateform.phtml', yes_time=self.yes_time, form=self.name, y=y, m=m, d=d, h=h, min=min, s=s)
|
||||||
|
|
||||||
|
#def
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue