diff --git a/VERSION b/VERSION index 9325c3c..a2268e2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 \ No newline at end of file +0.3.1 \ No newline at end of file diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst index 92b69fc..d207108 100644 --- a/docs/source/changelog.rst +++ b/docs/source/changelog.rst @@ -1,7 +1,7 @@ Changelog ========= -* :release:`0.3.1 <2015-07-06>` +* :release:`0.3.1 <2015-07-07>` * :support:`- backported` Added support for callables in 'default' field argument * :support:`- backported` Added support for 'onupdate' field argument diff --git a/docs/source/fields.rst b/docs/source/fields.rst index 9c5d936..9348b36 100644 --- a/docs/source/fields.rst +++ b/docs/source/fields.rst @@ -75,7 +75,7 @@ You can set a minimum and/or maximum length of your field by setting the ``min_l Field Processors ---------------- -You can define field processors by referencing their names in the ``before_validation`` and ``after_validation`` properties under ``args``. `before_` and `after_` prefixes refer when those processors are executed, either before or after database validation. +You can define field processors by referencing their names in the ``before_validation`` and ``after_validation`` properties under ``args``. The `before_` and `after_` prefixes refer to when those processors are executed, either before or after database validation. You can define more than one processor in each of those arguments in a comma-separated list. .. code-block:: json @@ -87,7 +87,7 @@ You can define field processors by referencing their names in the ``before_valid } } -You can read more about field processors :doc:`here `. +You can read more about writing custom field processors :doc:`here `. Relationship Fields diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index abb4746..e0720a9 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -17,5 +17,6 @@ Getting started Tutorials --------- -- Check out the great tutorial written by Chris Hart on Real Python: `Create a REST API in Minutes With Pyramid and Ramses `_. - For a more complete example of a Pyramid project using Ramses, you can take a look at the `Example Project `_. +- Check out the great tutorial written by Chris Hart on Real Python: `Create a REST API in Minutes With Pyramid and Ramses `_. +- RAML can be used to generate an end-to-end application, check out `this example `_ using Ramses on the backend and RAML-javascript-client + BackboneJS on the front-end. diff --git a/docs/source/processors.rst b/docs/source/processors.rst index e9412d3..165bf7e 100644 --- a/docs/source/processors.rst +++ b/docs/source/processors.rst @@ -4,16 +4,59 @@ Field Processors Writing Processors ------------------ -You can then define each custom processor in a function in your ``__init__.py`` file. A processor receives two arguments: `instance`, the object's instance, and `new_value`, the new value being set. +You can write custom functions inside your ``__init__.py`` file, then simply add the ``@registry.add`` decorator before the functions that you'd like to turn into processors. A processor receives two arguments: `instance`, the object instance being created or updated, and `new_value`, the new value being set. .. code-block:: python @registry.add - def custom_processor(instance, new_value): + def processor(instance, new_value): """ This is a field processor """ - return (new_value or '').lower().strip() + return new_value -Accessing Other Models ----------------------- +Things You Can Do +----------------- + +You can update another field's value. + +.. code-block:: python + + @registry.add + def processor(instance, new_value): + """ Update other_field """ + instance.other_field = "other_value" + + return new_value + + +You can transform the value of a field, for example crypt a password before saving it. + +.. code-block:: python + + @registry.add + def processor(instance, new_value): + """ Crypt new_value if it's not crypted yet """ + import cryptacular.bcrypt + crypt = cryptacular.bcrypt.BCRYPTPasswordManager() + + if new_value and not crypt.match(new_value): + new_value = str(crypt.encode(new_value)) + + return new_value + + +You can update other collections or other filtered collections whenever the field is being updated to a certain value. + +.. code-block:: python + + @registry.add + def processor(instance, new_value): + """ Update 5 latest OtherModel that have foo=bar """ + from nefertari import engine + + _other_model = engine.get_document_cls("OtherModel") + objects = _other_model.get_collection(foo=bar, _sort="created_at", _limit=5) + _other_model._update_many(objects, {"bar": "foo"}) + + return new_value diff --git a/setup.py b/setup.py index 144776a..8d5742d 100644 --- a/setup.py +++ b/setup.py @@ -10,9 +10,9 @@ 'cryptacular', 'pyraml-parser', 'inflection', - 'nefertari>=0.4.0', 'transaction', 'six', + 'nefertari>=0.4.1', ] setup(name='ramses',