Commits

Anonymous committed 977f1c2

aggiunto plugin feed a scorrimento

  • Participants
  • Parent commits 53f4f36

Comments (0)

Files changed (7)

File cmsplugin_feed/cms_plugins.py

 from cms.plugin_base import CMSPluginBase
 from cms.plugin_pool import plugin_pool
 
-from cmsplugin_feed.models import FeedPtr
+from cmsplugin_feed.models import FeedPtr, FeedScorrimento
 from cmsplugin_feed.forms import FeedForm
 from cmsplugin_feed.settings import CMSPLUGIN_FEED_CACHE_TIMEOUT
 
 
 class FeedPlugin(CMSPluginBase):
     model = FeedPtr
-    name = _('Feed')
+    name = _('Feed HTML')
     form = FeedForm
     render_template = 'cmsplugin_feed/feed.html'
 
 
 plugin_pool.register_plugin(FeedPlugin)
 
+class FeedScorrimentoPlugin(CMSPluginBase):
+    model = FeedScorrimento
+    name = _('Feed a SCORRIMENTO')
+    render_template = 'cmsplugin_feed/feed_scorrimento.html'
+
+    def render(self, context, instance, placeholder):
+        context.update({
+            'instance': instance,
+            'placeholder': placeholder,
+            })
+        return context
+
+plugin_pool.register_plugin(FeedScorrimentoPlugin)
+
 class UltimoFeedPlugin(CMSPluginBase):
     model = FeedPtr
     form = FeedForm

File cmsplugin_feed/migrations/0003_auto__add_feedscorrimento.py

+# -*- coding: 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 'FeedScorrimento'
+        db.create_table(u'cmsplugin_feedscorrimento', (
+            (u'cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, 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)),
+            ('limit', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
+            ('show_items', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
+            ('height', self.gf('django.db.models.fields.IntegerField')(null=True, blank=True)),
+            ('link_redirect', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
+        ))
+        db.send_create_signal(u'cmsplugin_feed', ['FeedScorrimento'])
+
+    def backwards(self, orm):
+        # Deleting model 'FeedScorrimento'
+        db.delete_table(u'cmsplugin_feedscorrimento')
+
+    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(2013, 8, 26, 0, 0)'}),
+            u'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'}),
+            u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
+        },
+        u'cmsplugin_feed.feed': {
+            'Meta': {'object_name': 'Feed'},
+            'feed_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            u'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'})
+        },
+        u'cmsplugin_feed.feedptr': {
+            'Meta': {'object_name': 'FeedPtr', 'db_table': "u'cmsplugin_feedptr'", '_ormbases': ['cms.CMSPlugin']},
+            u'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': u"orm['cmsplugin_feed.Feed']"})
+        },
+        u'cmsplugin_feed.feedscorrimento': {
+            'Meta': {'object_name': 'FeedScorrimento', 'db_table': "u'cmsplugin_feedscorrimento'", '_ormbases': ['cms.CMSPlugin']},
+            u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+            'feed_url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+            'height': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'limit': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'link_redirect': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+            'show_items': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'})
+        }
+    }
+
+    complete_apps = ['cmsplugin_feed']

File cmsplugin_feed/models.py

 
 # We don't both with SnippetPtr, since all the data is actually in Snippet
 reversion_register(Feed)
+
+
+class FeedScorrimento(CMSPlugin):
+    name = models.CharField(verbose_name=_('title'), max_length=255,
+                            null=True, blank=True)
+    feed_url = models.URLField(verbose_name=_('feed URL'))
+    limit = models.IntegerField(verbose_name="limit",
+                                null=True, blank=True)
+    show_items = models.IntegerField(verbose_name="show items",
+                                     null=True, blank=True)
+    height = models.IntegerField(verbose_name="height",
+                                     null=True, blank=True)
+    link_redirect = models.CharField(max_length=100, verbose_name="link redirect",
+                                     null=True, blank=True)

