diff --git a/drip/admin.py b/drip/admin.py index 9c1d5a1..956e20e 100644 --- a/drip/admin.py +++ b/drip/admin.py @@ -8,7 +8,6 @@ from drip.drips import configured_message_classes, message_class_for from drip.utils import get_user_model - class QuerySetRuleInline(admin.TabularInline): model = QuerySetRule diff --git a/drip/migrations/0001_initial.py b/drip/migrations/0001_initial.py index 914041f..b582fde 100644 --- a/drip/migrations/0001_initial.py +++ b/drip/migrations/0001_initial.py @@ -1,128 +1,65 @@ # -*- coding: utf-8 -*- -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models +from __future__ import unicode_literals +from django.db import models, migrations +from django.conf import settings -class Migration(SchemaMigration): - def forwards(self, orm): - # Adding model 'Drip' - db.create_table('drip_drip', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), - ('lastchanged', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - ('name', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)), - ('enabled', self.gf('django.db.models.fields.BooleanField')(default=False)), - ('subject_template', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), - ('body_html_template', self.gf('django.db.models.fields.TextField')(null=True, blank=True)), - )) - db.send_create_signal('drip', ['Drip']) +class Migration(migrations.Migration): - # Adding model 'SentDrip' - db.create_table('drip_sentdrip', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), - ('drip', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sent_drips', to=orm['drip.Drip'])), - ('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='sent_drips', to=orm['auth.User'])), - ('subject', self.gf('django.db.models.fields.TextField')()), - ('body', self.gf('django.db.models.fields.TextField')()), - )) - db.send_create_signal('drip', ['SentDrip']) + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] - # Adding model 'QuerySetRule' - db.create_table('drip_querysetrule', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('date', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)), - ('lastchanged', self.gf('django.db.models.fields.DateTimeField')(auto_now=True, blank=True)), - ('drip', self.gf('django.db.models.fields.related.ForeignKey')(related_name='queryset_rules', to=orm['drip.Drip'])), - ('method_type', self.gf('django.db.models.fields.CharField')(default='filter', max_length=12)), - ('field_name', self.gf('django.db.models.fields.CharField')(max_length=128)), - ('lookup_type', self.gf('django.db.models.fields.CharField')(default='exact', max_length=12)), - ('field_value', self.gf('django.db.models.fields.CharField')(max_length=255)), - )) - db.send_create_signal('drip', ['QuerySetRule']) - - - def backwards(self, orm): - # Deleting model 'Drip' - db.delete_table('drip_drip') - - # Deleting model 'SentDrip' - db.delete_table('drip_sentdrip') - - # Deleting model 'QuerySetRule' - db.delete_table('drip_querysetrule') - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - '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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - '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': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - '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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - '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'}), - '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'}) - }, - 'drip.drip': { - 'Meta': {'object_name': 'Drip'}, - 'body_html_template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lastchanged': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), - 'subject_template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}) - }, - 'drip.querysetrule': { - 'Meta': {'object_name': 'QuerySetRule'}, - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'drip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'queryset_rules'", 'to': "orm['drip.Drip']"}), - 'field_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'field_value': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lastchanged': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'lookup_type': ('django.db.models.fields.CharField', [], {'default': "'exact'", 'max_length': '12'}), - 'method_type': ('django.db.models.fields.CharField', [], {'default': "'filter'", 'max_length': '12'}) - }, - 'drip.sentdrip': { - 'Meta': {'object_name': 'SentDrip'}, - 'body': ('django.db.models.fields.TextField', [], {}), - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'drip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_drips'", 'to': "orm['drip.Drip']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'subject': ('django.db.models.fields.TextField', [], {}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_drips'", 'to': "orm['auth.User']"}) - } - } - - complete_apps = ['drip'] + operations = [ + migrations.CreateModel( + name='Drip', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('date', models.DateTimeField(auto_now_add=True)), + ('lastchanged', models.DateTimeField(auto_now=True)), + ('name', models.CharField(help_text=b'A unique name for this drip.', unique=True, max_length=255, verbose_name=b'Drip Name')), + ('enabled', models.BooleanField(default=False)), + ('from_email', models.EmailField(help_text=b'Set a custom from email.', max_length=254, null=True, blank=True)), + ('from_email_name', models.CharField(help_text=b'Set a name for a custom from email.', max_length=150, null=True, blank=True)), + ('subject_template', models.TextField(null=True, blank=True)), + ('body_html_template', models.TextField(help_text=b'You will have settings and user in the context.', null=True, blank=True)), + ('message_class', models.CharField(default=b'default', max_length=120, blank=True)), + ], + options={ + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='QuerySetRule', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('date', models.DateTimeField(auto_now_add=True)), + ('lastchanged', models.DateTimeField(auto_now=True)), + ('method_type', models.CharField(default=b'filter', max_length=12, choices=[(b'filter', b'Filter'), (b'exclude', b'Exclude')])), + ('field_name', models.CharField(max_length=128, verbose_name=b'Field name of User')), + ('lookup_type', models.CharField(default=b'exact', max_length=12, choices=[(b'exact', b'exactly'), (b'iexact', b'exactly (case insensitive)'), (b'contains', b'contains'), (b'icontains', b'contains (case insensitive)'), (b'regex', b'regex'), (b'iregex', b'contains (case insensitive)'), (b'gt', b'greater than'), (b'gte', b'greater than or equal to'), (b'lt', b'less than'), (b'lte', b'less than or equal to'), (b'startswith', b'starts with'), (b'endswith', b'starts with'), (b'istartswith', b'ends with (case insensitive)'), (b'iendswith', b'ends with (case insensitive)')])), + ('field_value', models.CharField(help_text=b'Can be anything from a number, to a string. Or, do `now-7 days` or `today+3 days` for fancy timedelta.', max_length=255)), + ('drip', models.ForeignKey(related_name='queryset_rules', to='drip.Drip')), + ], + options={ + }, + bases=(models.Model,), + ), + migrations.CreateModel( + name='SentDrip', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('date', models.DateTimeField(auto_now_add=True)), + ('subject', models.TextField()), + ('body', models.TextField()), + ('from_email', models.EmailField(default=None, max_length=254, null=True)), + ('from_email_name', models.CharField(default=None, max_length=150, null=True)), + ('drip', models.ForeignKey(related_name='sent_drips', to='drip.Drip')), + ('user', models.ForeignKey(related_name='sent_drips', to=settings.AUTH_USER_MODEL)), + ], + options={ + }, + bases=(models.Model,), + ), + ] diff --git a/drip/migrations/0002_auto__add_field_drip_from_email__add_field_drip_from_email_name__add_f.py b/drip/migrations/0002_auto__add_field_drip_from_email__add_field_drip_from_email_name__add_f.py deleted file mode 100644 index f287ae7..0000000 --- a/drip/migrations/0002_auto__add_field_drip_from_email__add_field_drip_from_email_name__add_f.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: utf-8 -*- -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding field 'Drip.from_email' - db.add_column('drip_drip', 'from_email', - self.gf('django.db.models.fields.EmailField')(max_length=75, null=True, blank=True), - keep_default=False) - - # Adding field 'Drip.from_email_name' - db.add_column('drip_drip', 'from_email_name', - self.gf('django.db.models.fields.CharField')(max_length=150, null=True, blank=True), - keep_default=False) - - # Adding field 'SentDrip.from_email' - db.add_column('drip_sentdrip', 'from_email', - self.gf('django.db.models.fields.EmailField')(default=None, max_length=75, null=True), - keep_default=False) - - # Adding field 'SentDrip.from_email_name' - db.add_column('drip_sentdrip', 'from_email_name', - self.gf('django.db.models.fields.CharField')(default=None, max_length=150, null=True), - keep_default=False) - - - def backwards(self, orm): - # Deleting field 'Drip.from_email' - db.delete_column('drip_drip', 'from_email') - - # Deleting field 'Drip.from_email_name' - db.delete_column('drip_drip', 'from_email_name') - - # Deleting field 'SentDrip.from_email' - db.delete_column('drip_sentdrip', 'from_email') - - # Deleting field 'SentDrip.from_email_name' - db.delete_column('drip_sentdrip', 'from_email_name') - - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - '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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - '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': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - '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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - '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'}), - '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'}) - }, - 'drip.drip': { - 'Meta': {'object_name': 'Drip'}, - 'body_html_template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'from_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), - 'from_email_name': ('django.db.models.fields.CharField', [], {'max_length': '150', 'null': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lastchanged': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), - 'subject_template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}) - }, - 'drip.querysetrule': { - 'Meta': {'object_name': 'QuerySetRule'}, - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'drip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'queryset_rules'", 'to': "orm['drip.Drip']"}), - 'field_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'field_value': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lastchanged': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'lookup_type': ('django.db.models.fields.CharField', [], {'default': "'exact'", 'max_length': '12'}), - 'method_type': ('django.db.models.fields.CharField', [], {'default': "'filter'", 'max_length': '12'}) - }, - 'drip.sentdrip': { - 'Meta': {'object_name': 'SentDrip'}, - 'body': ('django.db.models.fields.TextField', [], {}), - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'drip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_drips'", 'to': "orm['drip.Drip']"}), - 'from_email': ('django.db.models.fields.EmailField', [], {'default': 'None', 'max_length': '75', 'null': 'True'}), - 'from_email_name': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '150', 'null': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'subject': ('django.db.models.fields.TextField', [], {}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_drips'", 'to': "orm['auth.User']"}) - } - } - - complete_apps = ['drip'] \ No newline at end of file diff --git a/drip/migrations/0003_auto__add_field_drip_message_class.py b/drip/migrations/0003_auto__add_field_drip_message_class.py deleted file mode 100644 index 5851455..0000000 --- a/drip/migrations/0003_auto__add_field_drip_message_class.py +++ /dev/null @@ -1,94 +0,0 @@ -# -*- coding: utf-8 -*- -import datetime -from south.db import db -from south.v2 import SchemaMigration -from django.db import models - - -class Migration(SchemaMigration): - - def forwards(self, orm): - # Adding field 'Drip.message_class' - db.add_column('drip_drip', 'message_class', - self.gf('django.db.models.fields.CharField')(default='default', max_length=120, blank=True), - keep_default=False) - - def backwards(self, orm): - # Deleting field 'Drip.message_class' - db.delete_column('drip_drip', 'message_class') - - models = { - 'auth.group': { - 'Meta': {'object_name': 'Group'}, - '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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) - }, - 'auth.permission': { - 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, - 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) - }, - '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': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), - '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': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), - 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) - }, - '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'}), - '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'}) - }, - 'drip.drip': { - 'Meta': {'object_name': 'Drip'}, - 'body_html_template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}), - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), - 'from_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}), - 'from_email_name': ('django.db.models.fields.CharField', [], {'max_length': '150', 'null': 'True', 'blank': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lastchanged': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'message_class': ('django.db.models.fields.CharField', [], {'default': "'default'", 'max_length': '120', 'blank': 'True'}), - 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), - 'subject_template': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}) - }, - 'drip.querysetrule': { - 'Meta': {'object_name': 'QuerySetRule'}, - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'drip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'queryset_rules'", 'to': "orm['drip.Drip']"}), - 'field_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}), - 'field_value': ('django.db.models.fields.CharField', [], {'max_length': '255'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'lastchanged': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), - 'lookup_type': ('django.db.models.fields.CharField', [], {'default': "'exact'", 'max_length': '12'}), - 'method_type': ('django.db.models.fields.CharField', [], {'default': "'filter'", 'max_length': '12'}) - }, - 'drip.sentdrip': { - 'Meta': {'object_name': 'SentDrip'}, - 'body': ('django.db.models.fields.TextField', [], {}), - 'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), - 'drip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_drips'", 'to': "orm['drip.Drip']"}), - 'from_email': ('django.db.models.fields.EmailField', [], {'default': 'None', 'max_length': '75', 'null': 'True'}), - 'from_email_name': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '150', 'null': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'subject': ('django.db.models.fields.TextField', [], {}), - 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sent_drips'", 'to': "orm['auth.User']"}) - } - } - - complete_apps = ['drip'] \ No newline at end of file diff --git a/drip/models.py b/drip/models.py index 94fa400..e56996f 100644 --- a/drip/models.py +++ b/drip/models.py @@ -1,8 +1,10 @@ from datetime import datetime, timedelta +import random from django.db import models from django.core.exceptions import ValidationError from django.conf import settings +from django.utils.functional import cached_property from drip.utils import get_user_model @@ -10,7 +12,6 @@ # https://bitbucket.org/schinckel/django-timedelta-field/ import timedelta as djangotimedelta - class Drip(models.Model): date = models.DateTimeField(auto_now_add=True) lastchanged = models.DateTimeField(auto_now=True) @@ -48,6 +49,7 @@ def __unicode__(self): return self.name + class SentDrip(models.Model): """ Keeps a record of all sent drips. diff --git a/drip/utils.py b/drip/utils.py index 7bb2fe6..e50d327 100644 --- a/drip/utils.py +++ b/drip/utils.py @@ -2,7 +2,11 @@ from django.db import models from django.db.models import ForeignKey, OneToOneField, ManyToManyField -from django.db.models.related import RelatedObject +# try: +# from django.db.models.related import RelatedObject +# except: +# # django 1.8 + +from django.db.models.fields.related import ForeignObjectRel # taking a nod from python-requests and skipping six _ver = sys.version_info @@ -17,7 +21,7 @@ unicode = str -def get_fields(Model, +def get_fields(Model, parent_field="", model_stack=None, stack_limit=2, @@ -41,7 +45,8 @@ def get_fields(Model, app_label, model_name = Model.split('.') Model = models.get_model(app_label, model_name) - fields = Model._meta.fields + Model._meta.many_to_many + Model._meta.get_all_related_objects() + #fields = Model._meta.fields + Model._meta.many_to_many + tuple(Model._meta.get_all_related_objects()) + fields = Model._meta.get_fields() model_stack.append(Model) # do a variety of checks to ensure recursion isnt being redundant @@ -66,7 +71,12 @@ def get_fields(Model, for field in fields: field_name = field.name - if isinstance(field, RelatedObject): + # if instance(field, Man) + + if isinstance(field, ForeignObjectRel): + # from pdb import set_trace + # set_trace() + # print (field, type(field)) field_name = field.field.related_query_name() if parent_field: @@ -74,6 +84,8 @@ def get_fields(Model, else: full_field = field_name + # print (field, field_name, full_field) + if len([True for exclude in excludes if (exclude in full_field)]): continue @@ -81,14 +93,22 @@ def get_fields(Model, out_fields.append([full_field, field_name, Model, field.__class__]) if not stop_recursion and \ - (isinstance(field, ForeignKey) or isinstance(field, OneToOneField) or \ - isinstance(field, RelatedObject) or isinstance(field, ManyToManyField)): + isinstance(field, ForeignObjectRel): + # (isinstance(field, ForeignKey) or isinstance(field, OneToOneField) or \ + # isinstance(field, RelatedObject) or isinstance(field, ManyToManyField)): - if isinstance(field, RelatedObject): + # from pdb import set_trace + # set_trace() + if not isinstance(field, ForeignObjectRel): RelModel = field.model - #field_names.extend(get_fields(RelModel, full_field, True)) else: - RelModel = field.related.parent_model + RelModel = field.related_model + # print (RelModel) + # if isinstance(field, RelatedObject): + # RelModel = field.model + # #field_names.extend(get_fields(RelModel, full_field, True)) + # else: + # RelModel = field.related.parent_model out_fields.extend(get_fields(RelModel, full_field, list(model_stack)))