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

Commit

Permalink
Merge pull request #42 from brandicted/develop
Browse files Browse the repository at this point in the history
release 0.2.2
  • Loading branch information
chartpath committed Jun 4, 2015
2 parents f2d4ef6 + 069c648 commit 5a0055e
Show file tree
Hide file tree
Showing 20 changed files with 373 additions and 173 deletions.
3 changes: 2 additions & 1 deletion MANIFEST.in
@@ -1,2 +1,3 @@
include README.md
include VERSION
include VERSION
recursive-include ramses/scaffolds *
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2.1
0.2.2
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
@@ -1,6 +1,10 @@
Changelog
=========

* :release:`0.2.2 <2015-06-03>`
* :bug:`-` Fixed password minimum length support by adding before and after validation processors
* :bug:`-` Fixed race condition in Elasticsearch indexing

* :release:`0.2.1 <2015-05-27>`
* :bug:`-` fixes limiting fields to be searched
* :bug:`-` fixes login issue
Expand Down
2 changes: 1 addition & 1 deletion docs/source/fields.rst
Expand Up @@ -94,7 +94,7 @@ You can then define each custom processor in a function in your ``__init__.py``
Relationship Fields
-------------------

For relationship fields, you can define the name of your 'relation' model by setting the ``document`` property under ``args``. You can also set the ``backref_name`` which will automatically add a field of that name to your schema. Note that for SQLA, you must add a ``foreign_key`` field to your 'relation' model.
For relationship fields, you can define the name of your 'relation' model by setting the ``document`` property under ``args``. You can also set the ``backref_name`` which will automatically add a field of that name to your schema. Note that for SQLA, you must add a ``foreign_keys`` arg to your 'relation' model if you want to use multiple foreign keys pointing to the same model (see nefertari-example).

.. code-block:: json
Expand Down
132 changes: 7 additions & 125 deletions docs/source/getting_started.rst
@@ -1,134 +1,16 @@
Getting started
===============

**1. Create a Pyramid "starter" 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)
1. 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)

.. code-block:: shell
$ mkvirtualenv MyProject
$ virtualenv my_project
$ source my_project/bin/activate
$ cd my_project
$ pip install ramses
$ pcreate -s starter MyProject
$ cd MyProject
$ pip install -e .
$ pcreate -s ramses_starter my_project
$ pserve local.ini
Install the database backend of your choice, e.g. sqla or mongodb
.. code-block:: shell
$ pip install nefertari-<engine>
**2. Add a few settings** to development.ini, inside the ``[app:main]`` section

.. code-block:: ini
# Elasticsearh settings
elasticsearch.hosts = localhost:9200
elasticsearch.sniff = false
elasticsearch.index_name = myproject
elasticsearch.index.disable = false
# path to your RAML file
ramses.raml_schema = api.raml
# disable authentication
ramses.auth = false
# Set '<nefertari_engine>' (e.g. nefertari_sqla or nefertari_mongodb)
nefertari.engine = <nefertari_engine>
.. code-block:: ini
# For sqla:
sqlalchemy.url = postgresql://localhost:5432/myproject
.. code-block:: ini
# For mongo:
mongodb.host = localhost
mongodb.port = 27017
mongodb.db = myproject
**3. Replace the file** `myproject/__init__.py`

.. code-block:: python
from pyramid.config import Configurator
def main(global_config, **settings):
config = Configurator(settings=settings)
config.include('ramses')
return config.make_wsgi_app()
**4. Create the file** `api.raml`

.. code-block:: yaml
#%RAML 0.8
---
title: Ramses
documentation:
- title: Example REST API
content: |
Welcome to the Ramses example API.
baseUri: http://{host}:{port}/{version}
version: v1
mediaType: application/json
protocols: [HTTP]
/myitems:
displayName: Collection of items
get:
description: Get all item
post:
description: Create a new item
body:
application/json:
schema: !include items.json
/{id}:
displayName: Collection-item
get:
description: Get a particular item
delete:
description: Delete a particular item
patch:
description: Update a particular item
**5. Create the file** `items.json`

.. code-block:: json
{
"type": "object",
"title": "Item schema",
"$schema": "http://json-schema.org/draft-03/schema",
"properties": {
"id": {
"required": true,
"type": "id_field",
"args": {
"primary_key": true
}
},
"name": {
"required": true,
"type": "string"
},
"description": {
"required": false,
"type": "text"
}
}
}
**6. Run your app**