File cmsplugin_feed/static/cmsplugin_feed/jquery.vticker.js

+/*
+* Tadas Juozapaitis ( kasp3rito@gmail.com )
+*
+* Modifed by Zazar:
+* 24.06.2011 - Corrected pausing issue with multiple instances
+*
+*/
+
+(function($){
+
+$.fn.vTicker = function(options) {
+	var defaults = {
+		speed: 1400,
+		pause: 8000,
+		showItems: 3,
+		animation: '',
+		mousePause: true,
+		isPaused: false,
+        height: 0
+	};
+
+	var options = $.extend(defaults, options);
+
+	moveUp = function(obj2, height, paused){
+		if(paused) return;
+		
+		var obj = obj2.children('ul');
+		
+	    	first = obj.children('li:first').clone(true);
+		
+    		obj.animate({top: '-=' + height + 'px'}, options.speed, function() {
+        		$(this).children('li:first').remove();
+	        	$(this).css('top', '0px');
+        	});
+		
+		if(options.animation == 'fade') {
+			obj.children('li:first').fadeOut(options.speed);
+			obj.children('li:last').hide().fadeIn(options.speed);
+		}
+
+	    	first.appendTo(obj);
+	};
+	
+	return this.each(function() {
+		var obj = $(this);
+		var maxHeight = 0;
+        var customHeight = options.height;
+		var itempause = options.isPaused;
+
+		obj.css({overflow: 'hidden', position: 'relative'})
+			.children('ul').css({position: 'absolute', margin: 0, padding: 0})
+			.children('li').css({margin: 0, padding: 0});
+
+		obj.children('ul').children('li').each(function(){
+            if (customHeight > 0) {
+                maxHeight = customHeight;
+            }
+            else {
+                if($(this).height() > maxHeight) {
+                    maxHeight = $(this).height();
+                }
+            }
+		});
+
+		obj.children('ul').children('li').each(function() {
+			$(this).height(maxHeight);
+		});
+
+		obj.height(maxHeight * options.showItems);
+		
+    		var interval = setInterval(function(){ moveUp(obj, maxHeight, itempause); }, options.pause);
+		
+		if (options.mousePause)
+		{
+			obj.bind("mouseenter",function() {
+				itempause = true;
+			}).bind("mouseleave",function() {
+				itempause = false;
+			});
+		}
+	});
+};
+})(jQuery);

File cmsplugin_feed/static/cmsplugin_feed/jquery.zrssfeed.js

