Skip to content

Instantly share code, notes, and snippets.

Bruno Alla browniebroke

Block or report user

Report or block browniebroke

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View custom_celery_task.py
"""
Custom Celery task for providing useful extensions
http://docs.celeryproject.org/en/latest/userguide/tasks.html#custom-task-classes
"""
from celery.app.task import Task
from django.db import transaction
class BetterCeleryTask(Task):
"""Extend the default Task class to add helpers with Django's on_commit()."""
@browniebroke
browniebroke / MultiLocationField.py
Last active Jun 29, 2016 — forked from rfj001/MultiLocationField.py
MultiLocationField for django-haystack
View MultiLocationField.py
import six
from django.contrib.gis.geos import Point
from haystack import indexes
from haystack.exceptions import SpatialError
from haystack.utils.geo import ensure_geometry, ensure_point
def ensure_multipoint(geom):
"""
Makes sure the parameter passed in looks like a GEOS ``MultiPoint``.
@browniebroke
browniebroke / test_admin.py
Last active Aug 29, 2015
Basic test of the Django admin views yours installed apps: simple GET on the list view, add view and list seacrh
View test_admin.py
from django.contrib import admin
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db.models import get_models
from django.test import TestCase
class TestAdminViews(TestCase):
def setUp(self):
username = "test"
@browniebroke
browniebroke / model_stat_helper.py
Last active Aug 29, 2015
Django: Group model & count by date
View model_stat_helper.py
"""
Generic method (disclaimer: I did not consider any security concerns) to get stats
on a model in Django.
Created from http://stackoverflow.com/questions/8746014/django-group-sales-by-month
"""
from django.db import connection
from django.db.models import Sum, Count
def truncate_date_model(model, period_length, date_field, criteria=None, pk='pk'):
@browniebroke
browniebroke / circle.yml
Last active Aug 29, 2015
YAML Install postgres 9.1 with postgis on CircleCI
View circle.yml
database:
# Use postgres 9.1
pre:
- sudo service postgresql stop && sudo apt-get remove -y postgresql-9.3 && sudo apt-get update && sudo apt-get install -y postgresql-9.1 postgresql-contrib-9.1 postgresql-9.1-postgis-2.1
- sudo sed -i "s/\port = 5433/port = 5432/" /etc/postgresql/9.1/main/postgresql.conf
- sudo cp /etc/postgresql/9.3/main/pg_hba.conf /etc/postgresql/9.1/main/pg_hba.conf
- sudo service postgresql restart
- sudo -u postgres createuser ubuntu -d --superuser
- createdb circle_test
You can’t perform that action at this time.