Skip to content

Instantly share code, notes, and snippets.

View ishakoktn's full-sized avatar

İshak Okutan ishakoktn

  • Konya, Turkey
View GitHub Profile
@ishakoktn
ishakoktn / base64image_translationsfields.py
Created May 23, 2022 13:06
Accept Base64 Image with Django Parler Rest
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:
@ishakoktn
ishakoktn / translation_serializers.py
Created December 31, 2021 00:10
Django Parler Serializer To Take Only Selected Language's Data
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)
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)
@ishakoktn
ishakoktn / log_mixin.py
Last active March 16, 2021 23:40 — forked from Bernix01/log.py
Using LogEntry on Django Rest Framework Viewset
'''
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 _
@ishakoktn
ishakoktn / gist:b8eb326b128acf47861a67c5e1dc48b7
Last active August 25, 2020 12:47
React Native Janus Gateway
/*
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
# model.py
from django.contrib.gis.db.models import PointField
class User(AbstractBaseUser, PermissionsMixin):
...
location = PointField(_('location'), null=True, blank=True)
...
# 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
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