Commits

Anonymous committed f9a6450

add num entries

  • Participants
  • Parent commits 86796d6

Comments (0)

Files changed (6)

File cmsplugin_feed/cms_plugins.py

         return context
 
 plugin_pool.register_plugin(FeedPlugin)
+
+class UltimoFeedPlugin(CMSPluginBase):
+    model = FeedPtr
+    form = FeedForm
+    name = _('Ultimi Feed')
+    render_template = 'cmsplugin_feed/ultimo_feed.html'
+
+    def render(self, context, instance, placeholder):
+        #feed = get_cached_feed(instance)
+        feed = feedparser.parse(instance.feed.feed_url)
+        is_youtube_rss = False
+        if instance.feed.feed_url.find('youtube.com') > -1:
+            is_youtube_rss = True
+
+        entries = feed["entries"]
+
+        img_youtube = ''
+        if is_youtube_rss:
+            id = feed['entries'][0]['id'].split(":")[3]
+            img_youtube = '<img src="http://i.ytimg.com/vi/%s/default.jpg" alt="" width="272" />' % id
+
+        context.update({
+            'instance': instance.feed,
+            'last_entries': entries[:instance.feed.num_entries],
+            'is_youtube_rss': is_youtube_rss,
+            'img_youtube': img_youtube,
+            'placeholder': placeholder,
+            })
+        return context
+
+plugin_pool.register_plugin(UltimoFeedPlugin)

File cmsplugin_feed/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('cmsplugin_feed_feed', (
+            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('name', self.gf('django.db.models.fields.CharField')(max_length=255, null=True, blank=True)),
+            ('feed_url', self.gf('django.db.models.fields.URLField')(max_length=200)),
+            ('paginate_by', self.gf('django.db.models.fields.IntegerField')(default=5, null=True, blank=True)),
+        ))
+        db.send_create_signal('cmsplugin_feed', ['Feed'])
+
+        # Adding model 'FeedPtr'
+        db.create_table('cmsplugin_feedptr', (
+            ('cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)),
+            ('feed', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cmsplugin_feed.Feed'])),
+        ))
+        db.send_create_signal('cmsplugin_feed', ['FeedPtr'])
+
+
+    def backwards(self, orm):
+        
+        # Deleting model 'Feed'
+        db.delete_table('cmsplugin_feed_feed')
+
+        # Deleting model 'FeedPtr'
+        db.delete_table('cmsplugin_feedptr')
+
+
+    models = {
+        'cms.cmsplugin': {
+            'Meta': {'object_name': 'CMSPlugin'},
+            'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+            'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+            'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+            'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+        },
+        'cms.placeholder': {
+            'Meta': {'object_name': 'Placeholder'},
+            'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+        },
+        'cmsplugin_feed.feed': {
+            'Meta': {'object_name': 'Feed'},
+            'feed_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'paginate_by': ('django.db.models.fields.IntegerField', [], {'default': '5', 'null': 'True', 'blank': 'True'})
+        },
+        'cmsplugin_feed.feedptr': {
+            'Meta': {'object_name': 'FeedPtr', 'db_table': "'cmsplugin_feedptr'", '_ormbases': ['cms.CMSPlugin']},
+            'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+            'feed': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cmsplugin_feed.Feed']"})
+        }
+    }
+
+    complete_apps = ['cmsplugin_feed']

File cmsplugin_feed/migrations/0002_auto__add_field_feed_num_entries.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.num_entries'
+        db.add_column('cmsplugin_feed_feed', 'num_entries', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True), keep_default=False)
+
+
+    def backwards(self, orm):
+        
+        # Deleting field 'Feed.num_entries'
+        db.delete_column('cmsplugin_feed_feed', 'num_entries')
+
+
+    models = {
+        'cms.cmsplugin': {
+            'Meta': {'object_name': 'CMSPlugin'},
+            'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
+            'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
+            'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
+            'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
+            'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+            'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+        },
+        'cms.placeholder': {
+            'Meta': {'object_name': 'Placeholder'},
+            'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+        },
+        'cmsplugin_feed.feed': {
+            'Meta': {'object_name': 'Feed'},
+            'feed_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'num_entries': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'paginate_by': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+        },
+        'cmsplugin_feed.feedptr': {
+            'Meta': {'object_name': 'FeedPtr', 'db_table': "'cmsplugin_feedptr'", '_ormbases': ['cms.CMSPlugin']},
+            'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+            'feed': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cmsplugin_feed.Feed']"})
+        }
+    }
+
+    complete_apps = ['cmsplugin_feed']

File cmsplugin_feed/migrations/__init__.py

Empty file added.

File cmsplugin_feed/models.py

 class Feed(models.Model):
     name = models.CharField(verbose_name=_('name'),max_length=255,
                             null=True, blank=True)
-    feed_url = models.URLField(verbose_name=_('feed URL'),verify_exists=True)
+    feed_url = models.URLField(verbose_name=_('feed URL'))
     paginate_by = models.IntegerField(verbose_name="paginate by",
-                                      null=True, blank=True,
-                                      default=5)
+                                      null=True, blank=True)
+    num_entries = models.IntegerField(verbose_name="Num. Entries",
+        null=True, blank=True)
 
     def __unicode__(self):
         return self.name

File cmsplugin_feed/templates/cmsplugin_feed/ultimo_feed.html

+<h1>{{ instance.name }}</h1>
+<div class="feed">
+    <h2><a href='{{ last_entry.link}}'>{{ last_entry.title }}</a></h2>
+    {{ last_entry.summary|safe }}
+</div>