Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Commit

Permalink
Remove sets package
Browse files Browse the repository at this point in the history
Fix #184

Signed-off-by: Byron Ruth <b@devel.io>
  • Loading branch information
bruth committed Jan 16, 2015
1 parent adcd3a8 commit 9da909f
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 138 deletions.
18 changes: 0 additions & 18 deletions avocado/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,30 +149,12 @@ def test_install(self):
return False


class Objectset(Dependency):
"""django-objectset provides a set-like abstract model for Django and
makes it trivial to creates sets of objects using common set operations.
Install by doing `pip install django-objectset`. Define models that
subclass `objectset.models.ObjectSet`.
"""

name = 'objectset'

def test_install(self):
try:
import objectset # noqa
except ImportError:
return False


# Keep track of the officially supported apps and libraries used for various
# features.
OPTIONAL_DEPS = {
'haystack': Haystack(),
'openpyxl': Openpyxl(),
'guardian': Guardian(),
'objectset': Objectset(),
}


Expand Down
51 changes: 13 additions & 38 deletions avocado/management/subcommands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.db.models import get_model, get_models, get_app, AutoField, \
ForeignKey, OneToOneField, ManyToManyField, FieldDoesNotExist
from django.core.management.base import BaseCommand
from avocado.conf import dep_supported
from avocado.models import DataField, DataConcept, DataCategory
from avocado.core import utils

Expand Down Expand Up @@ -129,21 +128,10 @@ def handle(self, *args, **options):
pending_models.extend(get_models(app))

for model in pending_models:
if dep_supported('objectset'):
from objectset.models import ObjectSet
is_objectset = issubclass(model, ObjectSet)
else:
is_objectset = False

model_name = model._meta.object_name.lower()

if is_objectset:
pk = model._meta.pk
pk.verbose_name = model._meta.verbose_name
pending_fields.append((pk, model_name, app_name))
else:
for field in model._meta.fields:
pending_fields.append((field, model_name, app_name))
for field in model._meta.fields:
pending_fields.append((field, model_name, app_name))

added = 0
updated = 0
Expand Down Expand Up @@ -181,26 +169,18 @@ def handle_field(self, field, model_name, app_name, **options):
if isinstance(field, ManyToManyField):
return

if dep_supported('objectset'):
from objectset.models import ObjectSet
is_objectset = issubclass(field.model, ObjectSet)
else:
is_objectset = False

# ObjectSets are represented by their primary key, so these may pass
if not is_objectset:
# Check for primary key, and foreign key fields
if isinstance(field, self.key_field_types) and not include_keys:
print(u'({0}) {1}.{2} is a primary or foreign key. Skipping...'
.format(app_name, model_name, field.name))
return
# Check for primary key, and foreign key fields
if isinstance(field, self.key_field_types) and not include_keys:
print(u'({0}) {1}.{2} is a primary or foreign key. Skipping...'
.format(app_name, model_name, field.name))
return

# Ignore non-editable fields since in most cases they are for
# managment purposes
if not field.editable and not include_non_editable:
print(u'({0}) {1}.{2} is not editable. Skipping...'
.format(app_name, model_name, field.name))
return
# Ignore non-editable fields since in most cases they are for
# managment purposes
if not field.editable and not include_non_editable:
print(u'({0}) {1}.{2} is not editable. Skipping...'
.format(app_name, model_name, field.name))
return

# All but the field name is case-insensitive, do initial lookup
# to see if it already exists, skip if it does
Expand All @@ -218,11 +198,6 @@ def handle_field(self, field, model_name, app_name, **options):
'field_name': field.name,
}

if is_objectset and hasattr(field.model, 'label_field'):
kwargs.update({
'label_field_name': field.model.label_field
})

try:
f = DataField.objects.get(**lookup)
except DataField.DoesNotExist:
Expand Down
246 changes: 246 additions & 0 deletions avocado/migrations/0042_migrate_objectset_fields.py

Large diffs are not rendered by default.

38 changes: 1 addition & 37 deletions avocado/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from avocado.core.models import Base, BasePlural, PublishArchiveMixin
from avocado.core.cache import post_save_cache, pre_delete_uncache, \
cached_method
from avocado.conf import settings, dep_supported
from avocado.conf import settings
from avocado import managers, history
from avocado.query.models import AbstractDataView, AbstractDataContext, \
AbstractDataQuery
Expand All @@ -32,24 +32,6 @@
log = logging.getLogger(__name__)


def is_objectset(f):
"""Returns true if the model is a subclass of ObjectSet and this
is the pk field. All other fields on the class are treated as
normal datafields.
"""
warn('ObjectSet detection in the DataField API is deprecated and '
'will be removed in 2.4. Set the alternate fields explicitly '
'on the field instance', DeprecationWarning)

if dep_supported('objectset'):
from objectset.models import ObjectSet

return f.model and issubclass(f.model, ObjectSet) \
and f.field == f.model._meta.pk

return False


class DataCategory(Base, PublishArchiveMixin):
"A high-level organization for data concepts."
# A reference to a parent for hierarchical categories
Expand Down Expand Up @@ -249,21 +231,8 @@ def model(self):
@property
def field(self):
"Returns the field object this datafield represents."
model = self.model

if model:
if dep_supported('objectset'):
from objectset.models import ObjectSet

if issubclass(model, ObjectSet):
return model._meta.pk

return self.real_field

@property
def objectset(self):
return is_objectset(self)

@property
def value_field_name(self):
"Alias for field name."
Expand All @@ -284,11 +253,6 @@ def label_field(self):

if self.label_field_name:
field_name = self.label_field_name
elif is_objectset(self):
if hasattr(self.model, 'label_field'):
field_name = self.model.label_field
else:
field_name = 'pk'

if field_name:
try:
Expand Down
Empty file removed avocado/sets/__init__.py
Empty file.
13 changes: 0 additions & 13 deletions avocado/sets/models.py

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ South>=0.8.1
Whoosh==2.4.1
django-guardian>=1.0.4
django-haystack==2.0.0
django-objectset>=0.2.2
jsonfield>=0.9.4
modeltree>=1.1.9
openpyxl>=1.6,<1.7
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
'whoosh==2.4.1',
'openpyxl>=1.6,<1.7',
'python-memcached>=1.48',
'django-objectset>=0.2.2',
],

# Optional dependencies
Expand Down
1 change: 0 additions & 1 deletion test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'history',
'models',
'query',
'sets',
'stats',
'search',
'subcommands',
Expand Down
Empty file removed tests/cases/sets/__init__.py
Empty file.
Empty file removed tests/cases/sets/models.py
Empty file.
28 changes: 0 additions & 28 deletions tests/cases/sets/tests.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
'tests.cases.history',
'tests.cases.models',
'tests.cases.query',
'tests.cases.sets',
'tests.cases.search',
'tests.cases.stats',
'tests.cases.subcommands',
Expand Down

0 comments on commit 9da909f

Please sign in to comment.