mirror of
https://github.com/yweber/lodel2.git
synced 2025-10-21 16:49:02 +02:00
Code cleaning (PEP8 / Pylint) on fields.py
This commit is contained in:
parent
20c152c58b
commit
49f4f210b6
1 changed files with 11 additions and 14 deletions
|
@ -7,7 +7,8 @@ from EditorialModel.components import EmComponent
|
|||
from EditorialModel.exceptions import EmComponentCheckError
|
||||
import EditorialModel
|
||||
import EditorialModel.fieldtypes
|
||||
from django.db import models
|
||||
#from django.db import models
|
||||
|
||||
|
||||
## EmField (Class)
|
||||
#
|
||||
|
@ -22,9 +23,9 @@ class EmField(EmComponent):
|
|||
## Instanciate a new EmField
|
||||
# @todo define and test type for icon and fieldtype
|
||||
# @warning nullable == True by default
|
||||
def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable = True, default = None, uniq = False, **kwargs):
|
||||
def __init__(self, model, uid, name, fieldgroup_id, fieldtype, optional=False, internal=False, rel_field_id=None, icon='0', string=None, help_text=None, date_update=None, date_create=None, rank=None, nullable=True, default=None, uniq=False, **kwargs):
|
||||
|
||||
if self.ftype == None:
|
||||
if self.ftype is None:
|
||||
raise NotImplementedError("Trying to instanciate an EmField and not one of the fieldtypes child classes")
|
||||
|
||||
self.fieldgroup_id = fieldgroup_id
|
||||
|
@ -37,7 +38,6 @@ class EmField(EmComponent):
|
|||
self.check_type('rel_field_id', (int, type(None)))
|
||||
self.icon = icon
|
||||
|
||||
|
||||
#Field type elements
|
||||
self.fieldtype = fieldtype
|
||||
self.nullable = nullable
|
||||
|
@ -46,8 +46,7 @@ class EmField(EmComponent):
|
|||
|
||||
if len(kwargs) > 0:
|
||||
for kwargs_f in kwargs:
|
||||
warnings.warn("Argument '%s' not used and will be invalid for EmField __init__"%kwargs_f,SyntaxWarning)
|
||||
|
||||
warnings.warn("Argument '%s' not used and will be invalid for EmField __init__" % kwargs_f, SyntaxWarning)
|
||||
|
||||
super(EmField, self).__init__(model=model, uid=uid, name=name, string=string, help_text=help_text, date_update=date_update, date_create=date_create, rank=rank)
|
||||
|
||||
|
@ -60,35 +59,34 @@ class EmField(EmComponent):
|
|||
if ftype == 'integer':
|
||||
ftype_module = importlib.import_module('EditorialModel.fieldtypes.int')
|
||||
else:
|
||||
ftype_module = importlib.import_module('EditorialModel.fieldtypes.%s'%ftype)
|
||||
ftype_module = importlib.import_module('EditorialModel.fieldtypes.%s' % ftype)
|
||||
|
||||
return ftype_module.fclass
|
||||
|
||||
@staticmethod
|
||||
## @brief Return the list of allowed field type
|
||||
def fieldtypes_list():
|
||||
return [ f for f in EditorialModel.fieldtypes.__all__ if f != '__init__' ]
|
||||
return [f for f in EditorialModel.fieldtypes.__all__ if f != '__init__']
|
||||
|
||||
## @brief Abstract method that should return a validation function
|
||||
# @param raise_e Exception : if not valid raise this exception
|
||||
# @param ret_valid : if valid return this value
|
||||
# @param ret_invalid : if not valid return this value
|
||||
def validation_function(self, raise_e = None, ret_valid = None, ret_invalid = None):
|
||||
def validation_function(self, raise_e=None, ret_valid=None, ret_invalid=None):
|
||||
if self.__class__ == EmField:
|
||||
raise NotImplementedError("Abstract method")
|
||||
if raise_e is None and ret_valid is None:
|
||||
raise AttributeError("Behavior doesn't allows to return a valid validation function")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
## @brief Return the list of relation fields for a rel_to_type
|
||||
# @return None if the field is not a rel_to_type else return a list of EmField
|
||||
def rel_to_type_fields(self):
|
||||
if not self.rel_to_type_id:
|
||||
if not self.rel_to_type_id: # TODO Ajouter cette propriété
|
||||
return None
|
||||
|
||||
return [ f for f in self.model.components(EmField) if f.rel_field_id == self.uid ]
|
||||
|
||||
return [f for f in self.model.components(EmField) if f.rel_field_id == self.uid]
|
||||
|
||||
## Check if the EmField is valid
|
||||
# @return True if valid False if not
|
||||
|
@ -105,4 +103,3 @@ class EmField(EmComponent):
|
|||
# @todo Check if unconditionnal deletion is correct
|
||||
def delete_check(self):
|
||||
return True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue