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

Commit

Permalink
updated documentation and added changelog for version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jstoiko committed Aug 16, 2015
1 parent c4307bd commit f07066b
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 121 deletions.
11 changes: 7 additions & 4 deletions docs/source/auth.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Authentication & Security
=========================

Authentication Mechanism
------------------------
In order to enable authentication, add the ``auth`` paramer to your .ini file:

Set ``auth = true`` in you .ini file to turn enable authentication. Nefertari currently uses the default Pyramid "auth ticket" cookie mechanism.
.. code-block:: ini
auth = true
Nefertari currently uses the default Pyramid "auth ticket" cookie mechanism.


Custom User Model
Expand All @@ -25,7 +28,7 @@ When authentication is enabled, Nefertari uses its own `User` model. This model
last_name = eng.StringField(max_length=50, default='')
Visible fields in views
Visible Fields in Views
-----------------------

You can control which fields to display to both authenticated users and unauthenticated users by defining `_auth_fields` and `_public_fields` respectively in your models.
Expand Down
17 changes: 15 additions & 2 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========

* :release:`0.5.0 <2015-08-x>`
* :feature:`-` Renamed field `self` to `_self`
* :feature:`-` Refactored authentication
* :feature:`-` Added the ability to apply processors on 'Relationship' fields and their backrefs
* :bug:`- major` Fixed sorting by 'id' when two ES-based models have two different 'id' field types
* :bug:`- major` Fixed bug with full-text search (`?q=`) when used in combination with field search (`&<field>=`)
* :bug:`- major` Fixed 40x error responses returning html, now all responses are json-formatted
* :bug:`- major` Fixed formatting error when using `_fields` query parameter
* :bug:`- major` Fixed duplicate records when querying ES aggregations by '_type'
* :bug:`- major` Fixed 400 error returned when querying resources with id in another format than the id field used in URL schema, e.g. ``/api/<collection>/<string_instead_of_integer>``, it now returns 404
* :bug:`- major` Fixed `_count` querying not respecting ``public_max_limit`` .ini setting
* :bug:`- major` Fixed error response when aggregating hidden fields with ``auth = true``, it now returns 403

* :release:`0.4.1 <2015-07-07>`
* :bug:`-` Fixed a bug when setting ``cors.allow_origins = *``
* :bug:`-` Fixed errors in http methods HEAD/OPTIONS response
Expand All @@ -14,7 +27,7 @@ Changelog
* :feature:`-` Added ability to empty listfields by setting them to "" or null

* :release:`0.3.4 <2015-06-09>`
* :bug:`-` Fixed bug whereby _count would throw exception when authentication was enabled
* :bug:`-` Fixed bug whereby `_count` would throw exception when authentication was enabled

* :release:`0.3.3 <2015-06-05>`
* :bug:`-` Fixed bug with posting multiple new relations at the same time
Expand All @@ -25,7 +38,7 @@ Changelog

* :release:`0.3.1 <2015-05-27>`
* :bug:`-` Fixed PUT to replace all fields and PATCH to update some
* :bug:`-` Fixed posting to singular resources e.d. /api/users/<username>/profile
* :bug:`-` Fixed posting to singular resources e.g. ``/api/users/<username>/profile``
* :bug:`-` Fixed ES mapping error when values of field were all null

* :release:`0.3.0 <2015-05-18>`
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# html_static_path = ['_static']

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down
82 changes: 0 additions & 82 deletions docs/source/database_backends.rst

This file was deleted.

11 changes: 10 additions & 1 deletion docs/source/getting_started.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Getting started
===============

