Skip to content

Instantly share code, notes, and snippets.

Sudip Raval rsudip90

Block or report user

Report or block rsudip90

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rsudip90
rsudip90 / views.py
Created May 12, 2019
drf serializer classes dynamic -- views.py -- custom user limited info
View views.py
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 May 12, 2019
drf serializer class dynamic -- views.py -- using serializer_action_classes
View views.py
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
drf serializer class dynamic -- mixins.py
View 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
drf serializer class dynamic -- serializers.py
View 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 May 12, 2019
drf serializer class dynamic -- models.py
View 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
get serializer classes dynamically based on viewset actions
View mixins.py
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 Feb 28, 2019
Google Picker dialog vue component
View GPicker.vue
<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 Oct 4, 2018 — 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.
View extract-attachments.py
#!/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 May 7, 2019
working with MySQL JSON type in prepared statements using Go
View directory_structure.txt
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 Jul 15, 2018
MySQL JSON type data handling in python
View mysql-json-ex.py
import mysql.connector
import json
config = {
"user": "",
"password": "",
"host": "localhost",
"database": "test",
"use_pure": True,
}
You can’t perform that action at this time.