Working on API
parent
d4dc37e430
commit
37fedf10f2
|
@ -0,0 +1,31 @@
|
||||||
|
from piston.handler import AnonymousBaseHandler, BaseHandler
|
||||||
|
from piston.utils import rc
|
||||||
|
|
||||||
|
from snipts.models import Snipt
|
||||||
|
|
||||||
|
|
||||||
|
class AnonSniptHandler(AnonymousBaseHandler):
|
||||||
|
model = Snipt
|
||||||
|
fields = ('title',)
|
||||||
|
|
||||||
|
def read(self, request, snipt_id):
|
||||||
|
return super(self.read)
|
||||||
|
|
||||||
|
class SniptHandler(BaseHandler):
|
||||||
|
allowed_methods = ('GET',)
|
||||||
|
anonymous = AnonSniptHandler
|
||||||
|
exclude = ('id',)
|
||||||
|
model = Snipt
|
||||||
|
|
||||||
|
def read(self, request, snipt_id):
|
||||||
|
"""
|
||||||
|
Returns an individual public or private snipt.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if snipt_id:
|
||||||
|
try:
|
||||||
|
return Snipt.objects.get(pk=snipt_id, public=True)
|
||||||
|
except Snipt.DoesNotExist:
|
||||||
|
return rc.NOT_FOUND
|
||||||
|
else:
|
||||||
|
return rc.BAD_REQUEST
|
|
@ -0,0 +1,17 @@
|
||||||
|
from django.conf.urls.defaults import *
|
||||||
|
|
||||||
|
from piston.emitters import Emitter
|
||||||
|
from piston.resource import Resource
|
||||||
|
|
||||||
|
from api.handlers import SniptHandler
|
||||||
|
|
||||||
|
|
||||||
|
Emitter.unregister('django')
|
||||||
|
Emitter.unregister('pickle')
|
||||||
|
Emitter.unregister('yaml')
|
||||||
|
|
||||||
|
snipt_handler = Resource(SniptHandler)
|
||||||
|
|
||||||
|
urlpatterns = patterns('',
|
||||||
|
url(r'^snipt/(?P<snipt_id>\d+)/', snipt_handler),
|
||||||
|
)
|
|
@ -13,6 +13,9 @@
|
||||||
-e git+http://github.com/benoitc/gunicorn.git#egg=gunicorn
|
-e git+http://github.com/benoitc/gunicorn.git#egg=gunicorn
|
||||||
-e hg+ssh://hg@bitbucket.org/nicksergeant/dwfab#egg=dwfab
|
-e hg+ssh://hg@bitbucket.org/nicksergeant/dwfab#egg=dwfab
|
||||||
|
|
||||||
|
# API
|
||||||
|
-e hg+ssh://hg@bitbucket.org/jespern/django-piston#egg=django-piston
|
||||||
|
|
||||||
BeautifulSoup
|
BeautifulSoup
|
||||||
django-taggit
|
django-taggit
|
||||||
django-postmark
|
django-postmark
|
||||||
|
|
|
@ -60,6 +60,7 @@ INSTALLED_APPS = (
|
||||||
|
|
||||||
'compressor',
|
'compressor',
|
||||||
'django_bcrypt',
|
'django_bcrypt',
|
||||||
|
'piston',
|
||||||
'south',
|
'south',
|
||||||
'taggit',
|
'taggit',
|
||||||
|
|
||||||
|
|
2
urls.py
2
urls.py
|
@ -14,5 +14,7 @@ urlpatterns = patterns('',
|
||||||
url(r'^404/$', direct_to_template, {'template': '404.html'}),
|
url(r'^404/$', direct_to_template, {'template': '404.html'}),
|
||||||
url(r'^500/$', direct_to_template, {'template': '500.html'}),
|
url(r'^500/$', direct_to_template, {'template': '500.html'}),
|
||||||
|
|
||||||
|
url(r'^api/', include('api.urls')),
|
||||||
|
|
||||||
url(r'^$', home),
|
url(r'^$', home),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue