Skip to content

Instantly share code, notes, and snippets.

Avatar

David Sanders shangxiao

View GitHub Profile
View pyproject.toml
[tool.poetry]
name = "poetry-test"
version = "0.1.0"
description = ""
authors = ["Some User <some@user.com>"]
[tool.poetry.dependencies]
python = "^3.6"
[tool.poetry.dev-dependencies]
@shangxiao
shangxiao / results
Created Jul 3, 2019
Pytest not raising import exceptions for regular classes?
View results
shangxiao ~/projects/test-pytest $ pytest
========================================================= test session starts =========================================================
platform darwin -- Python 3.6.2, pytest-5.0.0, py-1.8.0, pluggy-0.12.0
rootdir: /Users/shangxiao/projects/test-pytest
collected 1 item
test_foo.py F [100%]
============================================================== FAILURES ===============================================================
________________________________________________________ FooTestCase.test_foo _________________________________________________________
@shangxiao
shangxiao / django-cte.md
Last active May 17, 2018
CTE's in Django
View django-cte.md
@shangxiao
shangxiao / debug_middleware.py
Created Sep 11, 2017
FunkyBob's debug middleware
View debug_middleware.py
import time
from django.conf import settings
from django.db import connection
class DebugMiddleware:
def __init__(self):
import logging
self.log = logging.getLogger(__name__)
View GraphQL & Relay notes (December 2015)
Relay Notes
===========
- Define a schema, that is used for _both_ server side endpoint setup & frontend graphql compilation
- node only for now, some graphql ports
- Relay has a strict specification of how a graphql schema is set up: https://facebook.github.io/relay/docs/graphql-relay-specification.html
- tree children are called "plural links" (see _writePluralLink())
@shangxiao
shangxiao / faq.md
Last active Jul 24, 2016
django faq
View faq.md

Frequently asked questions:

  • Why shouldn't i use mysql? / mongo?
  • Should I use jinja, I read it's faster?
  • Should I use sqlalchemy, I read it's superior?
  • How do i make this thing happen in parallel/not wait for xxx to finish?
  • Why does django ask for a default? (But my table has no data in it wtf django!?!)
    • FunkyBob | I think, perhaps, it's time I wrote a blog post on "why does a migration adding a field need a default?"
  • Why do I need to commit my migrations? Why can't I just run makemigrations on the server?
  • migrations are source, makemigrations is a helper which takes you part way
  • i've seen people accidentally lose their migrations on production…  oops now what?
@shangxiao
shangxiao / authenticated_or_404.py
Created May 14, 2016
Django view decorator for returning 404 if not authenticated
View authenticated_or_404.py
from functools import update_wrapper
from django.http import Http404
class authenticated_or_404(object):
def __init__(self, func):
self.func = func
update_wrapper(self, func)
@shangxiao
shangxiao / gotcha.py
Created Jul 31, 2015
Django is_authenticated gotcha
View gotcha.py
def some_view(request):
if request.user.is_authenticated:
do_something_private()
View gist:93b983ea2313aa71137a
class ChoiceField(Field):
...
def to_representation(self, value):
if data == '' and self.allow_blank:
return ''
try:
return self.choice_strings_to_values[six.text_type(value)]
except KeyError:
return value