Initial test with Eve
This commit is contained in:
@@ -1,37 +1,51 @@
|
|||||||
import config
|
from eve import Eve
|
||||||
from flask import Flask, Blueprint
|
|
||||||
from flask.ext.mail import Mail
|
# import config
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
# from flask import Flask, Blueprint
|
||||||
from flask.ext.thumbnails import Thumbnail
|
# from flask.ext.mail import Mail
|
||||||
from flask.ext.assets import Environment, Bundle
|
# from flask.ext.sqlalchemy import SQLAlchemy
|
||||||
|
# from flask.ext.thumbnails import Thumbnail
|
||||||
|
# from flask.ext.assets import Environment, Bundle
|
||||||
|
|
||||||
# Initialize the Flask all object
|
# Initialize the Flask all object
|
||||||
app = Flask(__name__,
|
|
||||||
template_folder='templates',
|
from eve.io.mongo import Validator
|
||||||
static_folder='static')
|
|
||||||
|
class ValidateCustomFields(Validator):
|
||||||
|
def _validate_validcf(self, validcf, field, value):
|
||||||
|
if validcf:
|
||||||
|
print self.document['node_type']
|
||||||
|
if value == 'hi':
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self._error(field, "Must be hi")
|
||||||
|
|
||||||
|
|
||||||
|
app = Eve(validator=ValidateCustomFields)
|
||||||
|
|
||||||
|
|
||||||
# Filemanager used by Flask-Admin extension
|
# Filemanager used by Flask-Admin extension
|
||||||
filemanager = Blueprint('filemanager', __name__, static_folder='static/files')
|
# filemanager = Blueprint('filemanager', __name__, static_folder='static/files')
|
||||||
|
|
||||||
# Choose the configuration to load
|
# # Choose the configuration to load
|
||||||
app.config.from_object(config.Development)
|
# app.config.from_object(config.Development)
|
||||||
|
|
||||||
# Initialized the available extensions
|
# # Initialized the available extensions
|
||||||
mail = Mail(app)
|
# mail = Mail(app)
|
||||||
db = SQLAlchemy(app)
|
# db = SQLAlchemy(app)
|
||||||
thumb = Thumbnail(app)
|
# thumb = Thumbnail(app)
|
||||||
assets = Environment(app)
|
# assets = Environment(app)
|
||||||
|
|
||||||
# Import controllers
|
# # Import controllers
|
||||||
from application.modules.nodes import node_types
|
# from application.modules.nodes import node_types
|
||||||
from application.modules.nodes import nodes
|
# from application.modules.nodes import nodes
|
||||||
from application.modules.main import homepage
|
# from application.modules.main import homepage
|
||||||
from application.modules.shots import shots
|
# from application.modules.shots import shots
|
||||||
from application.modules.projects import projects
|
# from application.modules.projects import projects
|
||||||
|
|
||||||
# Register blueprints for the imported controllers
|
# # Register blueprints for the imported controllers
|
||||||
app.register_blueprint(filemanager)
|
# app.register_blueprint(filemanager)
|
||||||
app.register_blueprint(shots, url_prefix='/shots')
|
# app.register_blueprint(shots, url_prefix='/shots')
|
||||||
app.register_blueprint(projects, url_prefix='/projects')
|
# app.register_blueprint(projects, url_prefix='/projects')
|
||||||
app.register_blueprint(node_types, url_prefix='/node-types')
|
# app.register_blueprint(node_types, url_prefix='/node-types')
|
||||||
app.register_blueprint(nodes, url_prefix='/nodes')
|
# app.register_blueprint(nodes, url_prefix='/nodes')
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
from application import app
|
from application import app
|
||||||
from application import db
|
#from application import db
|
||||||
from flask.ext.script import Manager
|
from flask.ext.script import Manager
|
||||||
# from flask.ext.migrate import Migrate
|
# from flask.ext.migrate import Migrate
|
||||||
# from flask.ext.migrate import MigrateCommand
|
# from flask.ext.migrate import MigrateCommand
|
||||||
@@ -10,6 +10,7 @@ manager = Manager(app)
|
|||||||
|
|
||||||
@manager.command
|
@manager.command
|
||||||
def create_all_tables():
|
def create_all_tables():
|
||||||
db.create_all()
|
pass
|
||||||
|
#db.create_all()
|
||||||
|
|
||||||
manager.run()
|
manager.run()
|
||||||
|
111
attract/settings.py
Normal file
111
attract/settings.py
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
# Enable reads (GET), inserts (POST) and DELETE for resources/collections
|
||||||
|
# (if you omit this line, the API will default to ['GET'] and provide
|
||||||
|
# read-only access to the endpoint).
|
||||||
|
RESOURCE_METHODS = ['GET', 'POST', 'DELETE']
|
||||||
|
|
||||||
|
# Enable reads (GET), edits (PATCH), replacements (PUT) and deletes of
|
||||||
|
# individual items (defaults to read-only item access).
|
||||||
|
ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE']
|
||||||
|
|
||||||
|
|
||||||
|
schema = {
|
||||||
|
# Schema definition, based on Cerberus grammar. Check the Cerberus project
|
||||||
|
# (https://github.com/nicolaiarocci/cerberus) for details.
|
||||||
|
'firstname': {
|
||||||
|
'type': 'string',
|
||||||
|
'minlength': 1,
|
||||||
|
'maxlength': 10,
|
||||||
|
},
|
||||||
|
'lastname': {
|
||||||
|
'type': 'string',
|
||||||
|
'minlength': 1,
|
||||||
|
'maxlength': 15,
|
||||||
|
'required': True,
|
||||||
|
# talk about hard constraints! For the purpose of the demo
|
||||||
|
# 'lastname' is an API entry-point, so we need it to be unique.
|
||||||
|
'unique': True,
|
||||||
|
},
|
||||||
|
# 'role' is a list, and can only contain values from 'allowed'.
|
||||||
|
'role': {
|
||||||
|
'type': 'list',
|
||||||
|
'allowed': ["author", "contributor", "copy"],
|
||||||
|
},
|
||||||
|
# An embedded 'strongly-typed' dictionary.
|
||||||
|
'location': {
|
||||||
|
'type': 'dict',
|
||||||
|
'schema': {
|
||||||
|
'address': {'type': 'string'},
|
||||||
|
'city': {'type': 'string'}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'born': {
|
||||||
|
'type': 'datetime',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes_schema = {
|
||||||
|
'name': {
|
||||||
|
'type': 'string',
|
||||||
|
'minlength': 1,
|
||||||
|
'maxlength': 128,
|
||||||
|
},
|
||||||
|
'parent': {
|
||||||
|
'type': 'objectid',
|
||||||
|
# 'data_relation': {
|
||||||
|
# 'resource': 'node',
|
||||||
|
# 'field': '_id',
|
||||||
|
# },
|
||||||
|
},
|
||||||
|
'node_type' : {
|
||||||
|
'type' : 'string',
|
||||||
|
'validcf' : True,
|
||||||
|
},
|
||||||
|
# 'custom_fields' : {
|
||||||
|
# 'type' : 'dict'
|
||||||
|
# }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nodes = {
|
||||||
|
# We choose to override global cache-control directives for this resource.
|
||||||
|
'cache_control': 'max-age=10,must-revalidate',
|
||||||
|
'cache_expires': 10,
|
||||||
|
|
||||||
|
# most global settings can be overridden at resource level
|
||||||
|
'resource_methods': ['GET', 'POST'],
|
||||||
|
|
||||||
|
'schema': nodes_schema
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
people = {
|
||||||
|
# 'title' tag used in item links. Defaults to the resource title minus
|
||||||
|
# the final, plural 's' (works fine in most cases but not for 'people')
|
||||||
|
'item_title': 'person',
|
||||||
|
|
||||||
|
# by default the standard item entry point is defined as
|
||||||
|
# '/people/<ObjectId>'. We leave it untouched, and we also enable an
|
||||||
|
# additional read-only entry point. This way consumers can also perform
|
||||||
|
# GET requests at '/people/<lastname>'.
|
||||||
|
'additional_lookup': {
|
||||||
|
'url': 'regex("[\w]+")',
|
||||||
|
'field': 'lastname'
|
||||||
|
},
|
||||||
|
|
||||||
|
# We choose to override global cache-control directives for this resource.
|
||||||
|
'cache_control': 'max-age=10,must-revalidate',
|
||||||
|
'cache_expires': 10,
|
||||||
|
|
||||||
|
# most global settings can be overridden at resource level
|
||||||
|
'resource_methods': ['GET', 'POST'],
|
||||||
|
|
||||||
|
'schema': schema
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DOMAIN = {
|
||||||
|
'people': people,
|
||||||
|
'nodes' : nodes
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user