Skip to content

Instantly share code, notes, and snippets.

View bismitaguha's full-sized avatar
:octocat:
Always learning

Bismita Guha bismitaguha

:octocat:
Always learning
View GitHub Profile
const listReducer = (state = initialState, action) => {
switch(action.type) {
case GET_LIST:
return {
...state,
list: action.payload,
};
default:
return state
}
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,
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
class RandomView(views.APIView):
@api_view(('GET',))
def activate(request, uidb64, token):
"""
Function for account activation
"""
try:
uid = force_text(urlsafe_base64_decode(uidb64))
from django.contrib.auth.tokens import PasswordResetTokenGenerator
class TokenGenerator(PasswordResetTokenGenerator):
"""
Class for generation token for email confirmation
"""
def _make_hash_value(self, user, timestamp):
"""
import statements
"""
class RandomView(views.APIView):
# other functions
def function(self, request, *args, **kwargs):
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
export SENDGRID_API_KEY=xxxxxxxxxxxxxxxxxxxxxxx
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'),
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
}