.. code-block:: shell
$ pserve development.ini
2. Tada! Start editing api.raml to modify the API and items.json for the schema.
1 change: 0 additions & 1 deletion ramses/auth.py
Expand Up @@ -200,7 +200,6 @@ def create_admin_user(config):
groups=['admin']
))
if created:
user.clean(force_all=True)
transaction.commit()
except KeyError as e:
log.error('Failed to create system user. Missing config: %s' % e)
Expand Down
7 changes: 4 additions & 3 deletions ramses/models.py
Expand Up @@ -121,9 +121,10 @@ def generate_model_cls(schema, model_name, raml_resource, es_based=True):
}
field_kwargs.update(props.get('args', {}) or {})

processors = field_kwargs.get('processors', [])
field_kwargs['processors'] = [
registry.get(name) for name in processors]
for proc_key in ('before_validation', 'after_validation'):
processors = field_kwargs.get(proc_key, [])
field_kwargs[proc_key] = [
registry.get(name) for name in processors]

raml_type = (props.get('type', 'string') or 'string').lower()
if raml_type not in type_fields:
Expand Down
29 changes: 29 additions & 0 deletions ramses/scaffolds/__init__.py
@@ -0,0 +1,29 @@
from pyramid.scaffolds import PyramidTemplate
import binascii
import os
from os import urandom, chdir
import subprocess


class RamsesStarterTemplate(PyramidTemplate):
_template_dir = 'ramses_starter'
summary = 'Ramses starter'

def pre(self, command, output_dir, vars):
dbengine_choices = {'1':'sqla', '2':'mongodb'}
vars['engine'] = dbengine_choices[raw_input("""
Which DB backend would you like to use: 1)'sqla' or 2)'mongodb'?:
""")]
vars['random_string'] = binascii.hexlify(os.urandom(20))
if vars['package'] == 'site':
raise ValueError("""
"Site" is a reserved keyword in Python.
Please use a different project name. """)

def post(self, command, output_dir, vars):
os.chdir(str(output_dir))
subprocess.call('pip install -r requirements.txt', shell=True)
subprocess.call('pip install nefertari-{}'.format(vars['engine']), shell=True)
msg = """Goodbye boilerplate! Welcome to Ramses."""
self.out(msg)

7 changes: 7 additions & 0 deletions ramses/scaffolds/ramses_starter/+package+/__init__.py
@@ -0,0 +1,7 @@
from pyramid.config import Configurator


def main(global_config, **settings):
config = Configurator(settings=settings)
config.include('ramses')
return config.make_wsgi_app()
60 changes: 60 additions & 0 deletions ramses/scaffolds/ramses_starter/.gitignore_tmpl
@@ -0,0 +1,60 @@
venv
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

local.ini
mock/
8 changes: 8 additions & 0 deletions ramses/scaffolds/ramses_starter/README.md
@@ -0,0 +1,8 @@
## Installation
```
$ pip install -r requirements.txt
## Run
```
$ pserve local.ini
```
30 changes: 30 additions & 0 deletions ramses/scaffolds/ramses_starter/api.raml_tmpl
@@ -0,0 +1,30 @@
#%RAML 0.8
---
title: {{package}} API
documentation:
- title: {{package}} REST API
content: |
Welcome to the {{package}} API.
baseUri: http://{host}:{port}/{version}
version: v1
mediaType: application/json
protocols: [HTTP]

/items:
displayName: Collection of items
get:
description: Get all item
post:
description: Create a new item
body:
application/json:
schema: !include items.json

/{id}:
displayName: Collection-item
get:
description: Get a particular item
delete:
description: Delete a particular item
patch:
description: Update a particular item
22 changes: 22 additions & 0 deletions ramses/scaffolds/ramses_starter/items.json
@@ -0,0 +1,22 @@
{
"type": "object",
"title": "Item schema",
"$schema": "http://json-schema.org/draft-03/schema",
"properties": {
"id": {
"required": true,
"type": "id_field",
"args": {
"primary_key": true
}
},
"name": {
"required": true,
"type": "string"
},
"description": {
"required": false,
"type": "text"
}
}
}

0 comments on commit 5a0055e

Please sign in to comment.