Add API route for paste
This commit is contained in:
parent
8555fbfa0f
commit
613369d9e9
|
@ -6,7 +6,7 @@ from django.core.files.base import File
|
|||
from django.core.cache import cache
|
||||
from rest_framework import viewsets, views, mixins, generics, exceptions
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.permissions import BasePermission, IsAuthenticated, SAFE_METHODS
|
||||
from rest_framework.permissions import BasePermission, IsAuthenticated, SAFE_METHODS, IsAuthenticatedOrReadOnly
|
||||
from rest_framework.response import Response
|
||||
from rest_auth.views import PasswordChangeView
|
||||
from rest_auth.registration.views import RegisterView
|
||||
|
@ -303,7 +303,6 @@ class PingView(views.APIView):
|
|||
return Response(200)
|
||||
|
||||
|
||||
|
||||
class DoorViewSet(viewsets.ViewSet, List):
|
||||
def list(self, request):
|
||||
cards = models.Card.objects.filter(active_status='card_active')
|
||||
|
@ -328,7 +327,6 @@ class DoorViewSet(viewsets.ViewSet, List):
|
|||
return Response(200)
|
||||
|
||||
|
||||
|
||||
class IpnView(views.APIView):
|
||||
def post(self, request):
|
||||
try:
|
||||
|
@ -339,7 +337,6 @@ class IpnView(views.APIView):
|
|||
return Response(200)
|
||||
|
||||
|
||||
|
||||
class StatsView(views.APIView):
|
||||
def get(self, request):
|
||||
stats_keys = utils_stats.DEFAULTS.keys()
|
||||
|
@ -369,6 +366,19 @@ class BackupView(views.APIView):
|
|||
return Response(dict(url=backup_url))
|
||||
|
||||
|
||||
class PasteView(views.APIView):
|
||||
permission_classes = [IsAuthenticatedOrReadOnly]
|
||||
|
||||
def get(self, request):
|
||||
return Response(dict(paste=cache.get('paste', '')))
|
||||
|
||||
def post(self, request):
|
||||
if 'paste' in request.data:
|
||||
cache.set('paste', request.data['paste'][:20000])
|
||||
return Response(dict(paste=cache.get('paste', '')))
|
||||
else:
|
||||
raise exceptions.ValidationError(dict(paste='This field is required.'))
|
||||
|
||||
|
||||
class RegistrationView(RegisterView):
|
||||
serializer_class = serializers.MyRegisterSerializer
|
||||
|
|
|
@ -30,6 +30,7 @@ urlpatterns = [
|
|||
url(r'^user/', views.UserView.as_view(), name='user'),
|
||||
url(r'^ping/', views.PingView.as_view(), name='ping'),
|
||||
url(r'^stats/', views.StatsView.as_view(), name='stats'),
|
||||
url(r'^paste/', views.PasteView.as_view(), name='paste'),
|
||||
url(r'^backup/', views.BackupView.as_view(), name='backup'),
|
||||
url(IPN_ROUTE, views.IpnView.as_view(), name='ipn'),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue
Block a user