Skip to content

Instantly share code, notes, and snippets.

View jarshwah's full-sized avatar

Josh Smeaton jarshwah

View GitHub Profile
def _get_model(self):
DynamicClass = cache.get('DynamicModel_' + self.table_name)
if DynamicClass is None:
# get the custom columns required for this table..
attrs = dict((c.column_name, models.CharField(max_length=100, blank=True, null=True)) for c in self.custom_fields.all())
class Meta:
db_table = self.table_name
app_label = self._meta.app_label
managed = False
@jarshwah
jarshwah / django-test-suite-profile.txt
Created June 10, 2014 23:29
Cumulative profiling data from django test suite, with loaddata optimisations
This file has been truncated, but you can view the full file.
vagrant@djangocore:~$ PYTHONPATH=/django /home/vagrant/.virtualenvs/py2.7/bin/python -m cProfile -s cumulative /django/tests/runtests.py --settings=djangocore_test_postgresql
Testing against Django installed in '/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
..........................................................................................................................................................................................................................................................................................................................................................................x........................................................................................................................................................................................s..............................................................................................................................................................
@jarshwah
jarshwah / gist:35c367a4cf567c62b579
Created June 19, 2014 14:51
Django test output for resolve_columns
field=None value=1L
field=<django.db.models.fields.AutoField: id> value=u'159059725'
field=<django.db.models.fields.CharField: isbn> value=u'The Definitive Guide to Django: Web Development Done Right'
field=<django.db.models.fields.CharField: name> value=447L
field=<django.db.models.fields.IntegerField: pages> value=4.5
field=<django.db.models.fields.FloatField: rating> value=Decimal('30.00')
field=<django.db.models.fields.DecimalField: price> value=1L
field=<django.db.models.fields.related.ForeignKey: contact> value=1L
field=<django.db.models.fields.related.ForeignKey: publisher> value=datetime.date(2007, 12, 6)
field=<django.db.models.fields.DateField: pubdate> value=1L
@jarshwah
jarshwah / goal.py
Last active August 29, 2015 14:04
goal in python
def g(letters=None):
if letters: return 'gal'
goal = ['go']
def o(letters=None):
assert letters is None or letters == 'al'
if letters:
goal.append(letters)
return ''.join(goal)
goal.append('o')
return o
@jarshwah
jarshwah / output.txt
Created August 26, 2014 05:17
Profiling django tests with Oracle RAC
(django)[vagrant@peppermint django]$ ./runoracletests.py expressions
Testing against Django installed in '/django/django'
Creating test database for alias 'default'...
Creating test user...
Creating test database for alias 'other'...
Creating test user...
..s.................s..................
----------------------------------------------------------------------
Ran 39 tests in 386.525s
@jarshwah
jarshwah / backend.py
Last active August 29, 2015 14:11
Django Custom Auth Backend - if refactored
import base64
import hashlib
import hmac
import requests
import time
from django.contrib.auth import get_user_model
from django.conf import settings
from django.core.cache import cache
from django.utils.http import unquote
@jarshwah
jarshwah / func_as_transform.diff
Created December 20, 2014 08:44
Making func expressions into Transforms
diff --git django/db/models/functions.py django/db/models/functions.py
index c3dea1f..30046ea 100644
--- django/db/models/functions.py
+++ django/db/models/functions.py
@@ -2,7 +2,7 @@
Classes that represent database functions.
"""
from django.db.models.expressions import Func, Value
-from django.db.models import IntegerField
+from django.db.models import IntegerField, Transform
@jarshwah
jarshwah / update-djangocore-box
Last active August 29, 2015 14:12
Update djangocore-box VM to run py3.3 tests properly
sudo apt-get update
sudo apt-get install gcc libffi-dev vim
sudo apt-get install python3.3 python3.3-dev python3.3-minimal
workon py2.7
pip install -r /home/vagrant/.hosthome/Development/django/tests/requirements/py2.txt
deactivate
rm /home/vagrant/.virtualenvs/py3.3/bin/python
cd /home/vagrant/.virtualenvs/
mkvirtualenv py3.3 --python=`which python3.3`
workon py3.3
@jarshwah
jarshwah / case_expressions.diff
Last active August 29, 2015 14:12
Fixes problems with oracle, cast issues with postgres, and removes depending on the type of compiler
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 64b5ba0..8b69406 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -487,11 +487,7 @@ class Value(ExpressionNode):
def as_sql(self, compiler, connection):
val = self.value
if self._output_field_or_none is not None:
- from django.db.models.sql.compiler import SQLUpdateCompiler
- if isinstance(compiler, SQLUpdateCompiler):
@jarshwah
jarshwah / branch-oracle.sql
Created January 6, 2015 01:34
Compare queries
-- queries.tests.Queries1Tests.test_ticket2496
SELECT * FROM (
SELECT "_SUB".*,
ROWNUM AS "_RN" FROM (SELECT "QUERIES_ITEM"."ID",
"QUERIES_ITEM"."NAME",
"QUERIES_ITEM"."CREATED",
"QUERIES_ITEM"."MODIFIED",
"QUERIES_ITEM"."CREATOR_ID",
"QUERIES_ITEM"."NOTE_ID",
"QUERIES_AUTHOR"."ID",