Skip to content

Instantly share code, notes, and snippets.

View stefanfoulis's full-sized avatar

Stefan Foulis stefanfoulis

View GitHub Profile
"""
Collects as much information as possible from ENV for auto-configuration.
Individual items should actually be exported from here and integrated into heroku-buildpack-python
"""
from stefanfoulis.settings import *
import os
def sentry_config(default='', env='SENTRY_DSN'):
"""alter settings from SENTRY_DSN."""
return os.environ.get(env, default)
@stefanfoulis
stefanfoulis / chainable_manager.py
Created November 9, 2012 13:56 — forked from ojii/chainable_manager.py
Django Model Managers
from django.db import models
from django.db.models.query import QuerySet
class ChainableManager(models.Manager):
"""
A manager that allows chaining of all methods defined on it.
Example:
class MyManager(ChainableManager):
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/filer/folder/8/list/
Django Version: 1.6.dev20130123004615
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/filer/folder/
Django Version: 1.5c1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/cms/page/3/edit-plugin/27/
Django Version: 1.5c1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
@stefanfoulis
stefanfoulis / gist:5218064
Created March 22, 2013 00:34
Ugly as hell quick and dirty script to automatically add github notifications for a list of projects to hipchat and to create a room per project based on a naming convention.
# -*- coding: utf-8 -*-
import requests
import json
import pprint
from secrets import hipchat_api_key # the hipchat API key with admin rights
from secrets import github_credentials # a tuple for github access (github_username, password),
from secrets import hipchat_notification_api_key # the hipchat API key to use for the notification hooks on github
hipchat_apps_room_name = 'Divio Application Suite'
@stefanfoulis
stefanfoulis / gist:5352655
Created April 10, 2013 07:51
google places autocomplete widget limited to cities
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("maps", "3.x", {callback: initialize, other_params:'sensor=false&libraries=places'});
function initialize() {
var input = document.getElementById('id_location');
var autocomplete = new google.maps.places.Autocomplete(input, { types: ['(cities)'], region:'EU' });
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
@stefanfoulis
stefanfoulis / gist:5464012
Created April 25, 2013 23:13
super simple hacky multilingual
# -*- coding: utf-8 -*-
from django.utils.translation import get_language, activate, deactivate_all, deactivate
class LanguageFieldProxy(object):
def contribute_to_class(self, cls, name):
self.name = name
setattr(cls, self.name, self)
def __get__(self, instance, instance_type=None):
# -*- coding: utf-8 -*-
"""Refactor South migrations to use settings.AUTH_USER_MODEL.
Inserts a backwards-compatible code-snippet in all
your schema migration files and uses a possibly customized user
model as introduced in Django 1.5.
Please note that this has nothing to do with changing
settings.AUTH_USER_MODEL to a new model. If you do this, stuff
will very likely break in reusable apps that have their own
migration trees.