2011-05-30 09:03:04 +10:00
|
|
|
import datetime
|
|
|
|
import re
|
2011-06-08 20:23:08 +10:00
|
|
|
from piston.utils import rc
|
2011-05-30 09:03:04 +10:00
|
|
|
from piston.handler import AnonymousBaseHandler
|
|
|
|
from pastebin.apps.dpaste.models import Snippet
|
|
|
|
|
|
|
|
class SnippetHandler(AnonymousBaseHandler):
|
2011-05-30 18:55:48 +10:00
|
|
|
allowed_methods = ('POST',)
|
2011-05-30 09:03:04 +10:00
|
|
|
fields = ('title', 'content',)
|
|
|
|
model = Snippet
|
|
|
|
|
|
|
|
def create(self, request):
|
|
|
|
if not request.POST.get('content'):
|
|
|
|
return rc.BAD_REQUEST
|
|
|
|
|
|
|
|
s = Snippet.objects.create(
|
|
|
|
content=request.POST.get('content'),
|
|
|
|
expires=datetime.datetime.now()+datetime.timedelta(seconds=60*60*24*30)
|
|
|
|
)
|
|
|
|
s.save()
|
|
|
|
return 'http://dpaste.de%s' % s.get_absolute_url()
|