diff --git a/paramecio/libraries/db/extrafields/arrayfield.py b/paramecio/libraries/db/extrafields/arrayfield.py
index 03a0645..ec22984 100644
--- a/paramecio/libraries/db/extrafields/arrayfield.py
+++ b/paramecio/libraries/db/extrafields/arrayfield.py
@@ -1,9 +1,35 @@
+"""
+Parameciofm is a series of wrappers for Flask, mako and others and construct a simple headless cms.
+
+Copyright (C) 2024 Antonio de la Rosa Caballero
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+"""
+
from paramecio.libraries.db.webmodel import PhangoField,WebModel
import json
class ArrayField(PhangoField):
+ """Field for save json arrays with determined values"""
def __init__(self, name, field_type, required=False):
+ """
+ Args:
+ name (str): The name of new field
+ field_type (PhangoField): The type of PhangoField for save in ArrayField
+ required (bool): Boolean for define if field is required or not
+ """
super().__init__(name, required)
@@ -11,7 +37,9 @@ class ArrayField(PhangoField):
self.error_default='Sorry, the json array is invalid'
- self.set_default='NOT NULL'
+ self.set_default=''
+
+ self.type_sql='text'
def check(self, value):
@@ -30,10 +58,17 @@ class ArrayField(PhangoField):
self.error=True
self.txt_error='Sorry, the json array is invalid'
+ error=0
+
if type(self.field_type).__name__!='ArrayField':
for k,v in enumerate(value):
value[k]=self.field_type.check(v)
+ if self.field_type.error:
+ error+=1
+
+ if error>0:
+ self.error=True
final_value=json.dumps(value)
@@ -43,7 +78,7 @@ class ArrayField(PhangoField):
def get_type_sql(self):
- return 'TEXT '+self.set_default
+ return 'JSON'
def show_formatted(self, value):
diff --git a/paramecio/libraries/db/extrafields/colorfield.py b/paramecio/libraries/db/extrafields/colorfield.py
index 2444ee3..7c81180 100644
--- a/paramecio/libraries/db/extrafields/colorfield.py
+++ b/paramecio/libraries/db/extrafields/colorfield.py
@@ -1,7 +1,31 @@
+"""
+Parameciofm is a series of wrappers for Bottle, mako and others and construct a simple headless cms.
+
+Copyright (C) 2024 Antonio de la Rosa Caballero
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+"""
+
from paramecio.libraries.db.corefields import IntegerField
-from paramecio.libraries.db.extraforms.colorform import ColorForm
+try:
+ from paramecio.libraries.db.extraforms.colorform import ColorForm
+except:
+ class ColorForm:
+ pass
class ColorField(IntegerField):
+ """Simple field for save colors in hexadecimal format."""
def __init__(self, name, size=11, required=False):
super().__init__(name, size, required)
diff --git a/paramecio/libraries/db/extrafields/datefield.py b/paramecio/libraries/db/extrafields/datefield.py
index 54a1500..ea7f24a 100644
--- a/paramecio/libraries/db/extrafields/datefield.py
+++ b/paramecio/libraries/db/extrafields/datefield.py
@@ -1,8 +1,33 @@
+"""
+Parameciofm is a series of wrappers for Bottle, mako and others and construct a simple headless cms.
+
+Copyright (C) 2024 Antonio de la Rosa Caballero
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+"""
+
from paramecio.libraries.db.corefields import PhangoField
from paramecio.libraries import datetime
-from paramecio.libraries.db.extraforms.dateform import DateForm
+try:
+ from paramecio.libraries.db.extraforms.dateform import DateForm
+except:
+
+ class DateForm:
+ pass
class DateField(PhangoField):
+ """Field for use and save dates in YYYYMMDDHHSS format"""
def __init__(self, name, size=255, required=False):
diff --git a/paramecio/libraries/db/extrafields/datetimefield.py b/paramecio/libraries/db/extrafields/datetimefield.py
index 735e401..6be3071 100644
--- a/paramecio/libraries/db/extrafields/datetimefield.py
+++ b/paramecio/libraries/db/extrafields/datetimefield.py
@@ -1,8 +1,32 @@
+"""
+Parameciofm is a series of wrappers for Bottle, mako and others and construct a simple headless cms.
+
+Copyright (C) 2024 Antonio de la Rosa Caballero
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+"""
+
from paramecio.libraries.db.corefields import PhangoField
from paramecio.libraries import datetime
-from paramecio.libraries.db.extraforms.dateform import DateForm
+try:
+ from paramecio.libraries.db.extraforms.dateform import DateForm
+except:
+ class DateForm:
+ pass
class DateTimeField(PhangoField):
+ """Field for use and save dates in MySQL date format"""
def __init__(self, name, size=255, required=False):
@@ -13,6 +37,8 @@ class DateTimeField(PhangoField):
self.utc=False
self.error_default='Error: Date format invalid'
+
+ self.type_sql='datetime'
def check(self, value):
@@ -21,16 +47,17 @@ class DateTimeField(PhangoField):
value=datetime.local_to_gmt(value)
elif not datetime.obtain_timestamp(value):
-
+
self.error=True
self.txt_error=self.error_default
- return None
+
+ return '0000-00-00 00:00:00'
if value==False:
self.error=True
self.txt_error=self.error_default
- return None
+ return '0000-00-00 00:00:00'
else:
"""
@@ -46,14 +73,10 @@ class DateTimeField(PhangoField):
def show_formatted(self, value):
# Convert to paramecio value
- if value!=None:
- value=str(value)
- value=value.replace('-', '').replace(':', '').replace(' ', '')
-
- return datetime.format_date(value)
-
- else:
- return ''
+ value=str(value)
+ value=value.replace('-', '').replace(':', '').replace(' ', '')
+
+ return datetime.format_date(value)
def get_type_sql(self):
@@ -61,4 +84,4 @@ class DateTimeField(PhangoField):
"""
- return 'DATETIME NULL'
+ return 'DATETIME NOT NULL'
diff --git a/paramecio/libraries/db/extrafields/dictfield.py b/paramecio/libraries/db/extrafields/dictfield.py
index c3328e2..7c0b399 100644
--- a/paramecio/libraries/db/extrafields/dictfield.py
+++ b/paramecio/libraries/db/extrafields/dictfield.py
@@ -1,13 +1,35 @@
-from paramecio.libraries.db.webmodel import WebModel, PhangoField
+"""
+Parameciofm is a series of wrappers for Bottle, mako and others and construct a simple headless cms.
-try:
- import ujson as json
-except:
- import json
+Copyright (C) 2024 Antonio de la Rosa Caballero
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+"""
+
+from paramecio.libraries.db.webmodel import WebModel, PhangoField
+import json
class DictField(PhangoField):
+ """Field for save json dicts with determined values"""
def __init__(self, name, field_type, required=False):
+ """
+ Args:
+ name (str): The name of field
+ field_type (PhangoField): The type of PhangoField for save in ArrayField
+ required (bool): Boolean for define if field is required or not
+ """
super().__init__(name, required)
@@ -16,6 +38,8 @@ class DictField(PhangoField):
self.error_default='Sorry, the json dict is invalid'
self.set_default='NOT NULL'
+
+ self.type_sql='longtext'
def check(self, value):
@@ -33,20 +57,25 @@ class DictField(PhangoField):
value={}
self.error=True
self.txt_error=self.error_default
-
+ error=0
for k,v in value.items():
value[k]=self.field_type.check(v)
+ if self.field_type.error:
+ error+=1
final_value=json.dumps(value)
+ if error>0:
+ self.error=True
+
#final_value=WebModel.escape_sql(final_value)
return final_value
def get_type_sql(self):
- return 'TEXT '+self.set_default
+ return 'JSON '+self.set_default
def show_formatted(self, value):
diff --git a/paramecio/libraries/db/extrafields/emailfield.py b/paramecio/libraries/db/extrafields/emailfield.py
index 8fc2bc7..e4368fa 100644
--- a/paramecio/libraries/db/extrafields/emailfield.py
+++ b/paramecio/libraries/db/extrafields/emailfield.py
@@ -1,9 +1,29 @@
+"""
+Parameciofm is a series of wrappers for bottle, mako and others and construct a simple headless cms.
+
+Copyright (C) 2024 Antonio de la Rosa Caballero
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see .
+"""
+
from paramecio.libraries.db.corefields import CharField
import re
mail_pattern=re.compile(r"\w[\w\.-]*@\w[\w\.-]+\.\w+")
class EmailField(CharField):
+ """Field for save and check email addreses"""
def __init__(self, name, size=1024, required=False):
diff --git a/paramecio/libraries/mtemplates.py b/paramecio/libraries/mtemplates.py
index 215e5c8..84f8882 100644
--- a/paramecio/libraries/mtemplates.py
+++ b/paramecio/libraries/mtemplates.py
@@ -91,7 +91,7 @@ class PTemplate:
templates_loaded={}
- def __init__(self, environment):
+ def __init__(self, environment, app=None):
"""A class used how shortcuts for Mako template functions.