Skip to content
Browse files

Change buttons so that entering the url to like/share is always optio…

…nal.
  • Loading branch information...
1 parent 61d15bb commit 61c34c00161a5826f28d573ac0bf5ff023083034 @richardbarran richardbarran committed Aug 9, 2012
View
5 cmsplugin_facebook/cms_plugins.py
@@ -6,7 +6,10 @@ class BasePlugin(CMSPluginBase):
name = None
def render(self, context, instance, placeholder):
- context.update({'instance': instance, 'name': self.name})
+ context.update({'instance': instance,
+ 'name': self.name,
+ 'url': instance.pageurl or \
+ context['request'].build_absolute_uri()})
return context
class FacebookLikeBoxPlugin(BasePlugin):
View
79 ...migrations/0003_auto__chg_field_facebooklikebox_pageurl__chg_field_facebooklikebutton_.py
@@ -0,0 +1,79 @@
+# -*- 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):
+
+ # Changing field 'FacebookLikeBox.pageurl'
+ db.alter_column('cmsplugin_facebooklikebox', 'pageurl', self.gf('django.db.models.fields.URLField')(max_length=200, null=True))
+
+ # Changing field 'FacebookLikeButton.pageurl'
+ db.alter_column('cmsplugin_facebooklikebutton', 'pageurl', self.gf('django.db.models.fields.URLField')(max_length=200, null=True))
+
+ def backwards(self, orm):
+
+ # User chose to not deal with backwards NULL issues for 'FacebookLikeBox.pageurl'
+ raise RuntimeError("Cannot reverse this migration. 'FacebookLikeBox.pageurl' and its values cannot be restored.")
+
+ # User chose to not deal with backwards NULL issues for 'FacebookLikeButton.pageurl'
+ raise RuntimeError("Cannot reverse this migration. 'FacebookLikeButton.pageurl' and its values cannot be restored.")
+
+ models = {
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ '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_facebook.facebooklikebox': {
+ 'Meta': {'object_name': 'FacebookLikeBox', 'db_table': "'cmsplugin_facebooklikebox'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'connections': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '10'}),
+ 'header': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '587'}),
+ 'pageurl': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'stream': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'transparent': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'})
+ },
+ 'cmsplugin_facebook.facebooklikebutton': {
+ 'Meta': {'object_name': 'FacebookLikeButton', 'db_table': "'cmsplugin_facebooklikebutton'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'color_scheme': ('django.db.models.fields.CharField', [], {'default': "'light'", 'max_length': '50'}),
+ 'font': ('django.db.models.fields.CharField', [], {'default': "'verdana'", 'max_length': '50'}),
+ 'height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '80'}),
+ 'layout': ('django.db.models.fields.CharField', [], {'default': "'standard'", 'max_length': '50'}),
+ 'pageurl': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'show_faces': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'verb': ('django.db.models.fields.CharField', [], {'default': "'like'", 'max_length': '50'}),
+ 'width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'})
+ },
+ 'cmsplugin_facebook.facebooksharebutton': {
+ 'Meta': {'object_name': 'FacebookShareButton', 'db_table': "'cmsplugin_facebooksharebutton'", '_ormbases': ['cms.CMSPlugin']},
+ 'button_text': ('django.db.models.fields.CharField', [], {'default': "u'Share'", 'max_length': '255'}),
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'share_url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'style': ('django.db.models.fields.CharField', [], {'max_length': '12'})
+ }
+ }
+
+ complete_apps = ['cmsplugin_facebook']
View
69 ...migrations/0004_auto__del_field_facebooksharebutton_share_url__add_field_facebookshare.py
@@ -0,0 +1,69 @@
+# -*- 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):
+ db.rename_column('cmsplugin_facebooksharebutton', 'share_url', 'pageurl')
+
+ def backwards(self, orm):
+ db.rename_column('cmsplugin_facebooksharebutton', 'pageurl', 'share_url')
+
+ models = {
+ 'cms.cmsplugin': {
+ 'Meta': {'object_name': 'CMSPlugin'},
+ '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_facebook.facebooklikebox': {
+ 'Meta': {'object_name': 'FacebookLikeBox', 'db_table': "'cmsplugin_facebooklikebox'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'connections': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '10'}),
+ 'header': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '587'}),
+ 'pageurl': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'stream': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'transparent': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'})
+ },
+ 'cmsplugin_facebook.facebooklikebutton': {
+ 'Meta': {'object_name': 'FacebookLikeButton', 'db_table': "'cmsplugin_facebooklikebutton'", '_ormbases': ['cms.CMSPlugin']},
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'color_scheme': ('django.db.models.fields.CharField', [], {'default': "'light'", 'max_length': '50'}),
+ 'font': ('django.db.models.fields.CharField', [], {'default': "'verdana'", 'max_length': '50'}),
+ 'height': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '80'}),
+ 'layout': ('django.db.models.fields.CharField', [], {'default': "'standard'", 'max_length': '50'}),
+ 'pageurl': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'show_faces': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'verb': ('django.db.models.fields.CharField', [], {'default': "'like'", 'max_length': '50'}),
+ 'width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'})
+ },
+ 'cmsplugin_facebook.facebooksharebutton': {
+ 'Meta': {'object_name': 'FacebookShareButton', 'db_table': "'cmsplugin_facebooksharebutton'", '_ormbases': ['cms.CMSPlugin']},
+ 'button_text': ('django.db.models.fields.CharField', [], {'default': "u'Share'", 'max_length': '255'}),
+ 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
+ 'pageurl': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}),
+ 'style': ('django.db.models.fields.CharField', [], {'max_length': '12'})
+ }
+ }
+
+ complete_apps = ['cmsplugin_facebook']
View
8 cmsplugin_facebook/models.py
@@ -36,13 +36,14 @@
class FacebookShareButton(CMSPlugin):
style = models.CharField(max_length=12, choices=SHARE_BUTTON_STYLES)
- share_url = models.URLField(_("URL to share"), help_text=_("If blank, the page where it's displayed will be used"),
+ pageurl = models.URLField(_("URL to share"), help_text=_("If blank, the page where it's displayed will be used"),
null=True, blank=True)
button_text = models.CharField(_("Button text"), help_text=_("This text will be displayed in the \"Share\" button"),
max_length=255, default=_("Share"))
class FacebookLikeBox(CMSPlugin):
- pageurl = models.URLField(_("URL to like"))
+ pageurl = models.URLField(_("URL to like"), help_text=_("If blank, the page where it's displayed will be used"),
+ null=True, blank=True)
width = models.PositiveSmallIntegerField(_("Width"), default=None, null=True,
blank=True, help_text=_("Leave empty for auto scaling"))
height = models.PositiveSmallIntegerField(_("Height"), default=587)
@@ -69,7 +70,8 @@ def __unicode__(self):
class FacebookLikeButton(CMSPlugin):
- pageurl = models.URLField(_("URL to like"))
+ pageurl = models.URLField(_("URL to like"), help_text=_("If blank, the page where it's displayed will be used"),
+ null=True, blank=True)
layout = models.CharField(_("Layout Style"), choices=LAYOUT_CHOICES, default="standard", max_length=50)
show_faces = models.BooleanField(_("Show Faces"), default=True,
help_text=_("Show profile pictures below the like button"))
View
2 cmsplugin_facebook/templates/cmsplugin_facebook/likebox.html
@@ -17,7 +17,7 @@
</iframe> -->
{% endcomment %}
{% spaceless %}
-<iframe src="http://www.facebook.com/plugins/likebox.php?href={% autoescape on %}{{ instance.pageurl }}{% endautoescape %}&amp;width={% if instance.width %}{{ instance.width }}{% else %}{{ width|default:295 }}{% endif %}&amp;connections={{ instance.connections }}&amp;stream={% if instance.stream %}true{% else %}false{% endif %}&amp;header={% if instance.header %}true{% else %}false{% endif %}&amp;height={{ instance.height }}"
+<iframe src="http://www.facebook.com/plugins/likebox.php?href={% autoescape on %}{{ url }}{% endautoescape %}&amp;width={% if instance.width %}{{ instance.width }}{% else %}{{ width|default:295 }}{% endif %}&amp;connections={{ instance.connections }}&amp;stream={% if instance.stream %}true{% else %}false{% endif %}&amp;header={% if instance.header %}true{% else %}false{% endif %}&amp;height={{ instance.height }}"
scrolling="no"
frameborder="0"
style="border:none;overflow:hidden;width:{% if instance.width %}{{ instance.width }}{% else %}{{ width|default:295 }}{% endif %}px;height:{{ instance.height }}px;"
View
2 cmsplugin_facebook/templates/cmsplugin_facebook/likebutton.html
@@ -15,7 +15,7 @@
</iframe> -->
{% endcomment %}
{% spaceless %}
-<iframe src="http://www.facebook.com/plugins/like.php?href={% autoescape on %}{{ instance.pageurl }}{% endautoescape %}&amp;layout={% if instance.layout %}{{instance.layout}}{% endif %}&amp;show_faces={{instance.show_faces}}&amp;width={% if instance.width %}{{ instance.width }}{% else %}{{ width|default:295 }}{% endif %}&amp;height={{ instance.height }}&amp;action=like&amp;colorscheme=light"
+<iframe src="http://www.facebook.com/plugins/like.php?href={% autoescape on %}{{ url }}{% endautoescape %}&amp;layout={% if instance.layout %}{{instance.layout}}{% endif %}&amp;show_faces={{instance.show_faces}}&amp;width={% if instance.width %}{{ instance.width }}{% else %}{{ width|default:295 }}{% endif %}&amp;height={{ instance.height }}&amp;action=like&amp;colorscheme=light"
frameborder="0"
style="border:none;overflow:hidden; width:{% if instance.width %}{{ instance.width }}{% else %}{{ width|default:295 }}{% endif %}px; height:{{ instance.height }}px;"
allowTransparency="true">
View
2 cmsplugin_facebook/templates/cmsplugin_facebook/sharebutton.html
@@ -9,6 +9,6 @@
{{ instance.style }} can be "button", "button_count" or "box_count" (box_count is above, button_count is inline)
{% endcomment %}
{% spaceless %}
-<a name="fb_share" type="{{ instance.style }}" href="http://www.facebook.com/sharer.php"{% if instance.share_url %} share_url="{{ instance.share_url }}"{% endif %}>{{ instance.button_text }}</a>
+<a name="fb_share" type="{{ instance.style }}" href="http://www.facebook.com/sharer.php"{% if url %} share_url="{{ url }}"{% endif %}>{{ instance.button_text }}</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
{% endspaceless %}

0 comments on commit 61c34c0

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