Many fixes and docstrings

This commit is contained in:
Antonio de la Rosa 2022-04-01 01:04:29 +02:00
parent eb93be38ea
commit dd67eafd0d
5 changed files with 118 additions and 10 deletions

View file

@ -10,7 +10,7 @@ class IntegerField(PhangoField):
Args:
name (str): The name of new field
size (int): The size of the new field in database. By default 11.
required (bool): Boolean for define if
required (bool): Boolean for define if field is required or not
"""
@ -124,24 +124,41 @@ class FloatField(PhangoField):
return 'FLOAT NOT NULL DEFAULT "0"'
class DecimalField(FloatField):
"""PhangoField field for Decimals fields."""
def get_type_sql(self):
return 'DECIMAL(20, 2) NOT NULL DEFAULT "0"'
class DoubleField(FloatField):
"""PhangoField field for Double fields."""
def get_type_sql(self):
return 'DOUBLE NOT NULL DEFAULT "0"'
class CharField(PhangoField):
"""Simple alias for PhangoField for clarify that """
pass
class TextField(PhangoField):
"""Class used for text fields
Class used for text fields, use TEXT sql type for the this field.
"""
def __init__(self, name, required=False):
"""Init TextField class different to standard PhangoField
Args:
name (str): The name of new field
required (bool): Boolean for define if field is required or not
Attributes:
set_default (str): Set if the value es NOT NULL or not
"""
super().__init__(name, 11, required)
self.set_default='NOT NULL'
@ -155,12 +172,30 @@ class TextField(PhangoField):
return 'TEXT '+self.set_default
class HTMLField(TextField):
"""Class used for html fields
Class used for html fields, use TEXT sql type for the this field because is children of TextField.
"""
def __init__(self, name, required=False):
"""Init HTMLField class different to standard PhangoField
Args:
name (str): The name of new field
required (bool): Boolean for define if field is required or not
Attributes:
trusted_tags (list): A list with safe tags.
"""
super().__init__(name, required)
self.trusted_tags=[]
def check(self, value):
"""Check method for html values
This check method use beautifulsoap for clean and format html code
"""
soup=BeautifulSoup(value, features='html.parser')
@ -172,8 +207,17 @@ class HTMLField(TextField):
class ForeignKeyField(IntegerField):
"""Subclass of IntegerField for create Foreign keys
A subclass of IntegerField used for create foreign keys in related tables.
"""
def __init__(self, name, related_table, size=11, required=False, identifier_field='id', named_field="id", select_fields=[]):
"""
Args:
name (str): Name of field
"""
super(ForeignKeyField, self).__init__(name, size, required)

View file

@ -3,11 +3,14 @@ import sys
from pathlib import Path
from paramecio2.libraries.db.corefields import CharField
from paramecio2.libraries.db.extraforms.fileform import FileForm
from paramecio.citoplasma import httputils
from paramecio.citoplasma.keyutils import create_key
#from paramecio.citoplasma import httputils
from paramecio2.libraries.keyutils import create_key
import traceback
from bottle import request
#from bottle import request
from flask import request
from werkzeug.utils import secure_filename
from uuid import uuid4
@ -42,15 +45,15 @@ class FileField(CharField):
pass
def check(self, value):
files_uploaded=request.files
files_uploaded=request.files
print(request.files.keys())
field_file=self.name+'_file'
#if not change
if not field_file in files_uploaded:
if value=='':
if self.model:
@ -90,10 +93,10 @@ class FileField(CharField):
# Load image file
file_bytecode=files_uploaded[field_file].file
#file_bytecode=files_uploaded[field_file].file
filename=secure_filename(files_uploaded[field_file].filename)
filename=files_uploaded[field_file].filename
realfilename, ext = os.path.splitext(filename)
prefix=''
@ -158,6 +161,9 @@ class FileField(CharField):
self.model.yes_reset_conditions=old_reset
# Save file
files_uploaded[field_file].save(save_file)
#self.model.conditions=old_conditions

View file

@ -6,6 +6,17 @@ login_name='login'
login_url='.login'
def db(f):
"""Wrapper function for add db connection to your flask function
Wrapper function for add db connection to your flask function. Also close the connection if error or function exection is finished.
Args:
*args : The args of function
**kwds : Standard python extra arguments of function
Returns:
wrapper (function): Return the wrapper.
"""
@wraps(f)
@ -30,6 +41,17 @@ def db(f):
return wrapper
def login_site(f):
"""Wrapper function for check login in your flask function
Wrapper function for check a login session in your flask function. If
Args:
*args : The args of function
**kwds : Standard python extra arguments of function
Returns:
wrapper (function): Return the wrapper.
"""
@wraps(f)

View file

@ -13,6 +13,8 @@ import ssl as ssl_module
import sys
class SendMail:
"""Class for send email
"""
port=587
@ -25,6 +27,20 @@ class SendMail:
#ssl=True
def __init__(self, ssl=True):
"""Class for send email
Class for send email using standard python library
Attributes:
port (int): The port used for send email, by default 587
host (str): The hostname of mail server used for send the email
username (str): The username for login in mail server
password (str): The password for login in mail server
smtp (smtplib.SMTP): The python SMTP object used for send emails
txt_error: (str): If error, is saved in this attribute
"""
self.smtp=None #smtplib.SMTP(host=self.host, port=self.port)
self.txt_error=''
@ -94,6 +110,18 @@ class SendMail:
return True
def send(self, from_address, to_address: list, subject, message, content_type='plain', attachments=[]):
""" Method that send email
With this method you can send email to multiple address, html, and add attachments to email
Args:
from_adress (str): The adress used for send the email
to_address (list): A list of emails where the email will be sended.
subject (str): The subject of the email
message (str): The content of the message
content_type (str): The type of mail content, can be plain or html.
attatchments (list): A list with a serie of file paths for attach to the email.
"""
if self.smtp==None:
if not self.connect():
@ -174,12 +202,14 @@ class SendMail:
return True
def quit(self):
"""Function used when you need quit connection for any reason"""
if self.smtp!=None:
self.smtp.quit()
self.smtp=None
def __del__(self):
"""Method for clean the connection when the object is closed"""
if self.smtp!=None:

View file

@ -1,5 +1,11 @@
from slugify import slugify as slugify_func
def slugify(slug, *args, **wargs):
"""Simple wrapper for slugify module https://github.com/un33k/python-slugify
Args:
slug (str): The string to be slugified
"""
return slugify_func(slug, *args, **wargs)