Fixes in libraries
This commit is contained in:
parent
6a68dcd47c
commit
4d814326e0
6 changed files with 41 additions and 37 deletions
0
paramecio2/console.py
Normal file → Executable file
0
paramecio2/console.py
Normal file → Executable file
|
|
@ -153,10 +153,10 @@ def obtain_timestamp(timeform, local=False, tz=''):
|
||||||
|
|
||||||
t=arrow.arrow.Arrow(y, m, d, h, mi, s).to(tz)
|
t=arrow.arrow.Arrow(y, m, d, h, mi, s).to(tz)
|
||||||
|
|
||||||
timestamp=t.timestamp
|
timestamp=t.timestamp()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
timestamp=arrow.arrow.Arrow(y, m, d, h, mi, s).timestamp
|
timestamp=arrow.arrow.Arrow(y, m, d, h, mi, s).timestamp()
|
||||||
|
|
||||||
return timestamp
|
return timestamp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,12 @@ class FloatField(PhangoField):
|
||||||
|
|
||||||
return 'FLOAT NOT NULL DEFAULT "0"'
|
return 'FLOAT NOT NULL DEFAULT "0"'
|
||||||
|
|
||||||
|
class DecimalField(FloatField):
|
||||||
|
|
||||||
|
def get_type_sql(self):
|
||||||
|
|
||||||
|
return 'DECIMAL(20, 2) NOT NULL DEFAULT "0"'
|
||||||
|
|
||||||
class DoubleField(FloatField):
|
class DoubleField(FloatField):
|
||||||
|
|
||||||
def get_type_sql(self):
|
def get_type_sql(self):
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,17 @@ class TextForm(BaseForm):
|
||||||
|
|
||||||
class PasswordForm(BaseForm):
|
class PasswordForm(BaseForm):
|
||||||
|
|
||||||
def __init__(self, name, value):
|
def __init__(self, name, value, show_password=False):
|
||||||
super(PasswordForm, self).__init__(name, value)
|
super(PasswordForm, self).__init__(name, value)
|
||||||
self.type='password'
|
self.type='password'
|
||||||
|
self.show_password=show_password
|
||||||
|
|
||||||
def setform(self, value):
|
def setform(self, value):
|
||||||
return ""
|
if not self.show_password:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
class HiddenForm(BaseForm):
|
class HiddenForm(BaseForm):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
from paramecio2.libraries.db.corefields import FloatField
|
from paramecio2.libraries.db.corefields import DecimalField
|
||||||
from decimal import Decimal, getcontext
|
from decimal import Decimal, getcontext
|
||||||
from locale import format_string
|
from locale import format_string
|
||||||
|
|
||||||
getcontext().prec=2
|
getcontext().prec=2
|
||||||
|
|
||||||
class MoneyField(FloatField):
|
class MoneyField(DecimalField):
|
||||||
|
|
||||||
def __init__(self, name, required=False):
|
def __init__(self, name, required=False):
|
||||||
|
|
||||||
|
|
@ -23,4 +23,5 @@ class MoneyField(FloatField):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def format_money(value):
|
def format_money(value):
|
||||||
return format_string('%.2f', Decimal(value), grouping=True)
|
return format_string('%.2f', Decimal(value), grouping=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,22 +22,23 @@ class SendMail:
|
||||||
|
|
||||||
password=''
|
password=''
|
||||||
|
|
||||||
ssl=True
|
#ssl=True
|
||||||
|
|
||||||
if sys.version_info < (3, 6):
|
|
||||||
|
|
||||||
context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLSv1_2)
|
|
||||||
else:
|
|
||||||
context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS)
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, ssl=True):
|
||||||
|
|
||||||
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
|
self.smtp=None #smtplib.SMTP(host=self.host, port=self.port)
|
||||||
self.txt_error=''
|
self.txt_error=''
|
||||||
|
self.ssl=ssl
|
||||||
|
|
||||||
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
|
if sys.version_info < (3, 6):
|
||||||
|
|
||||||
|
self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLSv1_2)
|
||||||
|
else:
|
||||||
|
self.context = ssl_module.SSLContext(ssl_module.PROTOCOL_TLS)
|
||||||
|
|
||||||
if self.ssl==True:
|
if self.ssl==True:
|
||||||
|
|
||||||
|
self.smtp=smtplib.SMTP(host=self.host, port=self.port)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
@ -60,19 +61,13 @@ class SendMail:
|
||||||
self.txt_error=e.__str__()
|
self.txt_error=e.__str__()
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
"""
|
#login
|
||||||
except smtplib.SMTPNotSupportedError:
|
|
||||||
|
|
||||||
self.txt_error='Error: SSL/TLS is not supported'
|
|
||||||
|
|
||||||
return False
|
|
||||||
"""
|
|
||||||
|
|
||||||
if self.username!='':
|
if self.username!='':
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
self.smtp.login(self.username, self.password)
|
self.smtp.login(self.username, self.password)
|
||||||
|
|
||||||
except smtplib.SMTPHeloError:
|
except smtplib.SMTPHeloError:
|
||||||
|
|
@ -92,15 +87,9 @@ class SendMail:
|
||||||
self.txt_error='Error: any method for login is avaliable - '+e.__str__()
|
self.txt_error='Error: any method for login is avaliable - '+e.__str__()
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
"""
|
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
|
||||||
except smtplib.SMTPNotSupportedError:
|
|
||||||
|
|
||||||
self.txt_error='Error: AUTH is not supported'
|
|
||||||
|
|
||||||
return False
|
|
||||||
"""
|
|
||||||
|
|
||||||
COMMASPACE=', '
|
COMMASPACE=', '
|
||||||
|
|
||||||
if len(attachments)==0:
|
if len(attachments)==0:
|
||||||
|
|
@ -177,9 +166,12 @@ class SendMail:
|
||||||
|
|
||||||
def quit(self):
|
def quit(self):
|
||||||
|
|
||||||
self.smtp.quit()
|
if self.smtp!=None:
|
||||||
|
self.smtp.quit()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
|
||||||
self.smtp.quit()
|
if self.smtp!=None:
|
||||||
|
|
||||||
|
self.smtp.quit()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue