Skip to content

Instantly share code, notes, and snippets.

View carljm's full-sized avatar

Carl Meyer carljm

View GitHub Profile
@carljm
carljm / jinja2backend.py
Created June 14, 2015 21:21
Django Jinja2 backend subclass with context processor support
class Jinja2Backend(jinja2backend.Jinja2):
def __init__(self, params):
self.context_processors = [
import_string(p)
for p in params['OPTIONS'].pop('context_processors', [])
]
super(Jinja2Backend, self).__init__(params)
diff --git a/mypy/semanal.py b/mypy/semanal.py
index 7bac809..33d798f 100644
--- a/mypy/semanal.py
+++ b/mypy/semanal.py
@@ -2943,21 +2943,9 @@ class SemanticAnalyzer(NodeVisitor):
if isinstance(base.node, TypeInfo):
# C.bar where C is a class
type_info = base.node
- elif isinstance(base.node, Var) and self.function_stack:
- # check for self.bar or cls.bar in method/classmethod
@carljm
carljm / decorators.py
Created March 27, 2011 18:28
An example of a decorator for a view that returns a TemplateResponse, modifying the template context before it is rendered.
def paginate(ctx_name):
"""
View decorator that handles pagination of a ListObject. Expects to find it
in the TemplateResponse context under the name ``ctx_name``.
This needs to not force delivery of the ListObject.
"""
def decorator(view_func):
@wraps(view_func)
class TransactionMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
with transaction.atomic():
response = self.get_response(request)
if response.status_code == 500:
transaction.set_rollback()
return response
diff --git a/docs/ref/forms/models.txt b/docs/ref/forms/models.txt
index 46f7df1..dd0a422 100644
--- a/docs/ref/forms/models.txt
+++ b/docs/ref/forms/models.txt
@@ -33,8 +33,8 @@ Model Form Functions
``formfield_callback`` and ``widgets`` are all passed through to
:func:`~django.forms.models.modelform_factory`.
- Arguments ``formset``, ``extra``, ``max_num``, ``can_order``, and
- ``can_delete`` are passed through to
It seems to me that there's a remarkable level of consensus developing
here (though it may not look like it), and a small set of remaining open
questions.
The consensus (as I see it):
- Migrate away from scraping external HTML pages, with package owners in
control of the migration but a deadline for a forced switch, as outlined
in Holger's PEP (with all appropriate caution and testing).
It seems to me that there's a remarkable level of consensus developing here (though it may not look like it), and a small set of remaining open questions.
The consensus (as I see it):
- Migrate away from scraping external HTML pages, with package owners in control of the migration but a deadline for a forced switch, as outlined in Holger's PEP (with all appropriate caution and testing).
- In some way, migrate to a situation where the popular installer tools install only release files from PyPI by default, but are capable of installing from other locations if the user provides an option.
The open question is basically how to implement the latter portion. I see two options proposed:
import unittest
from unittest import mock
class SomeClass:
def a_method(self):
return 2
class TestStub(unittest.TestCase):
if 'raven.contrib.django' in settings.INSTALLED_APPS: # pragma: no cover
from raven.contrib.celery import register_signal
from raven.contrib.django.models import client
# automatic logging of task failures to Sentry
register_signal(client)
@carljm
carljm / test_something.py
Created February 8, 2013 19:26
writing a py.test fixture that can take params from the test
@pytest.fixture
def template(request):
if 'param' in request.fixturenames:
param = request.getfuncargvalue('param')
else:
param = 'default'
# return something based on param