Skip to content

Instantly share code, notes, and snippets.

@rsudip90
rsudip90 / views.py
Created May 12, 2019 11:52
drf serializer classes dynamic -- views.py -- custom user limited info
from rest_framework import viewsets
from .mixins import GetSerializerClassMixin
from .models import User, Company, SystemUserRole
from .serializers import (
CompanySerializer,
CompanyDetailSerializer,
UserSerializer,
UserDetailSerializer,
)
@rsudip90
rsudip90 / views.py
Last active February 14, 2022 07:56
drf serializer class dynamic -- views.py -- using serializer_action_classes
from rest_framework import viewsets
from .mixins import GetSerializerClassMixin
from .models import User, Company, SystemUserRole
from .serializers import (
CompanySerializer,
CompanyDetailSerializer,
UserSerializer,
UserDetailSerializer,
)
@rsudip90
rsudip90 / mixins.py
Created May 12, 2019 10:32
drf serializer class dynamic -- mixins.py
class GetSerializerClassMixin(object):
def get_serializer_class(self):
"""
A class which inhertis this mixins should have variable
`serializer_action_classes`.
Look for serializer class in self.serializer_action_classes, which
should be a dict mapping action name (key) to serializer class (value),
i.e.:
@rsudip90
rsudip90 / serializers.py
Created May 12, 2019 10:08
drf serializer class dynamic -- serializers.py
from rest_framework import serializers
from enumfields.drf.serializers import EnumSupportSerializerMixin
from .models import User, Company
class CompanySerializer(serializers.ModelSerializer):
full_address = serializers.CharField(read_only=True)
class Meta:
model = Company
@rsudip90
rsudip90 / models.py
Last active February 14, 2022 07:57
drf serializer class dynamic -- models.py
from django.conf import settings
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import ugettext_lazy as _
from enumfields import EnumField
from enumfields import Enum
class SystemUserRole(Enum):
SYS_ADMIN = "SYS_ADMIN"
SYS_USER = "SYS_USER"
@rsudip90
rsudip90 / mixins.py
Last active May 7, 2019 18:27
get serializer classes dynamically based on viewset actions
class GetSerializerClassMixin(object):
def get_serializer_class(self):
"""
under class which inhertis this mixins should have variable
`serializer_action_classes`.
Look for serializer class in self.serializer_action_classes, which
should be a dict mapping action name (key) to serializer class (value),
i.e.:
@rsudip90
rsudip90 / GPicker.vue
Last active February 28, 2019 12:28
Google Picker dialog vue component
<template lang="pug">
div
button.pronto-btn.add(disabled="true" ref="gAPIAuthBtn") Authenticate
div(ref="gAPIResult")
</template>
<script>
export default {
data() {
return {
@rsudip90
rsudip90 / extract-attachments.py
Created October 4, 2018 17:13 — forked from stefansundin/extract-attachments.py
Extract attachments from emails that Gmail doesn't allow you to download. This is dumb. Please use Python >= 3.4.
#!/usr/bin/env python3
# Get your files that Gmail block. Warning message:
# "Anti-virus warning - 1 attachment contains a virus or blocked file. Downloading this attachment is disabled."
# Based on: https://spapas.github.io/2014/10/23/retrieve-gmail-blocked-attachments/
# Instructions:
# Go to your emails, click the arrow button in the top right, "Show original", then "Download Original".
# Move the files to the same directory as this program, then run it.
import email
@rsudip90
rsudip90 / directory_structure.txt
Last active November 23, 2021 23:07
working with MySQL JSON type in prepared statements using Go
go-mysql-json-ex/
|-- dbm/ // contains all database related operations
| |-- internal/ // internal only accessible to dbm
| | |-- base.go // contains db conf, manager
| | |-- prepsql.go // all prepared statements used in entire app
| |-- conn.go // db init, close API call
| |-- delete.go // delete db resource APIs
| |-- get.go // get db resource APIs
| |-- insert.go // insert db resource APIs
| |-- models.go // models in go representing db tables structrure
@rsudip90
rsudip90 / mysql-json-ex.py
Last active October 26, 2019 23:05
MySQL JSON type data handling in python
import mysql.connector
import json
config = {
"user": "",
"password": "",
"host": "localhost",
"database": "test",
"use_pure": True,
}