Removed Django-Piston, added a very simple view to handle API calls. Fully backwards compatible. Fixes all tests.

This commit is contained in:
Martin Mahner 2013-03-29 19:09:22 +01:00
parent c595d99e6d
commit 4978538a97
4 changed files with 21 additions and 28 deletions

View file

@ -1,22 +0,0 @@
import datetime
from piston.utils import rc
from piston.handler import AnonymousBaseHandler
from dpaste.models import Snippet
class SnippetHandler(AnonymousBaseHandler):
allowed_methods = ('POST',)
fields = ('content',)
model = Snippet
def create(self, request):
content = request.POST.get('content', '').strip()
if not content:
return rc.BAD_REQUEST
s = Snippet.objects.create(
content=content,
expires=datetime.datetime.now()+datetime.timedelta(seconds=60*60*24*30)
)
s.save()
return 'http://dpaste.de%s' % s.get_absolute_url()

View file

@ -1,9 +1,6 @@
from django.conf.urls.defaults import url, patterns
from piston.resource import Resource
from ..handlers import SnippetHandler
snippet_resource = Resource(handler=SnippetHandler)
from ..views import snippet_api
urlpatterns = patterns('',
url(r'^api/$', snippet_resource, name='dpaste_api_create_snippet'),
url(r'^api/$', snippet_api, name='dpaste_api_create_snippet'),
)

View file

@ -1,3 +1,5 @@
import datetime
from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404
from django.template.context import RequestContext
from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, \
@ -54,6 +56,23 @@ def snippet_new(request, template_name='dpaste/snippet_new.html'):
)
def snippet_api(request, enclose_quotes=True):
content = request.POST.get('content', '').strip()
if not content:
return HttpResponseBadRequest()
s = Snippet.objects.create(
content=content,
expires=datetime.datetime.now()+datetime.timedelta(seconds=60*60*24*30)
)
s.save()
response = 'http://dpaste.de%s' % s.get_absolute_url()
if enclose_quotes:
return HttpResponse('"%s"' % response)
return HttpResponse(response)
def snippet_details(request, snippet_id, template_name='dpaste/snippet_details.html', is_raw=False):
try:

View file

@ -1,6 +1,5 @@
django==1.5
django-mptt==0.4.2
django-piston==0.2.3
pygments==1.6
south==0.7.6