Skip to content

Instantly share code, notes, and snippets.

@orehush
orehush / serializers.py
Last active December 18, 2023 14:23
DRF simple JWT logout flow
from django.utils.text import gettext_lazy as _
from rest_framework import serializers
from rest_framework_simplejwt.tokens import RefreshToken, TokenError
class RefreshTokenSerializer(serializers.Serializer):
refresh = serializers.CharField()
default_error_messages = {
'bad_token': _('Token is invalid or expired')
}
@orehush
orehush / apns.py
Created July 5, 2018 14:24
Send apns notification to iOS device in Python
import socket
import ssl
import json
import struct
import binascii
# device token returned when the iPhone application
# registers to receive alerts
device_token = b'XXXX ... XXX'
@orehush
orehush / django-validator-for-serializer-and-form.py
Created June 13, 2017 11:10
Common validator for use in both rest framework serializers and django forms. Support overriding for default error messages and error field representation
class Validator(object):
"""
Validator for validate data,
which used for both rest framework serializers and django forms.
Support binding error message for several fields
if you override default error fields and set value as tuple.
"""
default_error_messages = {