diff --git a/LICENSE b/LICENSE index 37ec93a..bafcd20 100644 --- a/LICENSE +++ b/LICENSE @@ -176,7 +176,7 @@ recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2013 Jeff Knupp Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/docs/.doctrees/environment.pickle b/docs/.doctrees/environment.pickle index 6330e67..01267cd 100644 Binary files a/docs/.doctrees/environment.pickle and b/docs/.doctrees/environment.pickle differ diff --git a/docs/.doctrees/index.doctree b/docs/.doctrees/index.doctree index 83cfd3f..8bfdbd4 100644 Binary files a/docs/.doctrees/index.doctree and b/docs/.doctrees/index.doctree differ diff --git a/docs/.doctrees/installation.doctree b/docs/.doctrees/installation.doctree index 089ce72..4448820 100644 Binary files a/docs/.doctrees/installation.doctree and b/docs/.doctrees/installation.doctree differ diff --git a/docs/.doctrees/modules.doctree b/docs/.doctrees/modules.doctree index 90fa1e7..0f6ac6e 100644 Binary files a/docs/.doctrees/modules.doctree and b/docs/.doctrees/modules.doctree differ diff --git a/docs/.doctrees/quickstart.doctree b/docs/.doctrees/quickstart.doctree index dfbc78d..0a3b8ff 100644 Binary files a/docs/.doctrees/quickstart.doctree and b/docs/.doctrees/quickstart.doctree differ diff --git a/docs/.doctrees/sandman.doctree b/docs/.doctrees/sandman.doctree index def6aad..9ffb27f 100644 Binary files a/docs/.doctrees/sandman.doctree and b/docs/.doctrees/sandman.doctree differ diff --git a/doc/conf.py b/docs/conf.py similarity index 100% rename from doc/conf.py rename to docs/conf.py diff --git a/docs/generated/.buildinfo b/docs/generated/.buildinfo new file mode 100644 index 0000000..0885fbe --- /dev/null +++ b/docs/generated/.buildinfo @@ -0,0 +1,4 @@ +# Sphinx build info version 1 +# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. +config: +tags: diff --git a/docs/generated/.doctrees/environment.pickle b/docs/generated/.doctrees/environment.pickle new file mode 100644 index 0000000..58a296c Binary files /dev/null and b/docs/generated/.doctrees/environment.pickle differ diff --git a/docs/generated/.doctrees/index.doctree b/docs/generated/.doctrees/index.doctree new file mode 100644 index 0000000..8bfdbd4 Binary files /dev/null and b/docs/generated/.doctrees/index.doctree differ diff --git a/docs/generated/.doctrees/installation.doctree b/docs/generated/.doctrees/installation.doctree new file mode 100644 index 0000000..4448820 Binary files /dev/null and b/docs/generated/.doctrees/installation.doctree differ diff --git a/docs/generated/.doctrees/modules.doctree b/docs/generated/.doctrees/modules.doctree new file mode 100644 index 0000000..0f6ac6e Binary files /dev/null and b/docs/generated/.doctrees/modules.doctree differ diff --git a/docs/generated/.doctrees/quickstart.doctree b/docs/generated/.doctrees/quickstart.doctree new file mode 100644 index 0000000..0a3b8ff Binary files /dev/null and b/docs/generated/.doctrees/quickstart.doctree differ diff --git a/docs/generated/.doctrees/sandman.doctree b/docs/generated/.doctrees/sandman.doctree new file mode 100644 index 0000000..9ffb27f Binary files /dev/null and b/docs/generated/.doctrees/sandman.doctree differ diff --git a/docs/_modules/index.html b/docs/generated/_modules/index.html similarity index 100% rename from docs/_modules/index.html rename to docs/generated/_modules/index.html diff --git a/docs/_modules/sandman/exception.html b/docs/generated/_modules/sandman/exception.html similarity index 100% rename from docs/_modules/sandman/exception.html rename to docs/generated/_modules/sandman/exception.html diff --git a/docs/_modules/sandman/model.html b/docs/generated/_modules/sandman/model.html similarity index 99% rename from docs/_modules/sandman/model.html rename to docs/generated/_modules/sandman/model.html index 6ae7120..ae35493 100644 --- a/docs/_modules/sandman/model.html +++ b/docs/generated/_modules/sandman/model.html @@ -62,7 +62,7 @@

Source code for sandman.model

     endpoint.
     
     :param cls: User-defined class derived from :class:`sandman.Resource` to be
