diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..963053a --- /dev/null +++ b/Makefile @@ -0,0 +1,51 @@ + + +help: + @echo "Options" + @echo "---------------------------------------------------------------" + @echo "help: This help" + @echo "requirements: Download requeroments" + @echo "requirements-test: Download requirements for tests" + @echo "requirements-docs: Download requirements for docs" + @echo "run-tests: Run tests with coverage" + @echo "publish: Publish new version on Pypi" + @echo "clean: Clean compiled files" + @echo "flake: Run Flake8" + @echo "prepush: Helper to run before to push to repo" + @echo "---------------------------------------------------------------" + +requirements: + @echo "Installing dirty-models requirements..." + pip install -r requirements.txt + +requirements-test: + @echo "Installing dirty-models tests requirements..." + @make requirements + pip install -r requirements-test.txt + +requirements-docs: + @echo "Installing dirty-models docs requirements..." + @make requirements + pip install -r requirements-docs.txt + +run-tests: + @echo "Running tests..." + nosetests --with-coverage -d --cover-package=dirty_models + +publish: + @echo "Publishing new version on Pypi..." + python setup.py sdist upload + +clean: + @echo "Cleaning compiled files..." + find . | grep -E "(__pycache__|\.pyc|\.pyo)$ " | xargs rm -rf + +flake: + @echo "Running flake8 tests..." + flake8 dirty_models + flake8 tests + +prepush: + @make flake + @make run-tests + diff --git a/README.rst b/README.rst index 8ee2f04..0129ba9 100644 --- a/README.rst +++ b/README.rst @@ -43,6 +43,7 @@ ============ dirty-models ============ + Dirty models for python 3 ************* @@ -54,6 +55,7 @@ http://dirty-models.readthedocs.org ******** Features ******** + - Python 3 package. - Easy to create a model. - Non destructive modifications. @@ -77,6 +79,13 @@ Features Changelog ********* +Version 0.5.2 +------------- + +- Fix model structure. +- Makefile helpers. + + Version 0.5.1 ------------- @@ -88,14 +97,14 @@ Version 0.5.0 - Added autolist parameter to ArrayField. It allows to assign a single item to a list field, so it will be converted to a list with this value. - .. code-block:: python +.. code-block:: python - class ExampleModel(BaseModel): - array_field = ArrayField(field_type=StringField(), autolist=True) + class ExampleModel(BaseModel): + array_field = ArrayField(field_type=StringField(), autolist=True) - model = ExampleModel() - model.array_field = 'foo' - assert model.array_field[0] is 'foo' + model = ExampleModel() + model.array_field = 'foo' + assert model.array_field[0] is 'foo' ************ Installation @@ -141,11 +150,11 @@ Basic usage assert fb.alias_field is 3 assert fb.alias1 is fb.alias_field assert fb.alias2 is fb.alias_field - -Note: ------ -Look at tests for more examples + +.. note:: + + Look at tests for more examples ***************** diff --git a/dirty_models/models.py b/dirty_models/models.py index 7d89514..9f7ef03 100644 --- a/dirty_models/models.py +++ b/dirty_models/models.py @@ -464,12 +464,13 @@ def reset_attr_by_path(self, field): else: self.reset_field_value(field) - def get_structure(self): + @classmethod + def get_structure(cls): """ Returns a dictionary with model field objects. :return: dict """ - return self._structure.copy() + return cls._structure.copy() class BaseDynamicModel(BaseModel): @@ -484,19 +485,6 @@ def __getattr__(self, name): except AttributeError: return self.get_field_value(name) - def __reduce__(self): - """ - Reduce function to allow dumpable by pickle - """ - return recover_model_from_data, (self.__class__, self.export_original_data(), - self.export_modified_data(), self.export_deleted_fields(),) - - def copy(self): - """ - Creates a copy of model - """ - return self.__class__(data=self.export_data()) - def _get_field_type(self, key, value): """ Helper to create field object based on value type @@ -708,13 +696,13 @@ def get_validated_object(self, field_type, value): else: return None - def get_structure(self): + def get_current_structure(self): """ Returns a dictionary with model field objects. :return: dict """ - struct = super(FastDynamicModel, self).get_structure() + struct = self.__class__.get_structure() struct.update(self._field_types) return struct diff --git a/docs/dirty_models.rst b/docs/dirty_models.rst index e67e9b7..6748796 100644 --- a/docs/dirty_models.rst +++ b/docs/dirty_models.rst @@ -4,32 +4,32 @@ Dirty Models package Main submodules to be used from Dirty Models. Models module --------------------------- +------------- .. automodule:: dirty_models.models - :members: - :show-inheritance: - +:members: + :show-inheritance: + Fields module --------------------------- +------------- .. automodule:: dirty_models.fields - :members: - :show-inheritance: - +:members: + :show-inheritance: + Base module ------------------------- +----------- .. automodule:: dirty_models.base - :members: - :show-inheritance: +:members: + :show-inheritance: Inner model types module -------------------------------- +------------------------ .. automodule:: dirty_models.model_types - :members: - :show-inheritance: +:members: + :show-inheritance: diff --git a/requirements-docs.txt b/requirements-docs.txt new file mode 100644 index 0000000..c72c2a9 --- /dev/null +++ b/requirements-docs.txt @@ -0,0 +1,3 @@ +sphinx +python-dateutil +iso8601 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index 17b097d..92fd99c 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ name='dirty-models', url='https://github.com/alfred82santa/dirty-models', author='alfred82santa', - version='0.5.1', + version='0.5.2', author_email='alfred82santa@gmail.com', classifiers=[ 'Intended Audience :: Developers', diff --git a/tests/dirty_models/tests_models.py b/tests/dirty_models/tests_models.py index 64f8281..f7e2075 100644 --- a/tests/dirty_models/tests_models.py +++ b/tests/dirty_models/tests_models.py @@ -1118,7 +1118,7 @@ def test_get_structure(self): self.model.testField1 = 'aaaa' self.model.testField2 = 1 - s = self.model.get_structure() + s = self.model.get_current_structure() self.assertIn('testField1', s) self.assertIsInstance(s['testField1'], StringField)