diff --git a/avocado/conf/__init__.py b/avocado/conf/__init__.py index 6fd28e3..750e30d 100644 --- a/avocado/conf/__init__.py +++ b/avocado/conf/__init__.py @@ -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(), } diff --git a/avocado/management/subcommands/init.py b/avocado/management/subcommands/init.py index 339858c..e7e7548 100644 --- a/avocado/management/subcommands/init.py +++ b/avocado/management/subcommands/init.py @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/avocado/migrations/0042_migrate_objectset_fields.py b/avocado/migrations/0042_migrate_objectset_fields.py new file mode 100644 index 0000000..6864dbf --- /dev/null +++ b/avocado/migrations/0042_migrate_objectset_fields.py @@ -0,0 +1,246 @@ +# -*- coding: utf-8 -*- +from south.utils import datetime_utils as datetime +from south.db import db +from south.v2 import DataMigration +from django.db import models +from django.db.models.fields import FieldDoesNotExist +try: + from objectset.models import ObjectSet +except ImportError: + ObjectSet = None + + +def is_objectset(f): + model = models.get_model(f.app_name, f.model_name) + + if not model or not issubclass(model, ObjectSet): + return + + try: + model_field = model._meta.get_field(f.field_name) + except FieldDoesNotExist: + return + + if model_field == model._meta.pk: + return True + + + +class Migration(DataMigration): + def forwards(self, orm): + # Skip if objectset library is not installed + if not ObjectSet: + return + + for f in orm.DataField.objects.all(): + if not is_objectset(f): + continue + + model = models.get(f.app_name, f.model_name) + + if not f.label_field_name and hasattr(model, 'label_field'): + f.label_field_name = model.label_field + f.save() + + def backwards(self, orm): + pass + + models = { + u'auth.group': { + 'Meta': {'object_name': 'Group'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'auth.permission': { + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + u'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + u'avocado.datacategory': { + 'Meta': {'ordering': "('parent__order', 'parent__name', 'order', 'name')", 'object_name': 'DataCategory'}, + 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'keywords': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'order': ('django.db.models.fields.FloatField', [], {'null': 'True', 'db_column': "'_order'", 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': u"orm['avocado.DataCategory']"}), + 'published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}) + }, + 'avocado.dataconcept': { + 'Meta': {'ordering': "('category__order', 'category__name', 'order', 'name')", 'object_name': 'DataConcept'}, + 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['avocado.DataCategory']", 'null': 'True', 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'fields': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'concepts'", 'symmetrical': 'False', 'through': u"orm['avocado.DataConceptField']", 'to': u"orm['avocado.DataField']"}), + 'formatter': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'indexable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'keywords': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'name_plural': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'order': ('django.db.models.fields.FloatField', [], {'null': 'True', 'db_column': "'_order'", 'blank': 'True'}), + 'published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'queryable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'concepts+'", 'blank': 'True', 'to': u"orm['sites.Site']"}), + 'sortable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'viewable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}) + }, + u'avocado.dataconceptfield': { + 'Meta': {'ordering': "('order', 'name')", 'object_name': 'DataConceptField'}, + 'concept': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'concept_fields'", 'to': "orm['avocado.DataConcept']"}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'field': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'concept_fields'", 'to': u"orm['avocado.DataField']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'name_plural': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'order': ('django.db.models.fields.FloatField', [], {'null': 'True', 'db_column': "'_order'", 'blank': 'True'}) + }, + u'avocado.datacontext': { + 'Meta': {'object_name': 'DataContext'}, + 'accessed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2015, 1, 15, 0, 0)'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'json': ('jsonfield.fields.JSONField', [], {'default': '{}', 'null': 'True', 'blank': 'True'}), + 'keywords': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'forks'", 'null': 'True', 'to': u"orm['avocado.DataContext']"}), + 'session': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'datacontext+'", 'null': 'True', 'to': u"orm['auth.User']"}) + }, + u'avocado.datafield': { + 'Meta': {'ordering': "('category__order', 'category__name', 'order', 'name')", 'unique_together': "(('app_name', 'model_name', 'field_name'),)", 'object_name': 'DataField'}, + 'app_name': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'archived': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['avocado.DataCategory']", 'null': 'True', 'blank': 'True'}), + 'code_field_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'data_version': ('django.db.models.fields.IntegerField', [], {'default': '1'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + 'enumerable': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'field_name': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'indexable': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'keywords': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'label_field_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'model_name': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'name_plural': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'order': ('django.db.models.fields.FloatField', [], {'null': 'True', 'db_column': "'_order'", 'blank': 'True'}), + 'order_field_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'search_field_name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'fields+'", 'blank': 'True', 'to': u"orm['sites.Site']"}), + 'translator': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'unit': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'}), + 'unit_plural': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}) + }, + u'avocado.dataquery': { + 'Meta': {'object_name': 'DataQuery'}, + 'accessed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'context_json': ('jsonfield.fields.JSONField', [], {'default': '{}', 'null': 'True', 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'keywords': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'forks'", 'null': 'True', 'to': u"orm['avocado.DataQuery']"}), + 'public': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'session': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'shared_users': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'shareddataquery+'", 'symmetrical': 'False', 'to': u"orm['auth.User']"}), + 'template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'dataquery+'", 'null': 'True', 'to': u"orm['auth.User']"}), + 'view_json': ('jsonfield.fields.JSONField', [], {'default': '{}', 'null': 'True', 'blank': 'True'}) + }, + u'avocado.dataview': { + 'Meta': {'object_name': 'DataView'}, + 'accessed': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2015, 1, 15, 0, 0)'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'default': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'json': ('jsonfield.fields.JSONField', [], {'default': '{}', 'null': 'True', 'blank': 'True'}), + 'keywords': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), + 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'forks'", 'null': 'True', 'to': u"orm['avocado.DataView']"}), + 'session': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'template': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'dataview+'", 'null': 'True', 'to': u"orm['auth.User']"}) + }, + 'avocado.log': { + 'Meta': {'object_name': 'Log'}, + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']", 'null': 'True', 'blank': 'True'}), + 'data': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'event': ('django.db.models.fields.CharField', [], {'max_length': '200'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+'", 'null': 'True', 'to': u"orm['auth.User']"}) + }, + 'avocado.revision': { + 'Meta': {'ordering': "('-timestamp',)", 'object_name': 'Revision'}, + 'changes': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + 'data': ('jsonfield.fields.JSONField', [], {'null': 'True', 'blank': 'True'}), + 'deleted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), + 'session_key': ('django.db.models.fields.CharField', [], {'max_length': '40', 'null': 'True', 'blank': 'True'}), + 'timestamp': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now', 'db_index': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'+revision'", 'null': 'True', 'to': u"orm['auth.User']"}) + }, + u'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + }, + u'sites.site': { + 'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"}, + 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + } + } + + complete_apps = ['avocado'] + symmetrical = True diff --git a/avocado/models.py b/avocado/models.py index a742511..3198315 100644 --- a/avocado/models.py +++ b/avocado/models.py @@ -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 @@ -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 @@ -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." @@ -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: diff --git a/avocado/sets/__init__.py b/avocado/sets/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/avocado/sets/models.py b/avocado/sets/models.py deleted file mode 100644 index f6f2fba..0000000 --- a/avocado/sets/models.py +++ /dev/null @@ -1,13 +0,0 @@ -import warnings -from avocado.conf import dep_supported, raise_dep_error - -if not dep_supported('objectset'): - raise_dep_error('objectset') - -from objectset.models import ObjectSet, SetObject # noqa - -warnings.warn('The built-in ObjectSet and SetObject classes have been ' - 'removed in favor of the classes defined in the ' - 'django-objectset library. Imports should be changed to ' - 'import directly from objectset.models instead of from ' - 'avocado.sets.models') diff --git a/requirements.txt b/requirements.txt index 34934cd..c2691ec 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.py b/setup.py index 09295be..b619d73 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,6 @@ 'whoosh==2.4.1', 'openpyxl>=1.6,<1.7', 'python-memcached>=1.48', - 'django-objectset>=0.2.2', ], # Optional dependencies diff --git a/test_suite.py b/test_suite.py index 0a98017..7d0ec2f 100644 --- a/test_suite.py +++ b/test_suite.py @@ -16,7 +16,6 @@ 'history', 'models', 'query', - 'sets', 'stats', 'search', 'subcommands', diff --git a/tests/cases/sets/__init__.py b/tests/cases/sets/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/cases/sets/models.py b/tests/cases/sets/models.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/cases/sets/tests.py b/tests/cases/sets/tests.py deleted file mode 100644 index b024fa6..0000000 --- a/tests/cases/sets/tests.py +++ /dev/null @@ -1,28 +0,0 @@ -from django.test import TestCase -from avocado.models import DataField -from ...models import Record, RecordSet - - -class SetsTestCase(TestCase): - fixtures = ['sets.json'] - - def test_datafield_properties(self): - [RecordSet(name=u'Set {0}'.format(i)).save() for i in xrange(10)] - f = DataField(app_name='tests', model_name='recordset', - field_name='id') - self.assertEqual(list(f.values()), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) - self.assertEqual(list(f.labels()), ['Set 0', 'Set 1', 'Set 2', 'Set 3', - 'Set 4', 'Set 5', 'Set 6', 'Set 7', - 'Set 8', 'Set 9']) - - def test_translator(self): - s = RecordSet() - s.save() - objs = [Record(pk=i) for i in xrange(1, 11)] - s.bulk(objs) - - f = DataField(app_name='tests', model_name='recordset', - field_name='id') - trans = f.translate(value=s.pk, tree=Record) - self.assertEqual(unicode(trans['query_modifiers']['condition']), - "(AND: ('recordset__id__exact', 1))") diff --git a/tests/settings.py b/tests/settings.py index f1847d7..01a2125 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -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',