+/**
+ * Plugin: jquery.zRSSFeed
+ * 
+ * Version: 1.1.9
+ * (c) Copyright 2010-2012, Zazar Ltd
+ * 
+ * Description: jQuery plugin for display of RSS feeds via Google Feed API
+ *              (Based on original plugin jGFeed by jQuery HowTo. Filesize function by Cary Dunn.)
+ * 
+ * History:
+ * 1.1.9 - New dateformat option to allow feed date formatting
+ * 1.1.8 - Added historical option to enable scoring in the Google Feed API
+ * 1.1.7 - Added feed offset, link redirect & link content options
+ * 1.1.6 - Added sort options
+ * 1.1.5 - Target option now applies to all feed links
+ * 1.1.4 - Added option to hide media and now compressed with Google Closure
+ * 1.1.3 - Check for valid published date
+ * 1.1.2 - Added user callback function due to issue with ajaxStop after jQuery 1.4.2
+ * 1.1.1 - Correction to null xml entries and support for media with jQuery < 1.5
+ * 1.1.0 - Added support for media in enclosure tags
+ * 1.0.3 - Added feed link target
+ * 1.0.2 - Fixed issue with GET parameters (Seb Dangerfield) and SSL option
+ * 1.0.1 - Corrected issue with multiple instances
+ *
+ **/
+
+(function($){
+
+	$.fn.rssfeed = function(url, options, fn) {	
+	
+		// Set plugin defaults
+		var defaults = {
+			limit: 10,
+			offset: 1,
+			header: true,
+			titletag: 'h4',
+			date: true,
+			dateformat: 'datetime',
+			content: true,
+			snippet: true,
+			media: true,
+			showerror: true,
+			errormsg: '',
+			key: null,
+			ssl: false,
+			linktarget: '_self',
+			linkredirect: '',
+			linkcontent: false,
+			sort: '',
+			sortasc: true,
+			historical: false
+		};  
+		var options = $.extend(defaults, options); 
+		
+		// Functions
+		return this.each(function(i, e) {
+			var $e = $(e);
+			var s = '';
+
+			// Check for SSL protocol
+			if (options.ssl) s = 's';
+			
+			// Add feed class to user div
+			if (!$e.hasClass('rssFeed')) $e.addClass('rssFeed');
+			
+			// Check for valid url
+			if(url == null) return false;
+
+			// Add start offset to feed length
+			if (options.offset > 0) options.offset -= 1;
+			options.limit += options.offset;
+			
+			// Create Google Feed API address
+			var api = "http"+ s +"://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=" + encodeURIComponent(url);
+			api += "&num=" + options.limit;
+			if (options.historical) api += "&scoring=h";
+			if (options.key != null) api += "&key=" + options.key;
+			api += "&output=json_xml"
+
+			// Send request
+			$.getJSON(api, function(data){
+				
+				// Check for error
+				if (data.responseStatus == 200) {
+	
+					// Process the feeds
+					_process(e, data.responseData, options);
+
+					// Optional user callback function
+					if ($.isFunction(fn)) fn.call(this,$e);
+					
+				} else {
+
+					// Handle error if required
+					if (options.showerror)
+						if (options.errormsg != '') {
+							var msg = options.errormsg;
+						} else {
+							var msg = data.responseDetails;
+						};
+						$(e).html('<div class="rssError"><p>'+ msg +'</p></div>');
+				};
+			});				
+		});
+	};
+	
+	// Function to create HTML result
+	var _process = function(e, data, options) {
+
+		// Get JSON feed data
+		var feeds = data.feed;
+		if (!feeds) {
+			return false;
+		}
+		var rowArray = [];
+		var rowIndex = 0;
+		var html = '';	
+		var row = 'odd';
+		
+		// Get XML data for media (parseXML not used as requires 1.5+)
+		if (options.media) {
+			var xml = _getXMLDocument(data.xmlString);
+			var xmlEntries = xml.getElementsByTagName('item');
+		}
+		
+		// Add header if required
+		if (options.header)
+			html +=	'<div class="rssHeader">' +
+				'<a href="'+feeds.link+'" title="'+ feeds.description +'">'+ feeds.title +'</a>' +
+				'</div>';
+			
+		// Add body
+		html += '<div class="rssBody">' +
+			'<ul>';
+
+
+		// Add feeds
+		for (var i=options.offset; i<feeds.entries.length; i++) {
+			
+			rowIndex = i - options.offset;
+			rowArray[rowIndex] = [];
+
+			// Get individual feed
+			var entry = feeds.entries[i];
+			var pubDate;
+			var sort = '';
+			var feedLink = entry.link;
+
+			// Apply sort column
+			switch (options.sort) {
+				case 'title':
+					sort = entry.title;
+					break;
+				case 'date':
+					sort = entry.publishedDate;
+					break;
+			}
+			rowArray[rowIndex]['sort'] = sort;
+
+			// Format published date
+			if (entry.publishedDate) {
+
+				var entryDate = new Date(entry.publishedDate);
+				var pubDate = entryDate.toLocaleDateString() + ' ' + entryDate.toLocaleTimeString();
+
+				switch (options.dateformat) {
+					case 'datetime':
+						break;
+					case 'date':
+						pubDate = entryDate.toLocaleDateString();
+						break;
+					case 'time':
+						pubDate = entryDate.toLocaleTimeString();
+						break;
+					case 'timeline':
+						pubDate = _getLapsedTime(entryDate);
+						break;
+					default:
+						pubDate = _formatDate(entryDate,options.dateformat);
+						break;
+				}
+			}
+			
+			// Add feed row
+			if (options.linkredirect) feedLink = encodeURIComponent(feedLink);
+			rowArray[rowIndex]['html'] = '<'+ options.titletag +'><a href="'+ options.linkredirect +'" title="View this feed at '+ feeds.title +'">'+ entry.title +'</a></'+ options.titletag +'>'
+
+			if (options.date && pubDate) rowArray[rowIndex]['html'] += '<div>'+ pubDate +'</div>'
+			if (options.content) {
+			
+				// Use feed snippet if available and optioned
+				if (options.snippet && entry.contentSnippet != '') {
+					var content = entry.contentSnippet;
+				} else {
+					var content = entry.content;
+				}
+
+				if (options.linkcontent) {
+					content = '<a href="'+ options.linkredirect + feedLink +'" title="View this feed at '+ feeds.title +'">'+ content +'</a>'
+				}
+				
+				rowArray[rowIndex]['html'] += '<p>'+ content +'</p>'
+			}
+			
+			// Add any media
+			if (options.media && xmlEntries.length > 0) {
+				var xmlMedia = xmlEntries[i].getElementsByTagName('enclosure');
+				if (xmlMedia.length > 0) {
+					
+					rowArray[rowIndex]['html'] += '<div class="rssMedia"><div>Media files</div><ul>'
+					
+					for (var m=0; m<xmlMedia.length; m++) {
+						var xmlUrl = xmlMedia[m].getAttribute("url");
+						var xmlType = xmlMedia[m].getAttribute("type");
+						var xmlSize = xmlMedia[m].getAttribute("length");
+						rowArray[rowIndex]['html'] += '<li><a href="'+ xmlUrl +'" title="Download this media">'+ xmlUrl.split('/').pop() +'</a> ('+ xmlType +', '+ _formatFilesize(xmlSize) +')</li>';
+					}
+					rowArray[rowIndex]['html'] += '</ul></div>'
+				}
+			}
+					
+		}
+		
+		// Sort if required
+		if (options.sort) {
+			rowArray.sort(function(a,b) {
+
+				// Apply sort direction
+				if (options.sortasc) {
+					var c = a['sort'];
+					var d = b['sort'];
+				} else {
+					var c = b['sort'];
+					var d = a['sort'];
+				}
+
+				if (options.sort == 'date') {
+					return new Date(c) - new Date(d);
+				} else {
+					c = c.toLowerCase();
+					d = d.toLowerCase();
+					return (c < d) ? -1 : (c > d) ? 1 : 0;
+				}
+			});
+		}
+
+		// Add rows to output
+		$.each(rowArray, function(e) {
+
+			html += '<li class="rssRow '+row+'">' + rowArray[e]['html'] + '</li>';
+
+			// Alternate row classes
+			if (row == 'odd') {
+				row = 'even';
+			} else {
+				row = 'odd';
+			}			
+		});
+
+		html += '</ul>' +
+			'</div>'
+		
+		$(e).html(html);
+
+		// Apply target to links
+		$('a',e).attr('target',options.linktarget);
+	};
+	
+	var _formatFilesize = function(bytes) {
+		var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
+		var e = Math.floor(Math.log(bytes)/Math.log(1024));
+		return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
+	}
+
+	var _formatDate = function(date,mask) {
+
+		// Convert to date and set return to the mask
+		var fmtDate = new Date(date);
+		date = mask;
+
+		// Replace mask tokens
+		date = date.replace('dd', _formatDigit(fmtDate.getDate()));
+		date = date.replace('MM', _formatDigit(fmtDate.getMonth()+1));
+		date = date.replace('yyyy',fmtDate.getFullYear());
+		date = date.replace('hh', _formatDigit(fmtDate.getHours()));
+		date = date.replace('mm', _formatDigit(fmtDate.getMinutes()));
+		date = date.replace('ss', _formatDigit(fmtDate.getSeconds()));
+
+		return date;
+	}
+
+	var _formatDigit = function(digit) {
+		digit += '';
+		if (digit.length < 2) digit = '0' + digit;
+		return digit;
+	}
+
+	var _getXMLDocument = function(string) {
+		var browser = navigator.appName;
+		var xml;
+		if (browser == 'Microsoft Internet Explorer') {
+			xml = new ActiveXObject('Microsoft.XMLDOM');
+			xml.async = 'false';
+			xml.loadXML(string);
+		} else {
+			xml = (new DOMParser()).parseFromString(string, 'text/xml');
+		}
+		return xml;
+	}
+
+	var _getLapsedTime = function(date) {
+		
+		// Get current date and format date parameter
+		var todayDate = new Date();	
+		var pastDate = new Date(date);
+
+		// Get lasped time in seconds
+		var lapsedTime = Math.round((todayDate.getTime() - pastDate.getTime())/1000)
+
+		// Return lasped time in seconds, minutes, hours, days and weeks
+		if (lapsedTime < 60) {
+			return '< 1 min';
+		} else if (lapsedTime < (60*60)) {
+			var t = Math.round(lapsedTime / 60) - 1;
+			var u = 'min';
+		} else if (lapsedTime < (24*60*60)) {
+			var t = Math.round(lapsedTime / 3600) - 1;
+			var u = 'hour';
+		} else if (lapsedTime < (7*24*60*60)) {
+			var t = Math.round(lapsedTime / 86400) - 1;
+			var u = 'day';
+		} else {
+			var t = Math.round(lapsedTime / 604800) - 1;
+			var u = 'week';
+		}
+		
+		// Check for plural units
+		if (t > 1) u += 's';
+		return t + ' ' + u;
+	}
+
+})(jQuery);

