Untitled
unknown
plain_text
3 years ago
3.8 kB
10
Indexable
#settings.py
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import ListModelMixin, CreateModelMixin
from rest_framework import viewsets
from rest_framework.generics import get_object_or_404
from firsatcocuk_core.models import *
from firsatcocuk_core.api.serializers import *
from dj_rest_auth.registration.views import RegisterView
from .serializers import CustomRegisterSerializer
from rest_framework import views
#to add
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import authentication, permissions
from django.contrib.auth.models import User
import secrets
import base64
import hmac
import hashlib
import requests
import json
class ArtistViewSet(viewsets.ModelViewSet):
queryset = Artist.objects.all()
serializer_class = ArtistSerializer
class ListUsers(APIView):
"""
View to list all users in the system.
* Requires token authentication.
* Only admin users are able to access this view.
"""
authentication_classes = [authentication.TokenAuthentication]
permission_classes = [permissions.IsAdminUser]
def get(self, request, format=None):
"""
Return a list of all users.
"""
usernames = [user.username for user in User.objects.all()]
return Response(usernames)
class ListArtists(APIView):
"""
View to list all artists in the system.
* Requires token authentication.
* Only admin users are able to access this view.
"""
authentication_classes = [authentication.TokenAuthentication]
permission_classes = [permissions.IsAdminUser]
def get(self, request, format=None):
"""
Return a list of all users.
"""
artistnames = [artist.name for user in Artist.objects.all()]
return Response(artistnames)
#serializers.py
from rest_framework import serializers
from firsatcocuk_core.models import *
from dj_rest_auth.serializers import TokenSerializer
from dj_rest_auth.registration.serializers import RegisterSerializer
class ArtistSerializer(serializers.ModelSerializer):
class Meta:
model = Artist
fields = '__all__'
#urls.py
from django.urls import path, include
from firsatcocuk_core.api.views import *
from django.conf import settings
from rest_framework import routers
from django.conf.urls.static import static
routers = routers.DefaultRouter()
routers.register('artists', ArtistViewSet)
routers.register('cities', CityViewSet)
routers.register('buildings', BuildingViewSet)
routers.register('rules', RuleViewSet)
routers.register('halls', HallViewSet)
routers.register('blocks', BlockViewSet)
routers.register('seats', SeatViewSet)
# routers.register('events', EventViewSet)
# routers.register('variants', VariantViewSet)
routers.register('tickets', TicketViewSet)
routers.register('categories', CategoryViewSet)
routers.register('sliders', SliderViewSet)
urlpatterns = [
path('', include(routers.urls)),
path('category/<int:id>/', CategoryDetailViewSet.as_view(), name="category_detail"),
path('category/<int:id>/<int:limit>/', CategoryDetailViewSet.as_view(), name="category_detail"),
path('payment/', PaymentViewSet.as_view(), name="payment"),
path('events/', EventViewSet.as_view(), name="event_detail"),
path('events/<int:id>/', EventViewSet.as_view(), name="event_detail"),
path('variants/', VariantViewSet.as_view(), name="variant_detail"),
path('variants/<int:id>/', VariantViewSet.as_view(), name="variant_detail"),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)Editor is loading...