Commits

Dan Carroll committed fddc35a

Remove old source choice (and necessary migration), and make test management command actually create items.

Comments (0)

Files changed (4)

mysite/activitysync/management/commands/updatetest.py

 from django.core.management.color import no_style
 from django.core.mail import mail_admins
 from optparse import make_option
-from activitysync.models import Activity
+from activitysync.models import Provider, Activity
 from activitysync.providers import ActivityProvider, ActivityInfo
 
 import os
 
                 provider_instance = provider_class()
                 email_status_info.append('\n\n%s\n\n' % provider_instance.name())
+
+                # Create Provider model object if it does not exist
+                try:
+                    providerModelObject = Provider.objects.get(sourceid=provider_instance.sourceid())
+                except Provider.DoesNotExist:
+                    print 'First time seeing provider with sourceid: %s' % provider_instance.sourceid()
+                    providerModelObject = Provider.objects.create(
+                        name=provider_instance.name(),
+                        prefix=provider_instance.prefix(),
+                        link=provider_instance.link(),
+                        sourceid=provider_instance.sourceid()
+                    )
+
                 for activity_item in provider_instance.get_activity():
                     try:
                         Activity.objects.get(guid=activity_item.guid)
                         
                         if dry_run:
                             print 'Dry run, not creating item'
-                            #Activity.objects.create(title=activity_item.title, link=activity_item.link, source=provider_instance.sourceid(), username=activity_item.username, author=activity_item.author, comments=activity_item.comments, pub_date=activity_item.pub_date, published=activity_item.published, guid=activity_item.guid)
+                        else:
+                            Activity.objects.create(title=activity_item.title, link=activity_item.link, username=activity_item.username, author=activity_item.author, comments=activity_item.comments, pub_date=activity_item.pub_date, published=activity_item.published, guid=activity_item.guid, provider=providerModelObject)
 
         except:
             ### DEBUGGING CODE

mysite/activitysync/migrations/0004_auto__del_field_activity_source.py

+# 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):
+        
+        # Deleting field 'Activity.source'
+        db.delete_column('activitysync_activity', 'source')
+
+
+    def backwards(self, orm):
+        
+        # Adding field 'Activity.source'
+        db.add_column('activitysync_activity', 'source', self.gf('django.db.models.fields.CharField')(default='?', max_length=2), keep_default=False)
+
+
+    models = {
+        'activitysync.activity': {
+            'Meta': {'ordering': "('-pub_date',)", 'object_name': 'Activity'},
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'}),
+            'comments': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'guid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255', 'db_index': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'link': ('django.db.models.fields.URLField', [], {'max_length': '500'}),
+            'provider': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['activitysync.Provider']", 'null': 'True'}),
+            'pub_date': ('django.db.models.fields.DateTimeField', [], {}),
+            'published': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'username': ('django.db.models.fields.CharField', [], {'max_length': '20', 'blank': 'True'})
+        },
+        'activitysync.provider': {
+            'Meta': {'ordering': "('name',)", 'object_name': 'Provider'},
+            'link': ('django.db.models.fields.URLField', [], {'max_length': '500'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
+            'prefix': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+            'sourceid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '20', 'primary_key': 'True', 'db_index': 'True'})
+        }
+    }
+
+    complete_apps = ['activitysync']

mysite/activitysync/models.py

 from django.db import models
 from activitysync.managers import ActivityManager
-import datetime
 
 class Provider(models.Model):
     """Provider represents a particular social network"""
 
 class Activity(models.Model):
     """Activity from social network (Twitter, Flickr, etc)."""
-    SOURCE_CHOICES = (
-        ('T', 'twitter'),
-        ('DL', 'delicious'),
-        ('FB', 'facebook'),
-        ('HU', 'hulu'),
-        ('RD', 'reddit'),
-        ('GR', 'googlereader'),
-    )
     
     title = models.CharField('title', max_length=200)
     link = models.URLField(max_length=500)
-    source = models.CharField(max_length=2, choices=SOURCE_CHOICES)
     username = models.CharField(max_length=20, blank=True)
     author = models.CharField(max_length=20, blank=True)
     comments = models.TextField(blank=True)
     
     def __unicode__(self):
         return u'%s' % self.title
-
-    def get_activity_prefix(self):
-        if self.source == 'DL':
-            return u'Bookmarked '
-        elif self.source == 'HU':
-            return u'Watched '
-        elif self.source == 'RD':
-            return u'Liked '
-        elif self.source == 'GR':
-            return u'Shared '
-        else:
-            return u''
-    
-    def get_network_link(self):
-        if self.source == 'T':
-            return u"http://twitter.com/erunama"
-        elif self.source == 'DL':
-            return u"http://delicious.com/erunama"
-        elif self.source == 'FB':
-            return u"http://www.facebook.com/people/Dan-Carroll/401024"
-        elif self.source == 'HU':
-            return u"http://www.hulu.com/profiles/erunama/"
-        elif self.source == 'RD':
-            return u"http://www.reddit.com/user/erunama/"
-        elif self.source == 'GR':
-            return u"http://www.google.com/reader/shared/dancarroll"
-            
+       

mysite/activitysync/providers/__init__.py

         raise NotImplementedError
 
 class ActivityInfo(object):
-    def __init__(self, title, link, pub_date, guid, username=None, author=None, comments=None, published=True):
+    def __init__(self, title, link, pub_date, guid, username=None, author=None, comments='', published=True):
         self.title = title
         self.link = link
         self.username = username