This file contains hidden or 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
def to_dict(table, *keys, **kwargs): | |
""" | |
Coverts table like 2D list to dict | |
Args: | |
table (list of dict): result of values_list ORM method, | |
lets interpret each dict item of the list as a `row`. | |
*keys: keys in order from highest to lowest dimension | |
kwargs[flat_val_from] (str): if provided - returns flat key -> atomic dict, | |
other wise returns key -> `row`. |
This file contains hidden or 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
--- | |
version: "3.7" | |
services: | |
api: | |
image: flink_api | |
build: | |
context: ./api | |
dockerfile: Dockerfile | |
user: saleor:www-data |
This file contains hidden or 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
import pdb | |
import traceback | |
class DebugOnError: | |
def __init__(self, suppress=False): | |
self.suppress = suppress | |
def __enter__(self): | |
return None |
This file contains hidden or 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
import logging | |
log = logging.getLogger(__name__) | |
def enum_reduce(enum_name, _enum, exclude): | |
""" | |
Returns Enum type, based on specified _enum, | |
but reduced by iterable object of keys. |
This file contains hidden or 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
# Hardcode versions for all packages! <package>==x.y.z | |
psycopg2-binary | |
django | |
# REST Framework | |
djangorestframework | |
# Tests |
This file contains hidden or 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 python:3.7 | |
RUN mkdir /app | |
WORKDIR /app | |
# make docker user | |
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo | |
# turn off bell | |
RUN echo 'set bell-style none' >> ~/.inputrc |
This file contains hidden or 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 collections import defaultdict, OrderedDict | |
class DefaultOrderedDict(OrderedDict, defaultdict): | |
def __init__(self, default_factory=None, *args, **kwargs): | |
super(DefaultOrderedDict, self).__init__(*args, **kwargs) | |
self.default_factory = default_factory |
This file contains hidden or 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
class BiDict(object): | |
''' | |
Maps both directions: key->value and value->key | |
Requires both keys and values are unique. If you pass duplication, | |
then key/value be overwritten and you get not what expected. | |
''' | |
origin = {} # counters the {key->key} case | |
bidict = {} |
This file contains hidden or 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
class FileUploadSerializer(serializers.Serializer): | |
attachment = serializers.FileField() | |
class FileUploadView(views.APIView): | |
''' | |
FileUploadParser - is some sort of retardnes, | |
it takes entier http body and parses it as a file 0_0. | |
Very useful! Specially trash headers, prepended to the text file... | |
So, just don't use it ;-> Use MultiPartParser instead. |
This file contains hidden or 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 decimal import Decimal | |
from django.db import connection | |
from django.utils.decorators import ContextDecorator | |
class CountQueries(ContextDecorator): | |
''' | |
Either logs(if logger instance has passed) or prints number of queries. |
NewerOlder