- (gmail) ishak.oktn
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 rest_framework import serializers | |
from django.db import models | |
from drf_extra_fields.fields import Base64ImageField | |
from parler.models import TranslatableModelMixin, TranslatedFieldsModel | |
from parler_rest.serializers import TranslatedFieldsField | |
class Base64ImageModelMixin: |
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.conf import settings | |
LANGUAGES_CODES = [code for code, _ in settings.LANGUAGES] | |
DEFAULT_LANG = settings.PARLER_LANGUAGES['default'].get('fallback') | |
def get_languange_code(request): | |
""" gives languange code of the request | |
Returns(2 characters str) |
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 drf_yasg.generators import OpenAPISchemaGenerator | |
from drf_yasg.views import get_schema_view | |
from drf_yasg import openapi | |
from rest_framework.permissions import IsAdminUser | |
class CustomSchemeGenerator(OpenAPISchemaGenerator): | |
def get_path_parameters(self, path, view_cls): | |
parameters = super().get_path_parameters(path, view_cls) |
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
''' | |
Extracted and modified from django-model-logging | |
It used it's own LogEntry model but since django | |
has it's own LogEntry maybe someone would want to | |
register in the same model instead of creating a | |
new one. | |
''' | |
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, ContentType, DELETION | |
from django.utils.translation import gettext as _ |
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
/* | |
The MIT License (MIT) | |
Copyright (c) 2016 Meetecho | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the "Software"), | |
to deal in the Software without restriction, including without limitation | |
the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
and/or sell copies of the Software, and to permit persons to whom the |
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
# model.py | |
from django.contrib.gis.db.models import PointField | |
class User(AbstractBaseUser, PermissionsMixin): | |
... | |
location = PointField(_('location'), null=True, blank=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
# inspired by https://hashnode.com/post/using-django-drf-jwt-authentication-with-django-channels-cjzy5ffqs0013rus1yb9huxvl | |
# Caution! This is not secure for long live auth tokens. | |
# costum_middleware.py | |
from rest_framework_simplejwt.tokens import UntypedToken | |
from rest_framework_simplejwt.exceptions import InvalidToken, TokenError | |
from jwt import decode as jwt_decode | |
from django.conf import settings | |
from django.contrib.auth import get_user_model | |
from urllib.parse import parse_qs |
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 rest_framework_simplejwt.authentication import JWTAuthentication | |
from rest_framework_simplejwt.exceptions import InvalidToken | |
User = get_user_model() | |
class SetLastVisitMiddleware: | |
def __init__(self, get_response): | |
self.get_response = get_response |