-    registered with the endpoint returned by :func:`endpoint()`
+                registered with the endpoint returned by :func:`endpoint()`
     :type cls: :class:`sandman.Resource` or tuple
     
     """
diff --git a/docs/_modules/sandman/sandman.html b/docs/generated/_modules/sandman/sandman.html
similarity index 78%
rename from docs/_modules/sandman/sandman.html
rename to docs/generated/_modules/sandman/sandman.html
index 7d79ce2..de23451 100644
--- a/docs/_modules/sandman/sandman.html
+++ b/docs/generated/_modules/sandman/sandman.html
@@ -49,10 +49,14 @@ 

Navigation

Source code for sandman.sandman

 """Sandman REST API creator for Flask and SQLAlchemy"""
 
-from flask import jsonify, request, g, current_app, Response
+from flask import (jsonify, request, g, 
+        current_app, Response, render_template,
+        make_response)
 from . import app, db
 from .exception import JSONException
 
+JSON, HTML = range(2)
+
 def _get_session():
     """Return (and memoize) a database session"""
     session = getattr(g, '_session', None)
@@ -60,6 +64,40 @@ 

Source code for sandman.sandman

         session = g._session = db.session()
     return session
 
+def _get_mimetype(current_request):
+    """Return the mimetype for this request."""
+    if 'Accept' not in current_request.headers:
+        return JSON
+
+    if 'json' in current_request.headers['Accept']:
+        return JSON
+    else:
+        return HTML
+
+def _single_resource_json_response(resource):
+    """Return the JSON representation of *resource*"""
+    return jsonify(resource.as_dict())
+   
+def _single_resource_html_response(resource):
+    """Return the HTML representation of *resource*"""
+    tablename = resource.__tablename__
+    resource.pk = getattr(resource, resource.primary_key())
+    resource.attributes = resource.as_dict()
+    return make_response(render_template('resource.html', resource=resource,
+        tablename=tablename))
+
+def _collection_json_response(resources):
+    """Return the HTML representation of the collection *resources*"""
+    result_list = []
+    for resource in resources:
+        result_list.append(resource.as_dict())
+    return jsonify(resources=result_list)
+
+def _collection_html_response(resources):
+    """Return the HTML representation of the collection *resources*"""
+    return make_response(render_template('collection.html',
+        resources=resources))
+
 def _validate(cls, method, resource=None):
     """Return ``True`` if the the given *cls* supports the HTTP *method* found 
     on the incoming HTTP request.
@@ -75,7 +113,7 @@ 

Source code for sandman.sandman

     if not method in cls.__methods__:
         return False
 
-    class_validator_name = 'do_' + method
+    class_validator_name = 'validate_' + method
 
     if hasattr(cls, class_validator_name):
         class_validator = getattr(cls, class_validator_name)
@@ -83,18 +121,29 @@ 

Source code for sandman.sandman

 
     return True
 