Create your project in a virtualenv directory (see the `pyramid documentation <http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/project.html>`_ if you've never done that before)
Create your project in a virtualenv directory (see the `virtualenv documentation <https://virtualenv.pypa.io>`_)

.. code-block:: shell
Expand All @@ -12,6 +12,15 @@ Create your project in a virtualenv directory (see the `pyramid documentation <h
$ cd my_project
$ pserve local.ini
Requirements
------------

* Python 2.7, 3.3 or 3.4
* Elasticsearch for ElasticSearch-powered resources (see :any:`models <models>` and :any:`requests <making_requests>`)
* Postgres or Mongodb


Tutorials
---------

Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Table of Content

getting_started
views
database_backends
models
auth
making_requests
development_tools
Expand Down
22 changes: 13 additions & 9 deletions docs/source/making_requests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ Query parameters can be used on either GET, PATCH, PUT or DELETE requests.
=============================== ===========
url parameter description
=============================== ===========
``_m=<method>`` to tunnel any http method using GET, e.g. _m=POST [#]_
``_limit=<n>`` to limit the returned collection to <n> results (default: 20, max limit: 100 for unauthenticated users)
``_sort=<field_name>`` to sort collection by <field_name>
``_start=<n>`` to start collection from the <n>th resource
``_page=<n>`` to start collection at page <n> (n * _limit)
``_fields=<field_list>`` to display only specific fields, use ``-`` before field names to exclude those fields, e.g. ``_fields=-descripton``
``_m=<method>`` tunnel any http method using GET, e.g. _m=POST [#]_
``_limit=<n>`` limit the returned collection to <n> results
(default: 20, max limit: 100 for unauthenticated users)
``_sort=<field_name>`` sort collection by <field_name>
``_start=<n>`` start collection from the <n>th resource
``_page=<n>`` start collection at page <n> (n * _limit)
``_fields=<field_list>`` display only specific fields, use ``-`` before field
names to exclude those fields, e.g. ``_fields=-descripton``
=============================== ===========


Query syntax for ElasticSearch
------------------------------

Additional parameters are available when using an ElasticSearch-enabled collection (see **ESBaseDocument** in the `Wrapper API <database_backends.html#id1>`_ section of this documentation).
Additional parameters are available when using an ElasticSearch-enabled collection (see **ESBaseDocument** in the :any:`Wrapper API <wrapper-api>` section of this documentation).

======================================== ===========
url parameter description
Expand All @@ -31,9 +33,11 @@ url parameter description
``q=<keywords>`` to filter a collection using full-text search on all fields
``_search_fields=<field_list>`` use with ``?q=<keywords>`` to restrict search to specific fields
``_refresh_index=true`` to refresh the ES index after performing the operation [#]_
``_aggregations.<dot_notation_object>`` to use ES search aggregations, e.g. ``?_aggregations.my_agg.terms.field=tag`` [#]_
``_aggregations.<dot_notation_object>`` to use ES search aggregations,
e.g. ``?_aggregations.my_agg.terms.field=tag`` [#]_
======================================== ===========


Updating listfields
-------------------

Expand Down Expand Up @@ -88,7 +92,7 @@ Similarly, if delete_many() is defined, you will be able to delete entire collec
$ curl -XDELETE 'http://localhost:6543/api/<collection>?_missing_=<field_name>'
.. [#] To update listfields and dictfields, you can use the following syntax: ``_m=PATCH&<listfield>.<value>&<dictfield>.<key>=<value>``
.. [#] Set ``enable_get_tunneling = true`` in your .ini file to enable this feature. To update listfields and dictfields, you can use the following syntax: ``_m=PATCH&<listfield>.<value>&<dictfield>.<key>=<value>``
.. [#] The full syntax of ElasticSearch querying is beyond the scope of this documentation. You can read more on the `ElasticSearch Query String Query documentation <https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html>`_ to do things like fuzzy search: ``?name=fuzzy~`` or date range search: ``?date=[2015-01-01 TO *]``
.. [#] Set ``elasticsearch.enable_refresh_query = true`` in your .ini file to enable this feature. This parameter only works with POST, PATCH, PUT and DELETE methods. Read more on `ElasticSearch Bulk API documentation <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-refresh>`_.
.. [#] Set ``elasticsearch.enable_aggregations = true`` in your .ini file to enable this feature. You can also use the short name `_aggs`. Read more on `ElasticSearch Aggregations <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html>`_.
131 changes: 131 additions & 0 deletions docs/source/models.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
Configuring Models
==================

.. code-block:: python
from datetime import datetime
from nefertari import engine as eng
from nefertari.engine import BaseDocument
class Story(BaseDocument):
__tablename__ = 'stories'
_auth_fields = [
'id', 'updated_at', 'created_at', 'start_date',
'due_date', 'name', 'description']
_public_fields = ['id', 'start_date', 'due_date', 'name']
id = eng.IdField(primary_key=True)
updated_at = eng.DateTimeField(onupdate=datetime.utcnow)
created_at = eng.DateTimeField(default=datetime.utcnow)
start_date = eng.DateTimeField(default=datetime.utcnow)
due_date = eng.DateTimeField()
name = eng.StringField(required=True)
description = eng.TextField()
Database Backends
-----------------

Nefertari implements database engines on top of two different ORMs: `SQLAlchemy <http://www.sqlalchemy.org>`_ and `MongoEngine <http://mongoengine.org/>`_. These two engines wrap the underlying APIs of each ORM and provide a standardized syntax for using either one, making it easy to switch between them with minimal changes. Each Nefertari engine is maintained in its own repository:

* `nefertari-sqla github repository <https://github.com/brandicted/nefertari-sqla>`_
* `nefertari-mongodb github repository <https://github.com/brandicted/nefertari-mongodb>`_

Nefertari can either use `Elasticsearch <https://www.elastic.co/products/elasticsearch>`_ (*ESBaseDocument*) or the database engine itself (*BaseDocument*) for reads.

.. code-block:: python
from nefertari.engine import ESBaseDocument
class Story(ESBaseDocument):
(...)
or

.. code-block:: python
from nefertari.engine import BaseDocument
class Story(BaseDocument):
(...)
You can read more about *ESBaseDocument* and *BaseDocument* in the :any:`Wrapper API <wrapper-api>` section below.


.. _wrapper-api:

Wrapper API
-----------

Both database engines used by Nefertari implement a "Wrapper API" for developers who use Nefertari in their project. You can read more about either engine's in their respective documentation:

* `nefertari-sqla documentation <http://nefertari-sqla.readthedocs.org/>`_
* `nefertari-mongodb documentation <http://nefertari-mongodb.readthedocs.org/>`_

BaseMixin
Mixin with most of the API of *BaseDocument*. *BaseDocument* subclasses from this mixin.

BaseDocument
Base for regular models defined in your application. Just subclass it to define your model's fields. Relevant attributes:

* `__tablename__`: table name (only required by nefertari-sqla)
* `_auth_fields`: String names of fields meant to be displayed to authenticated users.
* `_public_fields`: String names of fields meant to be displayed to non-authenticated users.
* `_nested_relationships`: String names of relationship fields that should be included in JSON data of an object as full included documents. If relationship field is not present in this list, this field's value in JSON will be an object's ID or list of IDs.

ESBaseDocument
Subclass of *BaseDocument* instances of which are indexed on create/update/delete.

ESMetaclass
Document metaclass which is used in *ESBaseDocument* to enable automatic indexation to Elasticsearch of documents.

get_document_cls(name)
Helper function used to get the class of document by the name of the class.

JSONEncoder
JSON encoder that should be used to encode output of views.

ESJSONSerializer
JSON encoder used to encode documents prior indexing them in Elasticsearch.

relationship_fields
Tuple of classes that represent relationship fields in specific engine.

is_relationship_field(field, model_cls)
Helper function to determine whether *field* is a relationship field at *model_cls* class.

relationship_cls(field, model_cls)
Return class which is pointed to by relationship field *field* from model *model_cls*.


Field Types
-----------

This is the list of all the available field types:

* BigIntegerField
* BinaryField
* BooleanField
* ChoiceField
* DateField
* DateTimeField
* DecimalField
* DictField
* FloatField
* ForeignKeyField (ignored/not required when using mongodb)
* IdField
* IntegerField
* IntervalField
* ListField
* PickleField
* Relationship
* SmallIntegerField
* StringField
* TextField
* TimeField
* UnicodeField
* UnicodeTextField

0 comments on commit f07066b

Please sign in to comment.