From d9c3f8e86c8496c741287a6132e385979611f5e5 Mon Sep 17 00:00:00 2001 From: Roland Haroutiounian Date: Wed, 24 Jun 2015 11:23:52 +0200 Subject: [PATCH] =?UTF-8?q?[#11]=20Modification=20de=20la=20m=C3=A9thode?= =?UTF-8?q?=20create=20=3D>=20passage=20en=20arguments=20positionnels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EditorialModel/fields.py | 28 ++++++++++++++++++---------- EditorialModel/test/test_field.py | 4 +++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/EditorialModel/fields.py b/EditorialModel/fields.py index f76f27e..6875bff 100644 --- a/EditorialModel/fields.py +++ b/EditorialModel/fields.py @@ -40,25 +40,33 @@ class EmField(EmComponent): # # @static # + # @param name str: Name of the field + # @param fieldgroup EmFieldGroup: Field group in which the field is + # @param fieldtype EmFieldType: Type of the field + # @param optional int: is the field optional ? (default=0) + # @param internal int: is the field internal ? (default=0) + # @param rel_to_type_id int: default=0 + # @param rel_field_id int: default=0 + # @param icon int: default=0 # @param kwargs dict: Dictionary of the values to insert in the field record # # @throw TypeError # @see EmComponent::__init__() # @staticmethod @classmethod - def create(c, **kwargs): + def create(c, name, fieldgroup, fieldtype, optional=0, internal=0, rel_to_type_id=0, rel_field_id=0, icon=0): try: - exists = EmField(kwargs['name']) + exists = EmField(name) except EmComponentNotExistError: values = { - 'name' : kwargs['name'], - 'fieldgroup_id' : kwargs['fieldgroup_id'], - 'fieldtype' : kwargs['fieldtype'].name, - 'optional' : 1 if 'optional' in kwargs else 0, - 'internal' : 1 if 'internal' in kwargs else 0, - 'rel_to_type_id': 0 if 'rel_to_type_id' not in kwargs else kwargs['rel_to_type_id'], - 'rel_field_id': 0 if 'rel_field_id' not in kwargs else kwargs['rel_field_id'], - 'icon': 0 if 'icon' not in kwargs else kwargs['icon'] + 'name' : name, + 'fieldgroup_id' : fieldgroup.uid, + 'fieldtype' : fieldtype.name, + 'optional' : optional, + 'internal' : internal, + 'rel_to_type_id': rel_to_type_id, + 'rel_field_id': rel_field_id, + 'icon': icon } createdField = super(EmField,c).create(**values) diff --git a/EditorialModel/test/test_field.py b/EditorialModel/test/test_field.py index 61587dc..2b86007 100644 --- a/EditorialModel/test/test_field.py +++ b/EditorialModel/test/test_field.py @@ -136,13 +136,15 @@ class TestField(FieldTestCase): # # tests the creation process of a field def testCreate(self): + ''' field_values = { 'name':'testfield1', 'fieldgroup_id' : self.testFieldgroup.uid, 'fieldtype' : self.testFieldType, 'rel_to_type_id': self.testType.uid } - field = EmField.create(**field_values) + ''' + field = EmField.create(name='testfield1', fieldgroup=self.testFieldgroup, fieldtype=self.testFieldType, rel_to_type_id=self.testType.uid) # We check that the field has been added in the em_field table field_records = self.get_field_records(field)