AdBlock dodge (#622)
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 21 May 2010 09:31:43 +0000 (11:31 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 21 May 2010 09:31:43 +0000 (11:31 +0200)
apps/sponsors/fields.py
apps/sponsors/migrations/0001_initial.py [new file with mode: 0644]
apps/sponsors/migrations/0002_move_path.py [new file with mode: 0644]
apps/sponsors/migrations/__init__.py [new file with mode: 0644]
apps/sponsors/models.py

index 26effc5..b3fa361 100644 (file)
@@ -8,6 +8,7 @@ from django.conf import settings
 from django.db import models
 from django import forms
 from django.utils import simplejson as json
+from south.modelsinspector import add_introspection_rules
 
 
 class JSONEncoder(json.JSONEncoder):
@@ -62,3 +63,5 @@ class JSONField(models.TextField):
         def set_value(model_instance, json):
             return setattr(model_instance, self.attname, dumps(json))
         setattr(cls, 'set_%s_value' % self.name, set_value)
+
+add_introspection_rules([], [r"^sponsors\.fields\.JSONField"])
diff --git a/apps/sponsors/migrations/0001_initial.py b/apps/sponsors/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..35eebaa
--- /dev/null
@@ -0,0 +1,58 @@
+# encoding: 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 model 'Sponsor'
+        db.mock_model('sponsors_sponsor', (
+            ('url', self.gf('django.db.models.fields.URLField')(max_length=200, blank=True)),
+            ('logo', self.gf('django.db.models.fields.files.ImageField')(max_length=100)),
+            ('_description', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=120)),
+        ))
+        db.send_create_signal('sponsors', ['Sponsor'])
+
+        # Adding model 'SponsorPage'
+        db.mock_model('sponsors_sponsorpage', (
+            ('_html', self.gf('django.db.models.fields.TextField')(blank=True)),
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('sponsors', self.gf('sponsors.fields.JSONField')(default={})),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=120)),
+        ))
+        db.send_create_signal('sponsors', ['SponsorPage'])
+    
+    
+    def backwards(self, orm):
+        
+        # Deleting model 'Sponsor'
+        db.delete_table('sponsors_sponsor')
+
+        # Deleting model 'SponsorPage'
+        db.delete_table('sponsors_sponsorpage')
+    
+    
+    models = {
+        'sponsors.sponsor': {
+            'Meta': {'object_name': 'Sponsor'},
+            '_description': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'logo': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
+        },
+        'sponsors.sponsorpage': {
+            'Meta': {'object_name': 'SponsorPage'},
+            '_html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'sponsors': ('sponsors.fields.JSONField', [], {'default': '{}'})
+        }
+    }
+    
+    complete_apps = ['sponsors']
diff --git a/apps/sponsors/migrations/0002_move_path.py b/apps/sponsors/migrations/0002_move_path.py
new file mode 100644 (file)
index 0000000..1afbd54
--- /dev/null
@@ -0,0 +1,55 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+
+from django.conf import settings
+from shutil import move
+from os import path
+
+
+def move_sponsors_media(orm, old, new):
+    move(path.join(settings.MEDIA_ROOT, old), 
+        path.join(settings.MEDIA_ROOT, new))
+    for sponsor in orm.Sponsor.objects.all():
+        base, rest = sponsor.logo.name.split('/', 1)
+        sponsor.logo.name = '/'.join((new, rest))
+        sponsor.save()
+    # reset cache
+    for sponsor_page in orm.SponsorPage.objects.all():
+        sponsor_page.save()
+    
+
+class Migration(DataMigration):
+    
+    def forwards(self, orm):
+        "Write your forwards methods here."
+        if not db.dry_run:
+            move_sponsors_media(orm, 'sponsors', 'sponsorzy')
+    
+    def backwards(self, orm):
+        "Write your backwards methods here."
+        if not db.dry_run:
+            move_sponsors_media(orm, 'sponsorzy', 'sponsors')
+    
+    
+    models = {
+        'sponsors.sponsor': {
+            'Meta': {'object_name': 'Sponsor'},
+            '_description': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'logo': ('django.db.models.fields.files.ImageField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'})
+        },
+        'sponsors.sponsorpage': {
+            'Meta': {'object_name': 'SponsorPage'},
+            '_html': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
+            'sponsors': ('sponsors.fields.JSONField', [], {'default': '{}'})
+        }
+    }
+    
+    complete_apps = ['sponsors']
diff --git a/apps/sponsors/migrations/__init__.py b/apps/sponsors/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 60e4c49..28ef76e 100644 (file)
@@ -15,7 +15,7 @@ class Sponsor(models.Model):
     _description = models.CharField(_('description'), blank=True, max_length=255)
     logo = ImageWithThumbnailsField(
         _('logo'),
-        upload_to='sponsors/sponsor/logo',
+        upload_to='sponsorzy/sponsor/logo',
         thumbnail={
             'size': (120, 60),
             'extension': 'png',