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 itertools import groupby | |
| from operator import itemgetter | |
| def get_subclasses(cls: type): | |
| for subclass in cls.__subclasses__(): | |
| yield subclass | |
| yield from get_subclasses(subclass) | |
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
| SELECT | |
| mcl.changes #>> '{name, old_value, repr}' | |
| FROM history_modelchangelog as mcl | |
| WHERE ( | |
| mcl.action = 'updated' | |
| AND (mcl.changes #>> '{name, new_value, repr}') = %(new_name)s | |
| AND (mcl.changes #>> '{name, old_value, repr}') IS NOT NULL | |
| AND mcl.content_type_id = %(content_type_id)s | |
| AND mcl.object_id = %(object_id)s | |
| ) |
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 SingletonMeta(type): | |
| _instance = None | |
| _args = None | |
| _kwargs = None | |
| def __call__(cls, *args, **kwargs): | |
| if not cls._instance: | |
| cls._args = args | |
| cls._kwargs = kwargs | |
| cls._instance = super(SingletonMeta, cls).__call__(*args, **kwargs) |
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 functools | |
| import threading | |
| from time import sleep | |
| lock = threading.Lock() | |
| class SingletonMeta(type): | |
| _instance = None | |
| _args = 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
| from datetime import datetime | |
| from sqlalchemy import Column, Integer, DateTime, ForeignKey | |
| from sqlalchemy.orm import relationship | |
| from sqlalchemy.ext.declarative import declared_attr | |
| from flask_security import current_user | |
| class AuditMixin(object): | |
| created_at = Column(DateTime, default=datetime.now) | |
| updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now) |
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 typing import Any, Callable, Dict, Optional, Type, TypeVar | |
| from environs import Env | |
| __all__ = ('EnvVar',) | |
| T = TypeVar('T') | |
| class EnvVar: |
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 setup_audit(cls, level): | |
| # some code | |
| print(cls, level) | |
| class AuditMeta(type): | |
| def __new__(mcs, name, bases, attrs, **kwargs): | |
| cls = super().__new__(mcs, name, bases, attrs) | |
| level = kwargs.get('level', 0) | |
| setup_audit(cls, level) |
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 graphene import InputObjectType, ObjectType, Schema, String, ID, Field, List | |
| class UserSchema(ObjectType): | |
| username = String() | |
| first_name = String() | |
| class PostSchema(ObjectType): | |
| id = ID() |
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
| # shellcheck disable=SC2046 | |
| docker build -f docker/Dockerfile -t defmain/backend:latest . -t defmain/backend:$(git rev-parse --short HEAD) |
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
| # tests/helpers.py | |
| from contextlib import contextmanager | |
| from typing import TYPE_CHECKING, Any, Iterator | |
| from defmain.settings import get_settings | |
| if TYPE_CHECKING: | |
| from defmain.settings import Settings |