Skip to content

Instantly share code, notes, and snippets.

View patrys's full-sized avatar

Patryk Zawadzki patrys

View GitHub Profile
@patrys
patrys / example.py
Last active November 6, 2019 13:56
An ugly hack that allows type composition in Graphene, as it depends on metaclasses, you need to explicitly import the extension for it to work
from .extensions import ObjectTypeExtension
class OrderWithEvents(ObjectTypeExtension):
class Meta:
base_type = Order
events = graphene.Field(
graphene.List(
OrderEvent, description="List of events associated with the order."
@patrys
patrys / orm-tips.md
Last active February 7, 2020 12:08

Django ORM relations

1. Use select_related sparingly

Django's select_related results in an SQL JOIN.

It's very useful when fetching a one-to-one relation:

class User(Model):
export HISTFILE=$HOME/.zsh_history
HISTSIZE=50000
SAVEHIST=10000
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_dups
setopt hist_ignore_space
setopt hist_verify
setopt inc_append_history
setopt share_history
@patrys
patrys / mirql.py
Created July 4, 2018 17:29
Apollo-Server in Python
import datetime
from graphql import GraphQLObjectType, GraphQLScalarType, GraphQLSchema, graphql, parse
from graphql.execution.base import ResolveInfo
from graphql.utils.build_ast_schema import build_ast_schema
def build_schema(schema_description: str):
ast_schema = parse(schema_description)
return build_ast_schema(ast_schema)
@patrys
patrys / gnome-shell.css
Created January 15, 2017 19:42
Prettier GNOME
/* ~/.themes/YourTheme/gnome-shell/gnome-shell.css */
stage {
font-family: "System Font";
}
#panel {
font-weight: normal;
}
#panel .panel-button {
color: #ffffff;
font-weight: normal;
from django.contrib.auth.decorators import login_required
from django.template.response import TemplateResponse
from django.utils.decorators import method_decorator
from django.views.generic import View
class MyClassBasedView(View):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
from django.views.generic import View
from django.template.response import TemplateResponse
def get(request):
return TemplateResponse(request, 'index.html')
my_class_based_view = View.as_view(dispatch=get, __init__=7, as_view=None)
from django.views.generic import View
from django.template.response import TemplateResponse
def get(request):
return TemplateResponse(request, 'index.html')
my_class_based_view = View.as_view(dispatch=get)
from django.views.generic import View
from django.template.response import TemplateResponse
def get(request):
return TemplateResponse(request, 'index.html')
my_class_based_view = View.as_view(http_method_not_allowed=get)
from django.views.generic import View
from django.template.response import TemplateResponse
def get(request):
return TemplateResponse(request, 'index.html')
my_class_based_view = View.as_view(get=get)
# TypeError: You tried to pass in the get method name as a keyword argument to View(). Don't do that.