Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding approval_status to Feed objects (with accompanying admin).

  • Loading branch information...
commit 1ea624b97337f4eb75645750d200a779ed53a222 1 parent e358782
Justin Abrahms authored February 03, 2012
8  django_website/aggregator/admin.py
@@ -3,16 +3,16 @@
3 3
 from django.contrib import admin
4 4
 from .models import Feed, FeedItem, FeedType
5 5
 
6  
-admin.site.register(Feed, 
7  
-    list_display  = ["title", "feed_type", "public_url"],
8  
-    list_filter   = ["feed_type", "is_defunct"],
  6
+admin.site.register(Feed,
  7
+    list_display  = ["title", "feed_type", "public_url", "approval_status"],
  8
+    list_filter   = ["feed_type", "is_defunct", "approval_status"],
9 9
     ordering      = ["title"],
10 10
     search_fields = ["title", "public_url"],
11 11
     raw_id_fields = ['owner'],
12 12
     list_per_page = 500,
13 13
 )
14 14
 
15  
-admin.site.register(FeedItem, 
  15
+admin.site.register(FeedItem,
16 16
     list_display   = ['title', 'feed', 'date_modified'],
17 17
     list_filter    = ['feed'],
18 18
     search_fields  = ['feed__title', 'feed__public_url', 'title'],
88  django_website/aggregator/migrations/0004_add_approval_status_field.py
... ...
@@ -0,0 +1,88 @@
  1
+# encoding: utf-8
  2
+import datetime
  3
+from south.db import db
  4
+from south.v2 import SchemaMigration
  5
+from django.db import models
  6
+
  7
+class Migration(SchemaMigration):
  8
+
  9
+    def forwards(self, orm):
  10
+        
  11
+        # Adding field 'Feed.approval_status'
  12
+        db.add_column('aggregator_feed', 'approval_status', self.gf('django.db.models.fields.CharField')(default='P', max_length=1), keep_default=False)
  13
+
  14
+
  15
+    def backwards(self, orm):
  16
+        
  17
+        # Deleting field 'Feed.approval_status'
  18
+        db.delete_column('aggregator_feed', 'approval_status')
  19
+
  20
+
  21
+    models = {
  22
+        'aggregator.feed': {
  23
+            'Meta': {'object_name': 'Feed'},
  24
+            'approval_status': ('django.db.models.fields.CharField', [], {'default': "'P'", 'max_length': '1'}),
  25
+            'feed_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['aggregator.FeedType']"}),
  26
+            'feed_url': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '500'}),
  27
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  28
+            'is_defunct': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  29
+            'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'owned_feeds'", 'null': 'True', 'to': "orm['auth.User']"}),
  30
+            'public_url': ('django.db.models.fields.URLField', [], {'max_length': '500'}),
  31
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
  32
+        },
  33
+        'aggregator.feeditem': {
  34
+            'Meta': {'ordering': "('-date_modified',)", 'object_name': 'FeedItem'},
  35
+            'date_modified': ('django.db.models.fields.DateTimeField', [], {}),
  36
+            'feed': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['aggregator.Feed']"}),
  37
+            'guid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '500', 'db_index': 'True'}),
  38
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  39
+            'link': ('django.db.models.fields.URLField', [], {'max_length': '500'}),
  40
+            'summary': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
  41
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '500'})
  42
+        },
  43
+        'aggregator.feedtype': {
  44
+            'Meta': {'object_name': 'FeedType'},
  45
+            'can_self_add': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
  46
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  47
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '250'}),
  48
+            'slug': ('django.db.models.fields.SlugField', [], {'max_length': '250', 'db_index': 'True'})
  49
+        },
  50
+        'auth.group': {
  51
+            'Meta': {'object_name': 'Group'},
  52
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  53
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
  54
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
  55
+        },
  56
+        'auth.permission': {
  57
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
  58
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  59
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
  60
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  61
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
  62
+        },
  63
+        'auth.user': {
  64
+            'Meta': {'object_name': 'User'},
  65
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
  66
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
  67
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
  68
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
  69
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  70
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
  71
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  72
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
  73
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
  74
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
  75
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
  76
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
  77
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
  78
+        },
  79
+        'contenttypes.contenttype': {
  80
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
  81
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  82
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
  83
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
  84
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
  85
+        }
  86
+    }
  87
+
  88
+    complete_apps = ['aggregator']
15  django_website/aggregator/models.py
@@ -5,6 +5,7 @@
5 5
 from django.conf import settings
6 6
 from django_push.subscriber import signals as push_signals
7 7
 from django_push.subscriber.models import Subscription
  8
+from django.conf import settings
8 9
 
9 10
 log = logging.getLogger(__name__)
10 11
 
@@ -19,11 +20,19 @@ def __unicode__(self):
19 20
     def items(self):
20 21
         return FeedItem.objects.filter(feed__feed_type=self)
21 22
 
  23
+STATUS_CHOICES = (
  24
+    ('P', 'Pending'),
  25
+    ('D', 'Denied'),
  26
+    ('A', 'Approved')
  27
+)
  28
+
  29
+
22 30
 class Feed(models.Model):
23 31
     title = models.CharField(max_length=500)
24 32
     feed_url = models.URLField(unique=True, max_length=500)
25 33
     public_url = models.URLField(max_length=500)
26 34
     is_defunct = models.BooleanField()
  35
+    approval_status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=STATUS_CHOICES[0][0])
27 36
     feed_type = models.ForeignKey(FeedType)
28 37
     owner = models.ForeignKey(User, blank=True, null=True, related_name='owned_feeds')
29 38
 
@@ -32,11 +41,13 @@ def __unicode__(self):
32 41
 
33 42
     def save(self, **kwargs):
34 43
         super(Feed, self).save(**kwargs)
35  
-        Subscription.objects.subscribe(self.feed_url, settings.PUSH_HUB)
  44
+        if settings.PRODUCTION and self.approval_status == STATUS_CHOICES[2][0]:
  45
+            Subscription.objects.subscribe(self.feed_url, settings.PUSH_HUB)
36 46
 
37 47
     def delete(self, **kwargs):
38 48
         super(Feed, self).delete(**kwargs)
39  
-        Subscription.objects.unsubscribe(self.feed_url, settings.PUSH_HUB)
  49
+        if settings.PRODUCTION: # @@@ need to validate what pubsub stuff is actually doing here.
  50
+            Subscription.objects.unsubscribe(self.feed_url, settings.PUSH_HUB)
40 51
 
41 52
 class FeedItemManager(models.Manager):
42 53
     def create_or_update_by_guid(self, guid, **kwargs):

0 notes on commit 1ea624b

Please sign in to comment.
Something went wrong with that request. Please try again.