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 django.core import serializers | |
widgets = serializers.deserialize('json', open('widget/fixtures/widgets.json')) | |
for widget_data in widgets: | |
widget = orm.Widget() | |
for k,v in widget_data.object.__dict__.items(): | |
if k.startswith('_'): | |
continue | |
setattr(widget, k, v) | |
widget.save() |
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 django.http import HttpResponseRedirect | |
class SecureRequiredMiddleware(object): | |
def process_response(self, request, response): | |
""" | |
Ensures that any non decorated secure_required urls redirect if accessed | |
via https (only GET requests returning 200's are redirected to HTTP urls) | |
""" | |
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 django.conf import settings | |
from django.http import HttpResponseRedirect | |
def secure_required(func): | |
""" | |
Decorator makes sure URL is accessed over https. | |
Use with `SecureRequiredMiddleware` to ensure only decorated urls are | |
accessed via https | |
""" | |
def wrap(request, *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 sys | |
class ResultPlugin(object): | |
""" | |
Captures the TestResult object for later inspection. | |
nose doesn't return the full test result object from any of its runner | |
methods. Pass an instance of this plugin to the TestProgram and use | |
``result`` after running the tests to get the TestResult object. | |
""" |
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
diff --git a/README.md b/README.md | |
index 713bf92..6747aaa 100644 | |
--- a/README.md | |
+++ b/README.md | |
@@ -5,7 +5,7 @@ monocle straightens out event-driven code using Python's generators. | |
It aims to be portable between event-driven I/O frameworks, and | |
currently supports Twisted and Tornado. | |
-It's for Python 2.5 and up; the syntax it uses isn't supported | |
+It's for Python 2.5 and up (pre 2.7 builds require orderedict); the syntax it uses isn't supported |
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
""" | |
Using Jinja2 with Django 1.2 | |
Based on: http://djangosnippets.org/snippets/2063/ | |
To use: | |
* Add this template loader to settings: `TEMPLATE_LOADERS` | |
* Add template dirs to settings: `JINJA2_TEMPLATE_DIRS` | |
If in template debug mode - we fire the template rendered signal, which allows | |
debugging the context with the debug toolbar. Viewing source currently doesnt |
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 django.contrib.auth import SESSION_KEY, BACKEND_SESSION_KEY, load_backend | |
from users.models import AnonymousUser | |
def get_user(request): | |
try: | |
user_id = request.session[SESSION_KEY] | |
backend_path = request.session[BACKEND_SESSION_KEY] | |
backend = load_backend(backend_path) | |
user = backend.get_user(user_id) or AnonymousUser() | |
except KeyError: |
NewerOlder