Commits

Gregory Petukhov  committed 6bbe40a

Update Feed model with new fields: created, post_count, active_post_count. Create model migrations. Add new feature to Request admin interface: copy request details into Add Feed form

  • Participants
  • Parent commits ba1a0ca

Comments (0)

Files changed (8)

File feedzilla/admin.py

 # -*- coding: utf-8
+from urlparse import urlsplit
 
 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
+from django.core.urlresolvers import reverse
+from django.utils.http import urlencode
 
 from feedzilla.models import Feed, Post, FilterTag, FilterWord, Request
 
 
-def html_link(link):
-    return u'<a href="%(link)s">%(label)s</a>' % {'link': link, 'label': _('link')}
+def html_link(url):
+    host = urlsplit(url).hostname
+    return u'<a href="%s">%s</a>' % (url, host)
 
 
 class FeedAdmin(admin.ModelAdmin):
     list_display = ['title', 'active', 'last_checked',
-                    'author',
-                    'admin_feed_url', 'admin_site_url']
+                    'author', 'admin_feed_url', 'admin_site_url',
+                    'active_post_count', 'post_count', 'created']
     search_fields = ['title', 'site_url']
 
     def admin_feed_url(self, obj):
         return html_link(obj.feed_url)
     admin_feed_url.allow_tags = True
-    admin_feed_url.short_description = _('Feed link')
+    admin_feed_url.short_description = _('Feed')
 
     def admin_site_url(self, obj):
         return html_link(obj.site_url)
     admin_site_url.allow_tags = True
