summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chimere/templates/chimere/blocks/share_bar.html39
-rw-r--r--chimere/templates/chimere/detail.html11
-rw-r--r--chimere/templatetags/chimere_tags.py9
-rw-r--r--chimere/urls.py2
-rw-r--r--chimere/views.py13
5 files changed, 64 insertions, 10 deletions
diff --git a/chimere/templates/chimere/blocks/share_bar.html b/chimere/templates/chimere/blocks/share_bar.html
new file mode 100644
index 0000000..e421a0f
--- /dev/null
+++ b/chimere/templates/chimere/blocks/share_bar.html
@@ -0,0 +1,39 @@
+{% load i18n %}
+ {% if share_networks %}
+ {% if simple %}{% trans "Share on"%}{% for share_network in share_networks %}
+ <a href='{{share_network.1}}'>{{share_network.0}}</a>
+ {% endfor %}{%else%}
+ <ul class='share'>
+ <li>{% trans "Share"%}</li>{% for share_network in share_networks %}
+ <li><a class='share_link share_id_{{share_network.0}}' href='{{share_network.1}}'><img src="{{share_network.2}}" alt="{{share_network.0}}"/></a></li>
+ {% endfor %}</ul>{% endif %}
+ <script language='text/javascript'>
+ $(function(){
+ $('.share_link').click(function(){
+ var href = $(this).attr('href');
+ var url = '{% url chimere:get-share-url %}';
+ var classes = $(this).attr('class').split(' ');
+ prefix = 'share_id_';
+ var share_id;
+ for (idx=0;idx<classes.length;idx++){
+ if(classes[idx].substring(0, prefix.length) == prefix){
+ var share_id = classes[idx].substring(prefix.length);
+ }
+ }
+ var params = $('#permalink a').attr('href').split('/');
+ url += share_id + params[params.length-1];
+ $.ajax({url: url,
+ dataType: "html",
+ success: function (url) {
+ window.open(url);
+ return false;
+ },
+ error: function(){
+ return false;
+ }
+ });
+ return false;
+ });
+ });
+ </script>
+ {% endif %}
diff --git a/chimere/templates/chimere/detail.html b/chimere/templates/chimere/detail.html
index 2bd55aa..94270cb 100644
--- a/chimere/templates/chimere/detail.html
+++ b/chimere/templates/chimere/detail.html
@@ -25,21 +25,14 @@
{% if marker.multimedia_items %}
<a href='#' id='show_gallery_link'>{% trans "Show multimedia gallery" %}</a>
{% endif %}
- </div>{% if share_networks %}
- {% if simple %}{% trans "Share on"%}{% for share_network in share_networks %}
- <a href='{{share_network.1}}'>{{share_network.0}}</a>
- {% endfor %}{%else%}
- <ul class='share'>
- <li>{% trans "Share"%}</li>{% for share_network in share_networks %}
- <li><a href='{{share_network.1}}'><img src="{{share_network.2}}" alt="{{share_network.0}}"/></a></li>
- {% endfor %}</ul>{% endif %}
+ </div>
+ {% share_bar marker.name %}
<a href="{{modif_by_email}}">{% trans "Propose a modification" %}</a>
{% comment %}
<a href='{% if marker.route %}{% url chimere:editroute-item area_name_slash|default_if_none:"" marker.route.pk "" %}{%else%}{% url chimere:edit-item area_name_slash|default_if_none:"" marker.pk "" %}{%endif%}'>
{% trans "Submit a modification" %}
</a>
{% endcomment %}
-{% endif %}
</div>
{% if marker.multimedia_items %}
<div id='gallery-{{marker.pk}}' class='gallery'>
diff --git a/chimere/templatetags/chimere_tags.py b/chimere/templatetags/chimere_tags.py
index 88827a8..35861e1 100644
--- a/chimere/templatetags/chimere_tags.py
+++ b/chimere/templatetags/chimere_tags.py
@@ -10,6 +10,7 @@ from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Q
+from django.template import defaultfilters
from django.utils.translation import ugettext as _
from chimere.models import Marker, Area, News, SubCategory, MultimediaType
@@ -249,3 +250,11 @@ def get_tinyfied_url(marker, area_name=''):
return ""
url = marker.get_absolute_url(area_name)
return url
+
+@register.inclusion_tag('chimere/blocks/share_bar.html',
+ takes_context=True)
+def share_bar(context, name=''):
+ context['name'] = name
+ context['share_networks'] = [(defaultfilters.slugify(name), url, icon)
+ for name, url, icon in settings.CHIMERE_SHARE_NETWORKS]
+ return context
diff --git a/chimere/urls.py b/chimere/urls.py
index 2e40a5d..d6ef9b9 100644
--- a/chimere/urls.py
+++ b/chimere/urls.py
@@ -85,6 +85,8 @@ urlpatterns += patterns('chimere.views',
'get_available_categories', name="get_categories"),
url(r'^(?P<area_name>[a-zA-Z0-9_-]+/)?getCategory/(?P<category_id>\d+)/?$',
'getCategory', name="get_category"),
+ url(r'^(?P<area_name>[a-zA-Z0-9_-]*/)?get-share-url/(?P<network>\w+)?$',
+ 'getShareUrl', name="get-share-url"),
url(r'^(?P<area_name>[a-zA-Z0-9_-]*/)?ty/(?P<tiny_urn>\w+)$',
'redirectFromTinyURN', name="tiny"),
url(r'^(?P<area_name>[a-zA-Z0-9_-]+/)?upload_file/((?P<category_id>\w+)/)?$',
diff --git a/chimere/views.py b/chimere/views.py
index 20b4bd2..278ae22 100644
--- a/chimere/views.py
+++ b/chimere/views.py
@@ -35,7 +35,7 @@ from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import redirect, render_to_response
-from django.template import loader, RequestContext
+from django.template import loader, RequestContext, defaultfilters
from django.utils import simplejson
from django.utils.http import urlquote
from django.utils.translation import ugettext as _
@@ -104,6 +104,17 @@ def get_base_response(area_name=""):
base_response_dct['JQUERY_CSS_URLS'] = settings.JQUERY_CSS_URLS
return base_response_dct, None
+def getShareUrl(request, area_name='', network=''):
+ """
+ Get a share url
+ """
+ data = getTinyfiedUrl(request, request.GET.urlencode(), area_name)
+ print data
+ for name, url, img in settings.CHIMERE_SHARE_NETWORKS:
+ if defaultfilters.slugify(name) == network:
+ return HttpResponse(url % {'text':data['text'], 'url':data['url']})
+ return HttpResponse('')
+
def getShareNetwork(request, area_name='', marker=None):
"""
Get URLs to share items