Skip to content

Commit

Permalink
Updated to latest django-nonrel wkornewald version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Paro committed Oct 11, 2010
1 parent 1e1334d commit 992c10e
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 425 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Waldemar Kornewald
Alberto Paro (Setuptools)
Jonas Haag (patches)
11 changes: 0 additions & 11 deletions djangotoolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +0,0 @@
__author__ = 'Waldemar Kornewald - Flavio Percoco Premoli - Alberto Paro'

VERSION = (0, 0, 1)

def get_version():
version = '%s.%s' % (VERSION[0], VERSION[1])
if VERSION[2]:
version = '%s.%s' % (version, VERSION[2])
return version

__version__ = get_version()
10 changes: 7 additions & 3 deletions djangotoolbox/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User, Group


class UserForm(forms.ModelForm):
class Meta:
model = User
fields = ('username', 'email', 'first_name', 'last_name', 'is_active',
'is_staff', 'is_superuser')


class CustomUserAdmin(UserAdmin):
fieldsets = None
form = UserForm
fieldsets = None
form = UserForm


admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.register(User, CustomUserAdmin)
admin.site.register(User, CustomUserAdmin)

4 changes: 4 additions & 0 deletions djangotoolbox/db/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, connection):
distinguishes_insert_from_update = False
supports_deleting_related_objects = False
string_based_auto_field = False
supports_dicts = False

class NonrelDatabaseOperations(BaseDatabaseOperations):
def __init__(self, connection):
Expand All @@ -37,6 +38,9 @@ def value_to_db_time(self, value):
def prep_for_like_query(self, value):
return value

def prep_for_iexact_query(self, value):
return value

def check_aggregate_support(self, aggregate):
# TODO: Only COUNT(*) should be supported, by default.
# Raise NotImplementedError in all other cases.
Expand Down
61 changes: 37 additions & 24 deletions djangotoolbox/db/basecompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.db.models.sql import aggregates as sqlaggregates
from django.db.models.sql.compiler import SQLCompiler
from django.db.models.sql.constants import LOOKUP_SEP, MULTI, SINGLE
from django.db.models.sql.where import AND, OR
from django.db.models.sql.where import AND, OR, Constraint
from django.db.utils import DatabaseError, IntegrityError
from django.utils.tree import Node
import random
Expand Down Expand Up @@ -85,6 +85,9 @@ def _decode_child(self, child):
constraint, lookup_type, annotation, value = child
packed, value = constraint.process(lookup_type, value, self.connection)
alias, column, db_type = packed
if alias and alias != self.query.model._meta.db_table:
raise DatabaseError("This database doesn't support JOINs "
"and multi-table inheritance.")
value = self._normalize_lookup_value(value, annotation, lookup_type)
return column, lookup_type, db_type, value

Expand Down Expand Up @@ -121,11 +124,10 @@ def _get_children(self, children):
# not necessary with emulated negation handling code
result = []
for child in children:
if isinstance(child, Node) and child.negated and \
len(child.children) == 1 and \
isinstance(child.children[0], tuple):
node, lookup_type, annotation, value = child.children[0]
if lookup_type == 'isnull' and value == True and node.field is None:
if isinstance(child, tuple):
constraint = child[0]
lookup_type = child[1]
if lookup_type == 'isnull' and constraint.field is None:
continue
result.append(child)
return result
Expand All @@ -144,6 +146,9 @@ def _matches_filters(self, entity, filters):
constraint, lookup_type, annotation, value = child
packed, value = constraint.process(lookup_type, value, self.connection)
alias, column, db_type = packed
if alias != self.query.model._meta.db_table:
raise DatabaseError("This database doesn't support JOINs "
"and multi-table inheritance.")

# Django fields always return a list (see Field.get_db_prep_lookup)
# except if get_db_prep_lookup got overridden by a subclass
Expand Down Expand Up @@ -206,29 +211,13 @@ def results_iter(self):
"""
Returns an iterator over the results from executing this query.
"""
self.check_query()
fields = self.get_fields()
low_mark = self.query.low_mark
high_mark = self.query.high_mark
for entity in self.build_query(fields).fetch(low_mark, high_mark):
yield self._make_result(entity, fields)

def _make_result(self, entity, fields):
result = []
for field in fields:
if not field.null and entity.get(field.column,
field.get_default()) is None:
typename = type(field).__name__
if typename == "DictField":
result.append({})
continue
if typename == "ListField":
result.append([])
continue
raise DatabaseError("Non-nullable field %s can't be None!" % field.name)
result.append(self.convert_value_from_db(field.db_type(
connection=self.connection), entity.get(field.column, field.get_default())))
return result

def has_results(self):
return self.get_count(check_exists=True)

Expand All @@ -254,6 +243,21 @@ def execute_sql(self, result_type=MULTI):
# ----------------------------------------------
# Additional NonrelCompiler API
# ----------------------------------------------
def _make_result(self, entity, fields):
result = []
for field in fields:
if not field.null and entity.get(field.column,
field.get_default()) is None:
raise DatabaseError("Non-nullable field %s can't be None!" % field.name)
result.append(self.convert_value_from_db(field.db_type(
connection=self.connection), entity.get(field.column, field.get_default())))
return result

def check_query(self):
if (len([a for a in self.query.alias_map if self.query.alias_refcount[a]]) > 1
or self.query.distinct or self.query.extra or self.query.having):
raise DatabaseError('This query is not supported by the database.')

def get_count(self, check_exists=False):
"""
Counts matches using the current filter constraints.
Expand All @@ -278,7 +282,7 @@ def build_query(self, fields=None):

def get_fields(self):
"""
Returns the fields which should get loaded from the backend by self.query
Returns the fields which should get loaded from the backend by self.query
"""
# We only set this up here because
# related_select_fields isn't populated until
Expand All @@ -294,6 +298,15 @@ def get_fields(self):
db_table = self.query.model._meta.db_table
fields = [f for f in fields if db_table in only_load and
f.column in only_load[db_table]]

query_model = self.query.model
if query_model._meta.proxy:
query_model = query_model._meta.proxy_for_model

for field in fields:
if field.model._meta != query_model._meta:
raise DatabaseError('Multi-table inheritance is not supported '
'by non-relational DBs.')
return fields

def _get_ordering(self):
Expand Down
36 changes: 19 additions & 17 deletions djangotoolbox/db/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@

class NonrelDatabaseCreation(BaseDatabaseCreation):
data_types = {
'DateTimeField': 'datetime',
'DateField': 'date',
'TimeField': 'time',
'FloatField': 'float',
'EmailField': 'text',
'URLField': 'text',
'AutoField': 'integer',
'BigIntegerField': 'long',
'BooleanField': 'bool',
'NullBooleanField': 'bool',
'CharField': 'text',
'CommaSeparatedIntegerField': 'text',
'IPAddressField': 'text',
'SlugField': 'text',
'DateField': 'date',
'DateTimeField': 'datetime',
'DecimalField': 'decimal:%(max_digits)s,%(decimal_places)s',
'EmailField': 'text',
'FileField': 'text',
'FilePathField': 'text',
'TextField': 'longtext',
'XMLField': 'longtext',
'FloatField': 'float',
'ImageField': 'text',
'IntegerField': 'integer',
'SmallIntegerField': 'integer',
'IPAddressField': 'text',
'NullBooleanField': 'bool',
'OneToOneField': 'integer',
'PositiveIntegerField': 'integer',
'PositiveSmallIntegerField': 'integer',
'BigIntegerField': 'long',
'AutoField': 'integer',
'OneToOneField': 'integer',
'DecimalField': 'decimal:%(max_digits)s,%(decimal_places)s',
'SlugField': 'text',
'SmallIntegerField': 'integer',
'TextField': 'longtext',
'TimeField': 'time',
'URLField': 'text',
'XMLField': 'longtext',

'BlobField': 'blob',
# 'ImageField':
'RawField': 'raw',
}
Empty file removed djangotoolbox/dbproxy/__init__.py
Empty file.
13 changes: 0 additions & 13 deletions djangotoolbox/dbproxy/base.py

This file was deleted.

35 changes: 0 additions & 35 deletions djangotoolbox/dbproxy/compiler.py

This file was deleted.

Loading

0 comments on commit 992c10e

Please sign in to comment.