-    admin_site_url.short_description = _('Site link')
+    admin_site_url.short_description = _('Site')
 
 class PostAdmin(admin.ModelAdmin):
     list_display = ['title', 'feed', 'created', 'active',
 
 
 class RequestAdmin(admin.ModelAdmin):
-    list_display = ['url', 'title', 'author', 'created']
+    list_display = ['url', 'title', 'author', 'created', 'process_link']
+
+    def process_link(self, obj):
+        args = {
+            'title': obj.title,
+            'site_url': obj.url,
+            'feed_url': obj.feed_url,
+            'author': obj.author,
+        }
+        url = '%s?%s' % (reverse('admin:feedzilla_feed_add'),
+                         urlencode(args))
+        return u'<a href="%s">%s</a>' % (url, _('Process'))
+    process_link.allow_tags = True
+    process_link.short_description = _('Process')
 
 admin.site.register(Feed, FeedAdmin)
 admin.site.register(Post, PostAdmin)

File feedzilla/management/commands/feedzilla_update.py

 
             feed.last_checked = datetime.now()
             feed.save()
+            feed.update_counts()

File feedzilla/migrations/0001_initial.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):
+        
+        # Adding model 'Feed'
+        db.create_table('feedzilla_feed', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
+            ('feed_url', self.gf('django.db.models.fields.URLField')(unique=True, max_length=200)),
+            ('site_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+            ('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
+            ('etag', self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True)),
+            ('last_checked', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True)),
+            ('skip_filters', self.gf('django.db.models.fields.BooleanField')(default=False)),
+            ('author', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+        ))
+        db.send_create_signal('feedzilla', ['Feed'])
+
+        # Adding model 'Post'
+        db.create_table('feedzilla_post', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('feed', self.gf('django.db.models.fields.related.ForeignKey')(related_name='posts', to=orm['feedzilla.Feed'])),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
+            ('link', self.gf('django.db.models.fields.TextField')()),
+            ('summary', self.gf('django.db.models.fields.TextField')(blank=True)),
+            ('content', self.gf('django.db.models.fields.TextField')(blank=True)),
+            ('created', self.gf('django.db.models.fields.DateTimeField')()),
+            ('guid', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
+            ('tags', self.gf('tagging.fields.TagField')()),
+            ('active', self.gf('django.db.models.fields.BooleanField')(default=True)),
+        ))
+        db.send_create_signal('feedzilla', ['Post'])
+
+        # Adding model 'FilterTag'
+        db.create_table('feedzilla_filtertag', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('value', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
+            ('exact', self.gf('django.db.models.fields.BooleanField')(default=False)),
+        ))
+        db.send_create_signal('feedzilla', ['FilterTag'])
+
+        # Adding model 'FilterWord'
+        db.create_table('feedzilla_filterword', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('value', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
+            ('exact', self.gf('django.db.models.fields.BooleanField')(default=False)),
+        ))
+        db.send_create_signal('feedzilla', ['FilterWord'])
+
+        # Adding model 'Request'
+        db.create_table('feedzilla_request', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('url', self.gf('django.db.models.fields.CharField')(unique=True, max_length=255)),
+            ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
+            ('author', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
+            ('feed_url', self.gf('django.db.models.fields.CharField')(max_length=255, blank=True)),
+            ('created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, blank=True)),
+        ))
+        db.send_create_signal('feedzilla', ['Request'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'Feed'
+        db.delete_table('feedzilla_feed')
+
+        # Deleting model 'Post'
+        db.delete_table('feedzilla_post')
+
+        # Deleting model 'FilterTag'
+        db.delete_table('feedzilla_filtertag')
+
+        # Deleting model 'FilterWord'
+        db.delete_table('feedzilla_filterword')
+
+        # Deleting model 'Request'
+        db.delete_table('feedzilla_request')
+
+
+    models = {
+        'feedzilla.feed': {
+            'Meta': {'object_name': 'Feed'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'etag': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+            'feed_url': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_checked': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'site_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'skip_filters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'feedzilla.filtertag': {
+            'Meta': {'object_name': 'FilterTag'},
+            'exact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        },
+        'feedzilla.filterword': {
+            'Meta': {'object_name': 'FilterWord'},
+            'exact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        },
+        'feedzilla.post': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Post'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'feed': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['feedzilla.Feed']"}),
+            'guid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'link': ('django.db.models.fields.TextField', [], {}),
+            'summary': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'feedzilla.request': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Request'},
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'feed_url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'url': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        }
+    }
+
+    complete_apps = ['feedzilla']

File feedzilla/migrations/0002_auto__add_field_feed_created.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):
+        
+        # Adding field 'Feed.created'
+        db.add_column('feedzilla_feed', 'created', self.gf('django.db.models.fields.DateTimeField')(auto_now_add=True, null=True, blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Feed.created'
+        db.delete_column('feedzilla_feed', 'created')
+
+
+    models = {
+        'feedzilla.feed': {
+            'Meta': {'object_name': 'Feed'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'etag': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+            'feed_url': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_checked': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'site_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'skip_filters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'feedzilla.filtertag': {
+            'Meta': {'object_name': 'FilterTag'},
+            'exact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        },
+        'feedzilla.filterword': {
+            'Meta': {'object_name': 'FilterWord'},
+            'exact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        },
+        'feedzilla.post': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Post'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'feed': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['feedzilla.Feed']"}),
+            'guid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'link': ('django.db.models.fields.TextField', [], {}),
+            'summary': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'feedzilla.request': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Request'},
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'feed_url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'url': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        }
+    }
+
+    complete_apps = ['feedzilla']

File feedzilla/migrations/0003_auto__add_field_feed_post_count__add_field_feed_active_post_count.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):
+        
+        # Adding field 'Feed.post_count'
+        db.add_column('feedzilla_feed', 'post_count', self.gf('django.db.models.fields.IntegerField')(default=0, blank=True), keep_default=False)
+
+        # Adding field 'Feed.active_post_count'
+        db.add_column('feedzilla_feed', 'active_post_count', self.gf('django.db.models.fields.IntegerField')(default=0, blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Feed.post_count'
+        db.delete_column('feedzilla_feed', 'post_count')
+
+        # Deleting field 'Feed.active_post_count'
+        db.delete_column('feedzilla_feed', 'active_post_count')
+
+
+    models = {
+        'feedzilla.feed': {
+            'Meta': {'object_name': 'Feed'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'active_post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'null': 'True', 'blank': 'True'}),
+            'etag': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'blank': 'True'}),
+            'feed_url': ('django.db.models.fields.URLField', [], {'unique': 'True', 'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'last_checked': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'post_count': ('django.db.models.fields.IntegerField', [], {'default': '0', 'blank': 'True'}),
+            'site_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'skip_filters': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'feedzilla.filtertag': {
+            'Meta': {'object_name': 'FilterTag'},
+            'exact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        },
+        'feedzilla.filterword': {
+            'Meta': {'object_name': 'FilterWord'},
+            'exact': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'value': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        },
+        'feedzilla.post': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Post'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'content': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {}),
+            'feed': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'posts'", 'to': "orm['feedzilla.Feed']"}),
+            'guid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'link': ('django.db.models.fields.TextField', [], {}),
+            'summary': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'tags': ('tagging.fields.TagField', [], {}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+        },
+        'feedzilla.request': {
+            'Meta': {'ordering': "['-created']", 'object_name': 'Request'},
+            'author': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'feed_url': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+            'url': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
+        }
+    }
+
+    complete_apps = ['feedzilla']

File feedzilla/migrations/__init__.py

Empty file added.

File feedzilla/models.py

     last_checked = models.DateTimeField(_('last checked'), blank=True, null=True)
     skip_filters = models.BooleanField(_('allow all messages'), blank=True, default=False)
     author = models.CharField(_('blog author'), blank=True, max_length=255)
+    created = models.DateTimeField(_('Date of submition'), blank=True, null=True,
+                                   auto_now_add=True)
+    post_count = models.IntegerField(blank=True, default=0)
+    active_post_count = models.IntegerField(blank=True, default=0)
 
     def __unicode__(self):
         return self.title
     def author_or_title(self):
         return self.author or self.title
 
+    def update_counts(self):
+        self.post_count = self.posts.count()
+        self.active_post_count = self.posts.filter(active=True).count()
+        self.save()
+
 
 class ActivePostManager(models.Manager):
     def get_query_set(self):
             data_files.append(os.path.join(prefix, f))
 
 setup(
-    version = '0.1.14',
+    version = '0.1.15',
     description = 'Django application for atom/rss feeds aggregation i.e. planet engine',
     author = 'Grigoriy Petukhov',
     author_email = 'lorien@lorien.name',