Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
preparing release 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoiko committed Jul 8, 2015
1 parent 818c642 commit 824cc91
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.3.0
0.3.1
2 changes: 1 addition & 1 deletion 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

Expand Down
4 changes: 2 additions & 2 deletions docs/source/fields.rst
Expand Up @@ -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
Expand All @@ -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 <processors>`.
You can read more about writing custom field processors :doc:`here <processors>`.


Relationship Fields
Expand Down
3 changes: 2 additions & 1 deletion docs/source/getting_started.rst
Expand Up @@ -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 <https://realpython.com/blog/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 <https://github.com/brandicted/ramses-example>`_.
- Check out the great tutorial written by Chris Hart on Real Python: `Create a REST API in Minutes With Pyramid and Ramses <https://realpython.com/blog/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 <https://github.com/jstoiko/raml-javascript-client>`_ using Ramses on the backend and RAML-javascript-client + BackboneJS on the front-end.
53 changes: 48 additions & 5 deletions docs/source/processors.rst
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -10,9 +10,9 @@
'cryptacular',
'pyraml-parser',
'inflection',
'nefertari>=0.4.0',
'transaction',
'six',
'nefertari>=0.4.1',
]

setup(name='ramses',
Expand Down

0 comments on commit 824cc91

Please sign in to comment.