From 7995bf7887ea8378a6e13f48f63b50d9e728f367 Mon Sep 17 00:00:00 2001 From: Yann Date: Wed, 24 Feb 2016 17:13:31 +0100 Subject: [PATCH] Small changes & bugfixes in graphviz backend & some fieldtypes --- EditorialModel/backend/graphviz.py | 7 ++++--- EditorialModel/fieldtypes/bool.py | 4 ++-- EditorialModel/fieldtypes/char.py | 2 +- EditorialModel/fieldtypes/dictionary.py | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 EditorialModel/fieldtypes/dictionary.py diff --git a/EditorialModel/backend/graphviz.py b/EditorialModel/backend/graphviz.py index e34078b..83e96dd 100644 --- a/EditorialModel/backend/graphviz.py +++ b/EditorialModel/backend/graphviz.py @@ -91,9 +91,9 @@ class EmBackendGraphviz(EmBackendDummy): for f in [ f for f in c.fields() if f.name not in c.em_class.default_fields_list().keys()]: if f.rel_field_id is None: if f.fieldtype == 'rel2type': - rel_node_id = '%s%s'%(EmBackendGraphviz._component_id(c), EmBackendGraphviz._component_id(em.component(f.rel_to_type_id))) + rel_node_id = '%s%s%s'%(EmBackendGraphviz._component_id(c), EmBackendGraphviz._component_id(em.component(f.rel_to_type_id)), f.uid) - rel_node = '\t%s [ label="rel_to_type'%rel_node_id + rel_node = '\t%s [ label="rel2type %s'% (rel_node_id, f.name) if len(f.rel_to_type_fields()) > 0: #rel_node += '| {' @@ -104,7 +104,8 @@ class EmBackendGraphviz(EmBackendDummy): rel_node += '{ ' first = False rel_node += rf.name - rel_node += '}" shape="record"]\n' + rel_node += '}' if len(f.rel_to_type_fields()) > 0 else '' + rel_node += '" shape="record"]\n' rel_field += rel_node diff --git a/EditorialModel/fieldtypes/bool.py b/EditorialModel/fieldtypes/bool.py index d24d59e..5b6a793 100644 --- a/EditorialModel/fieldtypes/bool.py +++ b/EditorialModel/fieldtypes/bool.py @@ -1,9 +1,9 @@ #-*- coding: utf-8 -*- -from .generic import GenericFieldType +from .generic import SingleValueFieldType -class EmFieldType(GenericFieldType): +class EmFieldType(SingleValueFieldType): help = 'A basic boolean field' diff --git a/EditorialModel/fieldtypes/char.py b/EditorialModel/fieldtypes/char.py index 31ecaec..b6f06da 100644 --- a/EditorialModel/fieldtypes/char.py +++ b/EditorialModel/fieldtypes/char.py @@ -10,6 +10,6 @@ class EmFieldType(SingleValueFieldType): ## @brief A char field # @brief max_length int : The maximum length of this field def __init__(self, max_length=64, **kwargs): - self.max_length = max_length + self.max_length = int(max_length) super().__init__(**kwargs) diff --git a/EditorialModel/fieldtypes/dictionary.py b/EditorialModel/fieldtypes/dictionary.py new file mode 100644 index 0000000..5d61bd5 --- /dev/null +++ b/EditorialModel/fieldtypes/dictionary.py @@ -0,0 +1,15 @@ +#-*- coding: utf-8 -*- + +from .generic import MultiValueFieldType +from . import char + + +class EmFieldType(MultiValueFieldType): + + help = 'Fieldtype designed to handle translations' + + def __init__(self, value_max_length = 64, **args): + args['keyname'] = 'key' + args['key_fieldtype'] = char.EmFieldType(max_length = 4) + args['value_fieldtype'] = char.EmFieldType(value_max_length) + super().__init__(**args)