diff --git a/dpaste/handlers.py b/dpaste/handlers.py deleted file mode 100644 index bb22588..0000000 --- a/dpaste/handlers.py +++ /dev/null @@ -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() diff --git a/dpaste/urls/dpaste_api.py b/dpaste/urls/dpaste_api.py index ae02f14..67447b2 100644 --- a/dpaste/urls/dpaste_api.py +++ b/dpaste/urls/dpaste_api.py @@ -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'), ) \ No newline at end of file diff --git a/dpaste/views.py b/dpaste/views.py index ef15c72..ce13db0 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -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: diff --git a/requirements.txt b/requirements.txt index dc84690..356d21d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ django==1.5 django-mptt==0.4.2 -django-piston==0.2.3 pygments==1.6 south==0.7.6