Fixed silly bugs in slugifyfield and added new fields
This commit is contained in:
parent
4db3c91924
commit
44e3fe474f
4 changed files with 36 additions and 5 deletions
|
|
@ -54,7 +54,7 @@ def slugify(str_in, respect_upper=False, replace_space='-', replace_dot=False, r
|
||||||
str_out=str_out.replace(" ", replace_space)
|
str_out=str_out.replace(" ", replace_space)
|
||||||
|
|
||||||
if respect_upper==False:
|
if respect_upper==False:
|
||||||
pass
|
str_out=str_out.lower()
|
||||||
|
|
||||||
return str_out
|
return str_out
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,12 @@ class FloatField(PhangoField):
|
||||||
|
|
||||||
return 'FLOAT NOT NULL DEFAULT "0"'
|
return 'FLOAT NOT NULL DEFAULT "0"'
|
||||||
|
|
||||||
|
class DoubleField(FloatField):
|
||||||
|
|
||||||
|
def get_type_sql(self):
|
||||||
|
|
||||||
|
return 'DOUBLE NOT NULL DEFAULT "0"'
|
||||||
|
|
||||||
class CharField(PhangoField):
|
class CharField(PhangoField):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,36 @@
|
||||||
|
|
||||||
from paramecio.cromosoma.corefields import CharField
|
from paramecio.cromosoma.corefields import CharField
|
||||||
from paramecio.citoplasma.slugify import slugify
|
from paramecio.citoplasma.slugify import slugify
|
||||||
|
from paramecio.cromosoma.coreforms import HiddenForm
|
||||||
|
|
||||||
class SlugifyField(CharField):
|
class SlugifyField(CharField):
|
||||||
|
|
||||||
def check(value):
|
def __init__(self, name, size=255, field_related=None, required=False):
|
||||||
|
|
||||||
|
super(SlugifyField, self).__init__(name, size, required)
|
||||||
|
|
||||||
|
self.name_form=HiddenForm
|
||||||
|
|
||||||
|
self.field_related=field_related
|
||||||
|
|
||||||
|
def check(self, value):
|
||||||
|
|
||||||
value=slugify(value)
|
value=slugify(value)
|
||||||
|
|
||||||
if value=='':
|
if value=='':
|
||||||
|
|
||||||
self.error=True
|
if self.model!=None and self.field_related!=None:
|
||||||
|
|
||||||
return ''
|
self.model.post[self.field_related]=self.model.post.get(self.field_related, '')
|
||||||
|
|
||||||
|
value=slugify(self.model.post[self.field_related])
|
||||||
|
|
||||||
|
if value=='':
|
||||||
|
|
||||||
|
self.error=True
|
||||||
|
self.error_txt='Value is empty'
|
||||||
|
|
||||||
|
return ''
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,10 @@ class WebModel:
|
||||||
|
|
||||||
self.distinct=''
|
self.distinct=''
|
||||||
|
|
||||||
|
# A simple dictionary where post values are saved for use of fields classes
|
||||||
|
|
||||||
|
self.post={}
|
||||||
|
|
||||||
# A method where create the new fields of this model
|
# A method where create the new fields of this model
|
||||||
|
|
||||||
def create_fields(self):
|
def create_fields(self):
|
||||||
|
|
@ -149,6 +153,8 @@ class WebModel:
|
||||||
|
|
||||||
# Connect to db
|
# Connect to db
|
||||||
|
|
||||||
|
self.post=dict_values
|
||||||
|
|
||||||
self.connect_to_db()
|
self.connect_to_db()
|
||||||
|
|
||||||
self.query_error=''
|
self.query_error=''
|
||||||
|
|
@ -181,6 +187,8 @@ class WebModel:
|
||||||
|
|
||||||
def update(self, dict_values, external_agent=True):
|
def update(self, dict_values, external_agent=True):
|
||||||
|
|
||||||
|
self.post=dict_values
|
||||||
|
|
||||||
# Connect to db
|
# Connect to db
|
||||||
|
|
||||||
self.fields[self.name_field_id].required=False
|
self.fields[self.name_field_id].required=False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue