<commit_before># -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

from daily_emailer.models import Campaign, Email, SentEmail

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Adding model 'SentEmail'
        db.create_table(u'daily_emailer_sentemail', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('email', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['daily_emailer.Email'])),
            ('sent_date', self.gf('django.db.models.fields.DateField')(auto_now=True, blank=True)),
            ('campaign', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['daily_emailer.Campaign'])),
        ))
        db.send_create_signal(u'daily_emailer', ['SentEmail'])

        self.forward_migrate_status()

        # Deleting field 'Campaign.status'
        db.delete_column(u'daily_emailer_campaign', 'status')


    def backwards(self, orm):

        # Adding field 'Campaign.status'
        db.add_column(u'daily_emailer_campaign', 'status',
                      self.gf('daily_emailer.fields.StatusField')(null=True, blank=True),
                      keep_default=False)

        self.backward_migrate_status()

        # Deleting model 'SentEmail'
        db.delete_table(u'daily_emailer_sentemail')


    def forward_migrate_status(self):
        campaign_list = Campaign.objects.all()
        if campaign_list:
            for _campaign in campaign_list:
                for key, value in _campaign.status:
                    _email = Email.objects.get(pk=key)
                    SentEmail(email=_email, sent_date=value, campaign=_campaign)


    def backward_migrate_status(self):
        campaign_list = Campaign.objects.all()
        if campaign_list:
            for _campaign in campaign_list:
                sent_email_list = SentEmail.objects.all().filter(campaign=_campaign)
                if sent_email_list:
                    for email in sent_email_list:
                        _campaign.status[int(email.email.pk)] = email.sent_date


    models = {
        u'daily_emailer.attachment': {
            'Meta': {'object_name': 'Attachment'},
            'attachment': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
            'email': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['daily_emailer.Email']"}),
            'file_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
        },
        u'daily_emailer.campaign': {
            'Meta': {'object_name': 'Campaign'},
            'completed_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
            'email_group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['daily_emailer.EmailGroup']"}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'recipient': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['daily_emailer.Recipient']"}),
            'reference_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
            'start_date': ('django.db.models.fields.DateField', [], {})
        },
        u'daily_emailer.email': {
            'Meta': {'object_name': 'Email'},<commit_msg>Using orm version of models<commit_after># -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models

from daily_emailer.models import Campaign, Email, SentEmail

class Migration(SchemaMigration):

    def forwards(self, orm):
        # Adding model 'SentEmail'
        db.create_table(u'daily_emailer_sentemail', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('email', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['daily_emailer.Email'])),
            ('sent_date', self.gf('django.db.models.fields.DateField')(auto_now=True, blank=True)),
            ('campaign', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['daily_emailer.Campaign'])),
        ))
        db.send_create_signal(u'daily_emailer', ['SentEmail'])

        self.forward_migrate_status(orm)

        # Deleting field 'Campaign.status'
        db.delete_column(u'daily_emailer_campaign', 'status')


    def backwards(self, orm):

        # Adding field 'Campaign.status'
        db.add_column(u'daily_emailer_campaign', 'status',
                      self.gf('daily_emailer.fields.StatusField')(null=True, blank=True),
                      keep_default=False)

        self.backward_migrate_status(orm)

        # Deleting model 'SentEmail'
        db.delete_table(u'daily_emailer_sentemail')


    def forward_migrate_status(self, orm):
        campaign_list = orm.Campaign.objects.all()
        if campaign_list:
            for _campaign in campaign_list:
                for key, value in _campaign.status:
                    _email = Email.objects.get(pk=key)
                    SentEmail(email=_email, sent_date=value, campaign=_campaign)


    def backward_migrate_status(self, orm):
        campaign_list = Campaign.objects.all()
        if campaign_list:
            for _campaign in campaign_list:
                sent_email_list = orm.SentEmail.objects.all().filter(campaign=_campaign)
                if sent_email_list:
                    for email in sent_email_list:
                        _campaign.status[int(email.email.pk)] = email.sent_date


    models = {
        u'daily_emailer.attachment': {
            'Meta': {'object_name': 'Attachment'},
            'attachment': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
            'email': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['daily_emailer.Email']"}),
            'file_name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
        },
        u'daily_emailer.campaign': {
            'Meta': {'object_name': 'Campaign'},
            'completed_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
            'email_group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['daily_emailer.EmailGroup']"}),
            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'recipient': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['daily_emailer.Recipient']"}),
            'reference_name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
            'start_date': ('django.db.models.fields.DateField', [], {})
        },
        u'daily_emailer.email': {
            'Meta': {'object_name': 'Email'},
{'fraction_non_alphanumeric': 0.15763829177414732, 'fraction_numerical': 0.002866150759529951, 'mean_word_length': 2.8157463094587207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '142687', 'n_tokens_mistral': 2188, 'n_tokens_neox': 2070, 'n_words': 329}