This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const listReducer = (state = initialState, action) => { | |
switch(action.type) { | |
case GET_LIST: | |
return { | |
...state, | |
list: action.payload, | |
}; | |
default: | |
return state | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultView(viewsets.ModelViewSet): | |
books = Book.objects.all() | |
authors = Author.objects.all() | |
book_serializer = BookSerializer(books, many=True) | |
author_serializer = AuthorSerializer(authors, many=True) | |
return Response({ | |
"books": book_serializer.data, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookListSerializer(serializers.ListSerializer): | |
def create(self, validated_data): | |
books = [Book(**item) for item in validated_data] | |
return Book.objects.bulk_create(books) | |
class BookSerializer(serializers.Serializer): | |
... | |
class Meta: | |
list_serializer_class = BookListSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RandomView(views.APIView): | |
@api_view(('GET',)) | |
def activate(request, uidb64, token): | |
""" | |
Function for account activation | |
""" | |
try: | |
uid = force_text(urlsafe_base64_decode(uidb64)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.tokens import PasswordResetTokenGenerator | |
class TokenGenerator(PasswordResetTokenGenerator): | |
""" | |
Class for generation token for email confirmation | |
""" | |
def _make_hash_value(self, user, timestamp): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
import statements | |
""" | |
class RandomView(views.APIView): | |
# other functions | |
def function(self, request, *args, **kwargs): | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dotenv import load_dotenv | |
load_dotenv() | |
""" | |
Other settings here | |
""" | |
SENDGRID_API_KEY = os.getenv('SENDGRID_API_KEY') | |
SENDGRID_SANDBOX_MODE_IN_DEBUG = False | |
SENDGRID_ECHO_TO_STDOUT = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export SENDGRID_API_KEY=xxxxxxxxxxxxxxxxxxxxxxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from rest_framework_simplejwt import TokenObtainPairView, TokenRefreshView | |
urlpatterns = [ | |
# Other URLs... | |
path('api/token/', TokenObtainPairView, name='token_obtain_pair'), | |
path('api/token/refresh/', TokenRefreshView, name='token_refresh'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REST_FRAMEWORK = { | |
'DEFAULT_AUTHENTICATION_CLASSES': [ | |
'rest_framework_simplejwt.authentication.JWTAuthentication', | |
], | |
} |