basic flickr support
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 3 Feb 2012 14:50:27 +0000 (15:50 +0100)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 3 Feb 2012 14:50:27 +0000 (15:50 +0100)
apps/cover/templates/cover/flickr.html [new file with mode: 0644]
apps/cover/urls.py
apps/cover/views.py
redakcja/settings/common.py
redakcja/static/js/wiki/view_summary.js

diff --git a/apps/cover/templates/cover/flickr.html b/apps/cover/templates/cover/flickr.html
new file mode 100644 (file)
index 0000000..fcff1c5
--- /dev/null
@@ -0,0 +1,18 @@
+{% extends "catalogue/base.html" %}
+
+
+{% block content %}
+<h1>Flickr</h1>
+
+<form method="post">
+{% csrf_token %}
+URL: <input size="50" placeholder="np. http://www.flickr.com/photos/abcdef/1234567890" name="flickr_url" value="{{ url }}"/>
+<input type="submit" value="Generuj metadane" />
+</form>
+
+<textarea style="width:100%" rows="5">
+&lt;dc:relation.coverImage.url xmlns:dc="http://purl.org/dc/elements/1.1/">{{ image_url }}&lt;/dc:relation.coverImage.url>
+&lt;dc:relation.coverImage.attribution xmlns:dc="http://purl.org/dc/elements/1.1/">{{ author }}@Flickr, {{ license_name }}&lt;/dc:relation.coverImage.attribution>
+&lt;dc:relation.coverImage.source xmlns:dc="http://purl.org/dc/elements/1.1/">{{ url }}&lt;/dc:relation.coverImage.source>
+</textarea>
+{% endblock %}
index 24d7448..5e6ffc5 100644 (file)
@@ -9,4 +9,6 @@ urlpatterns = patterns('cover.views',
             'preview', name='cover_preview'),
     url(r'^preview/(?P<book>[^/]+)/(?P<chunk>[^/]+)/(?P<rev>\d+)/$',
             'preview', name='cover_preview'),
+
+    url(r'^flickr/$', 'flickr'),
 )
index 29fd117..19d81c2 100644 (file)
@@ -64,3 +64,34 @@ def preview_from_xml(request):
     image = cover.image().resize(PREVIEW_SIZE, Image.ANTIALIAS)
     image.save(os.path.join(settings.MEDIA_ROOT, fname))
     return HttpResponse(os.path.join(settings.MEDIA_URL, fname))
+
+
+def flickr(request):
+    url = request.POST.get('flickr_url')
+    if url:
+        import re
+        from urllib2 import urlopen
+
+        html = urlopen(url).read()
+        match = re.search(r'<a href="([^"]*)" rel="license cc:license">Some rights reserved</a>', html)
+        if match:
+            license_url = match.group(1)
+
+        re_license = re.compile(r'http://creativecommons.org/licenses/([^/]*)/([^/]*)/.*')
+        m = re_license.match(license_url)
+        if m:
+            license_name = 'CC %s %s' % (m.group(1).upper(), m.group(2))
+
+        m = re.search(r'<strong class="username">By <a href="[^"]*">([^<]*)</a></strong>', html)
+        if m:
+            author = m.group(1)
+
+        url_size = url.rstrip('/') + '/sizes/o/'
+        html = urlopen(url_size).read()
+        m = re.search(r'<div id="allsizes-photo">\s*<img src="([^"]*)"', html)
+        if m:
+            image_url = m.group(1)
+    else:
+        url = ""
+
+    return render(request, 'cover/flickr.html', locals())
index 1e16bb1..f6b889d 100644 (file)
@@ -118,6 +118,7 @@ INSTALLED_APPS = (
     'djkombu',
 
     'catalogue',
+    'cover',
     'dvcs',
     'wiki',
     'toolbar',
index 8fdf4b9..099a0e8 100644 (file)
     SummaryPerspective.prototype = new $.wiki.Perspective();
 
        SummaryPerspective.prototype.refreshCover = function() {
+               $('#summary-cover-refresh').attr('disabled', 'disabled');
                this.doc.refreshCover({
                        success: function(text) {
                                $('#summary-cover').attr('src', text);
+                       $('#summary-cover-refresh').removeAttr('disabled');
                        }
                });
        };