Skip to content

Commit

Permalink
Fix model structure, Makefile and clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
alfred82santa committed Dec 26, 2015
1 parent f0d9c0f commit 79d7676
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 43 deletions.
51 changes: 51 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

29 changes: 19 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
============
dirty-models
============

Dirty models for python 3

*************
Expand All @@ -54,6 +55,7 @@ http://dirty-models.readthedocs.org
********
Features
********

- Python 3 package.
- Easy to create a model.
- Non destructive modifications.
Expand All @@ -77,6 +79,13 @@ Features
Changelog
*********

Version 0.5.2
-------------

- Fix model structure.
- Makefile helpers.


Version 0.5.1
-------------

Expand All @@ -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
Expand Down Expand Up @@ -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


*****************
Expand Down
22 changes: 5 additions & 17 deletions dirty_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
28 changes: 14 additions & 14 deletions docs/dirty_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:



Expand Down
3 changes: 3 additions & 0 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx
python-dateutil
iso8601
Empty file added requirements.txt
Empty file.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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='[email protected]',
classifiers=[
'Intended Audience :: Developers',
Expand Down
2 changes: 1 addition & 1 deletion tests/dirty_models/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 79d7676

Please sign in to comment.