-
[docs]def resource_created_response(resource): +
[docs]def resource_created_response(resource, current_request): """Return HTTP response with status code *201*, signaling a created *resource* :param resource: resource created as a result of current request :type resource: :class:`sandman.model.Resource` :rtype: :class:`flask.Response` """ - response = jsonify(resource.as_dict()) + if _get_mimetype(current_request) == JSON: + response = _single_resource_json_response(resource) + else: + response = _single_resource_html_response(resource) response.status_code = 201 response.headers['Location'] = 'http://localhost:5000/' + resource.resource_uri() return response
+
[docs]def resource_response(resource, current_request): + result_dict = resource.as_dict() + if _get_mimetype(current_request) == JSON: + return _single_resource_json_response(resource) + else: + return _single_resource_html_response(resource) + +
[docs]def unsupported_method_response(): """Return the appropriate *Response* with status code *403*, signaling the HTTP method used in the request is not supported for the given endpoint. @@ -149,13 +198,12 @@

Source code for sandman.sandman

         setattr(resource, resource.primary_key(), lookup_id)
         session.add(resource)
         session.commit()
-        return resource_created_response(resource)
+        return resource_created_response(resource, request)
     else:
         resource.from_dict(request.json)
         session.merge(resource)
         session.commit()
         return no_content_response()
-
 
@app.route('/<collection>', methods=['POST'])
[docs]def add_resource(collection): @@ -176,7 +224,7 @@

Source code for sandman.sandman

     session = _get_session()
     session.add(resource)
     session.commit()
-    return resource_created_response(resource)
+    return resource_created_response(resource, request)
 
@app.route('/<collection>/<lookup_id>', methods=['DELETE'])
[docs]def delete_resource(collection, lookup_id): @@ -222,8 +270,7 @@

Source code for sandman.sandman

     elif not _validate(cls, request.method, resource):
         return unsupported_method_response()
 
-    result_dict = resource.as_dict()
-    return jsonify(**result_dict)
+    return resource_response(resource, request)
 
@app.route('/<collection>', methods=['GET'])
[docs]def collection_handler(collection): @@ -242,10 +289,10 @@

Source code for sandman.sandman

     if not _validate(cls, request.method, resources):
         return unsupported_method_response()
 
-    result_list = []
-    for resource in resources:
-        result_list.append(resource.as_dict())
-    return jsonify(resources=result_list)
+ if _get_mimetype(request) == JSON: + return _collection_json_response(resources) + else: + return _collection_html_response(resources)
diff --git a/docs/_sources/index.txt b/docs/generated/_sources/index.txt similarity index 100% rename from docs/_sources/index.txt rename to docs/generated/_sources/index.txt diff --git a/docs/_sources/installation.txt b/docs/generated/_sources/installation.txt similarity index 100% rename from docs/_sources/installation.txt rename to docs/generated/_sources/installation.txt diff --git a/docs/_sources/modules.txt b/docs/generated/_sources/modules.txt similarity index 100% rename from docs/_sources/modules.txt rename to docs/generated/_sources/modules.txt diff --git a/docs/_sources/quickstart.txt b/docs/generated/_sources/quickstart.txt similarity index 98% rename from docs/_sources/quickstart.txt rename to docs/generated/_sources/quickstart.txt index 117e22e..6abdb0d 100644 --- a/docs/_sources/quickstart.txt +++ b/docs/generated/_sources/quickstart.txt @@ -13,7 +13,6 @@ Create one file with the following contents (which I call ``runserver.py``):: from sandman import app, db app.config['SQLALCHEMY_DATABASE_URI'] = 'R
resource_handler() (in module sandman.sandman)
+ +
resource_response() (in module sandman.sandman) +
+ diff --git a/docs/index.html b/docs/generated/index.html similarity index 100% rename from docs/index.html rename to docs/generated/index.html diff --git a/docs/installation.html b/docs/generated/installation.html similarity index 100% rename from docs/installation.html rename to docs/generated/installation.html diff --git a/docs/modules.html b/docs/generated/modules.html similarity index 100% rename from docs/modules.html rename to docs/generated/modules.html diff --git a/docs/generated/objects.inv b/docs/generated/objects.inv new file mode 100644 index 0000000..6b4bc97 Binary files /dev/null and b/docs/generated/objects.inv differ diff --git a/docs/py-modindex.html b/docs/generated/py-modindex.html similarity index 100% rename from docs/py-modindex.html rename to docs/generated/py-modindex.html diff --git a/docs/quickstart.html b/docs/generated/quickstart.html similarity index 83% rename from docs/quickstart.html rename to docs/generated/quickstart.html index da3a5cd..3897a8b 100644 --- a/docs/quickstart.html +++ b/docs/generated/quickstart.html @@ -55,16 +55,16 @@

Navigation

Quickstart

Create one file with the following contents (which I call runserver.py):

-
from sandman.model import register, Model
+
from sandman.model import register, Model
 
-# Insert Models here
-# Register models here
-# register((Model1, Model2, Model3))
+# Insert Models here
+# Register models here
+# register((Model1, Model2, Model3))
 
-from sandman import app, db
-app.config['SQLALCHEMY_DATABASE_URI'] = '<your database connection string (using SQLAlchemy)'
-app.run()
-```
+from sandman import app, db +app.config['SQLALCHEMY_DATABASE_URI'] = '<your database connection string (using SQLAlchemy)' +app.run() +

Then simply run:

python runserver.py
diff --git a/docs/sandman.html b/docs/generated/sandman.html similarity index 93% rename from docs/sandman.html rename to docs/generated/sandman.html index 90849c3..cf41eea 100644 --- a/docs/sandman.html +++ b/docs/generated/sandman.html @@ -94,12 +94,11 @@

sandman Package -Parameters:cls – User-defined class derived from sandman.Resource to be +Parameters:cls (sandman.Resource or tuple) – User-defined class derived from sandman.Resource to be +registered with the endpoint returned by endpoint() -

registered with the endpoint returned by endpoint() -:type cls: sandman.Resource or tuple

@@ -208,7 +207,7 @@

sandman Package
-sandman.sandman.resource_created_response(resource)[source]
+sandman.sandman.resource_created_response(resource, current_request)[source]

Return HTTP response with status code 201, signaling a created resource

@@ -243,6 +242,11 @@

sandman Package +
+sandman.sandman.resource_response(resource, current_request)[source]
+
+
sandman.sandman.unsupported_method_response()[source]
diff --git a/docs/search.html b/docs/generated/search.html similarity index 100% rename from docs/search.html rename to docs/generated/search.html diff --git a/docs/generated/searchindex.js b/docs/generated/searchindex.js new file mode 100644 index 0000000..3ab6afa --- /dev/null +++ b/docs/generated/searchindex.js @@ -0,0 +1 @@ +Search.setIndex({envversion:42,terms:{code:[4,0],resource_handl:4,rest:[4,0],runserv:0,follow:0,yet:2,paramet:4,whose:4,expos:4,flask:[2,4],configur:0,except:[1,3],should:[4,0],other:0,unsupported_method_respons:4,collection_handl:4,lookup_id:4,modul:[1,3],sent:4,real:0,applic:4,sourc:4,"return":4,string:[4,0],insert:0,python:0,pypi:2,"import":0,requir:[2,4],httpexcept:4,specif:4,get_bodi:4,signal:4,patch:4,"try":0,collect:4,add_resourc:4,complet:4,page:1,jsonexcept:4,set:2,creator:4,connect:0,respons:4,resourc:4,get_head:4,index:1,statu:4,easili:2,databas:0,definit:0,your:0,content:[1,4,0],delet:4,werkzeug:4,"new":[4,0],method:4,whatev:0,run:[2,0],deriv:4,kei:4,gener:4,here:0,bodi:4,base:4,come:0,care:2,search:1,current:4,excecpt:4,action:4,patch_resourc:4,own:0,simpli:[2,0],app:0,api:[4,0],repsons:4,instal:1,primari:4,given:4,from:[4,0],aren:2,data:4,support:4,regist:[4,0],two:0,least:0,avail:4,json:4,call:0,taken:2,descript:4,scheme:0,type:4,"function":4,repons:4,idempot:4,no_content_respons:4,tupl:4,sqlalchemi:[2,4,0],than:4,none:4,endpoint:4,retriev:4,alia:4,servic:0,project:0,defin:4,below:2,can:0,result:4,quickstart:1,creat:[4,0],model3:0,model2:0,model1:0,current_request:4,sqlalchemy_database_uri:0,packag:[1,3],exist:4,file:0,pip:2,resource_respons:4,curl:0,serial:4,divid:0,rather:4,make:4,note:4,also:4,need:2,html:4,take:2,which:[4,0],resource_created_respons:4,you:[2,0],config:0,singl:4,updat:4,map:4,http:4,object:4,user:4,associ:4,"class":4,appropri:4,thu:4,request:4,doe:4,perform:4,environ:4,delete_resourc:4,model:[1,3,0]},objtypes:{"0":"py:module","1":"py:function","2":"py:method","3":"py:exception","4":"py:attribute"},objnames:{"0":["py","module","Python module"],"1":["py","function","Python function"],"2":["py","method","Python method"],"3":["py","exception","Python exception"],"4":["py","attribute","Python attribute"]},filenames:["quickstart","index","installation","modules","sandman"],titles:["Quickstart","Welcome to sandman’s documentation!","Installation","sandman","sandman Package"],objects:{"sandman.model":{Model:[4,4,1,""],register:[4,1,1,""]},"sandman.exception":{JSONException:[4,3,1,""]},"sandman.exception.JSONException":{get_body:[4,2,1,""],get_headers:[4,2,1,""]},sandman:{exception:[4,0,1,""],model:[4,0,1,""],sandman:[4,0,1,""]},"sandman.sandman":{resource_response:[4,1,1,""],add_resource:[4,1,1,""],collection_handler:[4,1,1,""],no_content_response:[4,1,1,""],unsupported_method_response:[4,1,1,""],patch_resource:[4,1,1,""],resource_created_response:[4,1,1,""],resource_handler:[4,1,1,""],delete_resource:[4,1,1,""]}},titleterms:{welcom:1,modul:4,except:4,indic:1,sandman:[1,3,4],packag:4,tabl:1,instal:2,model:4,document:1,quickstart:0}}) \ No newline at end of file diff --git a/doc/index.rst b/docs/index.rst similarity index 100% rename from doc/index.rst rename to docs/index.rst diff --git a/doc/installation.rst b/docs/installation.rst similarity index 100% rename from doc/installation.rst rename to docs/installation.rst diff --git a/doc/modules.rst b/docs/modules.rst similarity index 100% rename from doc/modules.rst rename to docs/modules.rst diff --git a/docs/objects.inv b/docs/objects.inv deleted file mode 100644 index 47f89f0..0000000 --- a/docs/objects.inv +++ /dev/null @@ -1,8 +0,0 @@ -# Sphinx inventory version 2 -# Project: sandman -# Version: 0.2 -# The remainder of this file is compressed using zlib. -xڭRAn HVsͽVJ)0L% )}mc6nS $,۳j^Ե1VFPה8 -l;C3pR4{dU\lɔ[k - u>Z閄$T϶ыWN˘_o` HYH囋ie$,8o6.=Rn./ټ,Տ}R]@)p mt -5kKIQՁ>( \ No newline at end of file diff --git a/doc/quickstart.rst b/docs/quickstart.rst similarity index 98% rename from doc/quickstart.rst rename to docs/quickstart.rst index 117e22e..6abdb0d 100644 --- a/doc/quickstart.rst +++ b/docs/quickstart.rst @@ -13,7 +13,6 @@ Create one file with the following contents (which I call ``runserver.py``):: from sandman import app, db app.config['SQLALCHEMY_DATABASE_URI'] = '