File cmsplugin_feed/templates/cmsplugin_feed/feed_scorrimento.html

+{% load sekizai_tags rss_tags %}
+
+{% random_id as id %}
+
+{% addtoblock "js" %}
+    <script src="{{ STATIC_URL }}cmsplugin_feed/jquery.zrssfeed.js" type="text/javascript"></script>
+    <script src="{{ STATIC_URL }}cmsplugin_feed/jquery.vticker.js" type="text/javascript"></script>
+{% endaddtoblock %}
+
+{% addtoblock "js" %}
+    <script type="text/javascript">
+        (function ($) {
+            $(document).ready(function () {
+                $('#ticker{{id}}').rssfeed(
+                        '{{ instance.feed_url }}',
+                        {
+                            {% if instance.limit %}limit: {{instance.limit}},{% endif %}
+                            header: false,
+                            {% if instance.link_redirect %}linkredirect: '{{ instance.link_redirect }}',{% endif %}
+                            dateformat: 'date',
+                            media: false
+                        },
+                        function (e) {
+                            $(e).find('div.rssBody').vTicker({
+                                showItems: {{ instance.show_items|default:3 }},
+                                height: {{instance.height|default:100}}
+                            });
+                        }
+                );
+            });
+        })(jQuery);
+    </script>
+{% endaddtoblock %}
+
+{% if instance.name %}
+    <h1>{{ instance.name }}</h1>
+{% endif %}
+
+<div id="ticker{{id}}"></div>
+
+<ul>
+    <li>spazio riservato alle nws moreno prova s</li>
+    <li>-</li>
+</ul>

File cmsplugin_feed/templatetags/rss_tags.py

 from datetime import datetime
 from django import template
-import time
+from fancy_tag import fancy_tag
+import time, random
 
 register = template.Library()
 
 @register.filter
 def parsed_to_date(value):
     return datetime(*time.localtime(time.mktime(value))[:6])
+
+
+@fancy_tag(register)
+def random_id():
+    return str(random.random()).replace('.', '')