Many fixes and docstrings
This commit is contained in:
parent
eb93be38ea
commit
dd67eafd0d
5 changed files with 118 additions and 10 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue