Skip to content

Commit

Permalink
Merge pull request #107 from djangonauts/django-1.8
Browse files Browse the repository at this point in the history
Added support for Django 1.8
  • Loading branch information
nemesifier committed Jun 7, 2015
2 parents b31f891 + f9462a0 commit 355388c
Show file tree
Hide file tree
Showing 43 changed files with 181 additions and 111 deletions.
Empty file modified .coveragerc
100755 → 100644
Empty file.
Empty file modified .gitignore
100755 → 100644
Empty file.
Empty file modified .landscape.yml
100755 → 100644
Empty file.
4 changes: 3 additions & 1 deletion .travis.yml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ python:
- "2.6"

env:
- DJANGO="django==1.8"
- DJANGO="django==1.7.7"
- DJANGO="django==1.6.11"
- DJANGO="django==1.5.12"

matrix:
exclude:
- python: "2.6"
env: DJANGO="django==1.7.7"
- python: "2.6"
env: DJANGO="django==1.8"

branches:
only:
Expand Down
Empty file modified AUTHORS
100755 → 100644
Empty file.
Empty file modified CONTRIBUTING.rst
100755 → 100644
Empty file.
Empty file modified LICENSE
100755 → 100644
Empty file.
Empty file modified README.rst
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion django_hstore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (1, 3, 8, 'final')
VERSION = (1, 4, 0, 'alpha')
__version__ = VERSION


Expand Down
8 changes: 4 additions & 4 deletions django_hstore/apps.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,15 @@ def attach_handler(self, func, vendor=None, unique=False):
def register_hstore_handler(connection, **kwargs):
# do not register hstore if DB is not postgres
# do not register if HAS_HSTORE flag is set to false

if connection.vendor != 'postgresql' or \
connection.settings_dict.get('HAS_HSTORE', True) is False:
return

# if the ``NAME`` of the database in the connection settings is ``None``
# defer hstore registration by setting up a new unique handler
if connection.settings_dict['NAME'] is None:
connection_handler.attach_handler(register_hstore_handler,
vendor="postgresql", unique=HSTORE_REGISTER_GLOBALLY)
vendor="postgresql",
unique=HSTORE_REGISTER_GLOBALLY)
return

if sys.version_info[0] < 3:
Expand All @@ -92,7 +91,8 @@ def register_hstore_handler(connection, **kwargs):


connection_handler.attach_handler(register_hstore_handler,
vendor="postgresql", unique=HSTORE_REGISTER_GLOBALLY)
vendor="postgresql",
unique=HSTORE_REGISTER_GLOBALLY)


class HStoreConfig(AppConfig):
Expand Down
Empty file modified django_hstore/compat.py
100755 → 100644
Empty file.
Empty file modified django_hstore/descriptors.py
100755 → 100644
Empty file.
Empty file modified django_hstore/dict.py
100755 → 100644
Empty file.
Empty file modified django_hstore/exceptions.py
100755 → 100644
Empty file.
23 changes: 18 additions & 5 deletions django_hstore/fields.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,30 @@ def _remove_hstore_virtual_fields(self):
for field_name in cls._hstore_virtual_fields.keys():
delattr(cls, field_name)
delattr(cls, '_hstore_virtual_fields')
# remove all hstore virtual fields from meta
for meta_fields in ['fields', 'local_fields', 'virtual_fields']:
# django >= 1.8
if get_version()[0:3] >= '1.8':
# remove all hstore virtual fields from meta
hstore_fields = []
# get all the existing hstore virtual fields
for field in getattr(cls._meta, meta_fields):
for field in getattr(cls._meta, 'virtual_fields'):
if hasattr(field, 'hstore_field_name'):
hstore_fields.append(field)
# remove from meta
for field in hstore_fields:
getattr(cls._meta, meta_fields).remove(field)
getattr(cls._meta, 'virtual_fields').remove(field)
# django <= 1.7
# TODO: will be removed in future versions
else:
# remove all hstore virtual fields from meta
for meta_fields in ['fields', 'local_fields', 'virtual_fields']:
hstore_fields = []
# get all the existing hstore virtual fields
for field in getattr(cls._meta, meta_fields):
if hasattr(field, 'hstore_field_name'):
hstore_fields.append(field)
# remove from meta
for field in hstore_fields:
getattr(cls._meta, meta_fields).remove(field)


class ReferencesField(HStoreField):
Expand Down Expand Up @@ -236,7 +250,6 @@ def _value_to_python(self, value):


class SerializedDictionaryField(HStoreField):

description = _("A python dictionary in a postgresql hstore field.")

def __init__(self, serializer=json.dumps, deserializer=json.loads, *args, **kwargs):
Expand Down
Empty file modified django_hstore/forms.py
100755 → 100644
Empty file.
Empty file modified django_hstore/hstore.py
100755 → 100644
Empty file.
23 changes: 12 additions & 11 deletions django_hstore/lookups.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class HStoreComparisonLookupMixin(HStoreLookupMixin):
Mixin for hstore comparison custom lookups.
"""

def as_postgresql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
def as_postgresql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
if len(rhs_params) == 1 and isinstance(rhs_params[0], dict):
param = rhs_params[0]
sign = (self.lookup_name[0] == 'g' and '>%s' or '<%s') % (self.lookup_name[-1] == 'e' and '=' or '')
Expand Down Expand Up @@ -75,8 +75,8 @@ class HStoreLessThanOrEqual(HStoreComparisonLookupMixin, LessThanOrEqual):

class HStoreContains(HStoreLookupMixin, Contains):

def as_postgresql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
def as_postgresql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
# FIXME: ::text cast is added by ``django.db.backends.postgresql_psycopg2.DatabaseOperations.lookup_cast``;
# maybe there's a cleaner way to fix the cast for hstore columns
if lhs.endswith('::text'):
Expand Down Expand Up @@ -105,15 +105,16 @@ def as_postgresql(self, qn, connection):
# if looking for a string perform the normal text lookup
# that is: look for occurence of string in all the keys
pass
elif hasattr(self.lhs.source, 'serializer'):
# needed for SerializedDictionaryField
elif hasattr(self.lhs.target, 'serializer'):
try:
self.lhs.source._serialize_value(param)
self.lhs.target._serialize_value(param)
pass
except Exception:
raise ValueError('invalid value')
else:
raise ValueError('invalid value')
return super(HStoreContains, self).as_sql(qn, connection)
return super(HStoreContains, self).as_sql(compiler, connection)


class HStoreIContains(IContains, HStoreContains):
Expand All @@ -122,8 +123,8 @@ class HStoreIContains(IContains, HStoreContains):

class HStoreIsNull(IsNull):

def as_postgresql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
def as_postgresql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)

if isinstance(self.rhs, dict):
param = self.rhs
Expand All @@ -136,4 +137,4 @@ def as_postgresql(self, qn, connection):

return (" AND ".join(conditions), lhs_params)

return super(HStoreIsNull, self).as_sql(qn, connection)
return super(HStoreIsNull, self).as_sql(compiler, connection)
Empty file modified django_hstore/managers.py
100755 → 100644
Empty file.
Empty file modified django_hstore/models.py
100755 → 100644
Empty file.
69 changes: 29 additions & 40 deletions django_hstore/query.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,8 @@ def updater(self, *args, **params):
self._for_write = True
query = method(self, self.query.clone(UpdateQuery), *args, **params)
forced_managed = False
# django >= 1.6
if VERSION[:2] >= (1, 6):
with transaction.atomic(using=self.db):
rows = query.get_compiler(self.db).execute_sql(None)
# django <= 1.5 - TODO: remove soon
else:
if not transaction.is_managed(using=self.db):
transaction.enter_transaction_management(using=self.db)
forced_managed = True
try:
rows = query.get_compiler(self.db).execute_sql(None)
if forced_managed:
transaction.commit(using=self.db)
else:
transaction.commit_unless_managed(using=self.db)
finally:
if forced_managed:
transaction.leave_transaction_management(using=self.db)
with transaction.atomic(using=self.db):
rows = query.get_compiler(self.db).execute_sql(None)
self._result_cache = None
return rows
updater.alters_data = True
Expand Down Expand Up @@ -87,7 +71,7 @@ def add(self, data, *args, **kwargs):
# FIXME: this method shuld be more clear.
def make_atom(self, child, qn, connection):
lvalue, lookup_type, value_annot, param = child
kwargs = {'connection': connection} if VERSION[:2] >= (1, 3) else {}
kwargs = {'connection': connection}

if lvalue and lvalue.field and hasattr(lvalue.field, 'db_type') and lvalue.field.db_type(**kwargs) == 'hstore':
try:
Expand Down Expand Up @@ -225,24 +209,29 @@ def hupdate(self, query, attr, updates):

if GEODJANGO_INSTALLED:
from django.contrib.gis.db.models.query import GeoQuerySet
from django.contrib.gis.db.models.sql.query import GeoQuery
from django.contrib.gis.db.models.sql.where import GeoWhereNode, GeoConstraint

class HStoreGeoWhereNode(HStoreWhereNode, GeoWhereNode):
def make_atom(self, child, qn, connection):
lvalue, lookup_type, value_annot, params_or_value = child
# if spatial query
if isinstance(lvalue, GeoConstraint):
return GeoWhereNode.make_atom(self, child, qn, connection)
# else might be an HSTORE query
return HStoreWhereNode.make_atom(self, child, qn, connection)

class HStoreGeoQuery(GeoQuery, Query):
def __init__(self, *args, **kwargs):
model = kwargs.pop('model', None) or args[0]
super(HStoreGeoQuery, self).__init__(model, HStoreGeoWhereNode)

class HStoreGeoQuerySet(HStoreQuerySet, GeoQuerySet):
def __init__(self, model=None, query=None, using=None, **kwargs):
query = query or HStoreGeoQuery(model)
super(HStoreGeoQuerySet, self).__init__(model=model, query=query, using=using, **kwargs)

if VERSION[:2] <= (1, 7):
from django.contrib.gis.db.models.sql.query import GeoQuery
from django.contrib.gis.db.models.sql.where import GeoWhereNode, GeoConstraint

class HStoreGeoWhereNode(HStoreWhereNode, GeoWhereNode):
def make_atom(self, child, qn, connection):
lvalue, lookup_type, value_annot, params_or_value = child
# if spatial query
if isinstance(lvalue, GeoConstraint):
return GeoWhereNode.make_atom(self, child, qn, connection)
# else might be an HSTORE query
return HStoreWhereNode.make_atom(self, child, qn, connection)

class HStoreGeoQuery(GeoQuery, Query):
def __init__(self, *args, **kwargs):
model = kwargs.pop('model', None) or args[0]
super(HStoreGeoQuery, self).__init__(model, HStoreGeoWhereNode)

class HStoreGeoQuerySet(HStoreQuerySet, GeoQuerySet):
def __init__(self, model=None, query=None, using=None, **kwargs):
query = query or HStoreGeoQuery(model)
super(HStoreGeoQuerySet, self).__init__(model=model, query=query, using=using, **kwargs)
else:
class HStoreGeoQuerySet(HStoreQuerySet, GeoQuerySet):
pass
Empty file modified django_hstore/static/admin/js/django_hstore/hstore-widget.js
100755 → 100644
Empty file.
Empty file modified django_hstore/static/admin/js/django_hstore/underscore-min.js
100755 → 100644
Empty file.
Empty file modified django_hstore/templates/hstore_default_widget.html
100755 → 100644
Empty file.
Empty file modified django_hstore/templates/hstore_grappelli_widget.html
100755 → 100644
Empty file.
Empty file modified django_hstore/utils.py
100755 → 100644
Empty file.
2 changes: 2 additions & 0 deletions django_hstore/virtual.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class HStoreVirtualMixin(object):
"""
must be mixed-in with django fields
"""
concrete = False

def contribute_to_class(self, cls, name):
if self.choices:
setattr(cls, 'get_%s_display' % self.name,
Expand Down
Empty file modified django_hstore/widgets.py
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion doc/doc.asciidoc
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Requirements
^^^^^^^^^^^^

- Python 2.6, 2.7 or 3.3+
- Django 1.5, 1.6 and 1.7
- Django 1.6, 1.7 and 1.8
- Psycopg2 2.4.3+
- PostgreSQL 9.0+
Expand Down
Empty file modified doc/images/deafult-admin-widget-raw.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified doc/images/deafult-admin-widget.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified doc/images/hstore-widget-raw.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified doc/images/hstore-widget.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified requirements.txt
100755 → 100644
Empty file.
Empty file modified setup.cfg
100755 → 100644
Empty file.
Empty file modified tests/__init__.py
100755 → 100644
Empty file.
Empty file modified tests/django_hstore_tests/admin.py
100755 → 100644
Empty file.
Empty file modified tests/django_hstore_tests/models.py
100755 → 100644
Empty file.
Loading

0 comments on commit 355388c

Please sign in to comment.