From f3339efe0d7ffa1199a113108c0e2f6f6b07afe2 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 3 Feb 2012 15:50:27 +0100 Subject: [PATCH] basic flickr support --- apps/cover/templates/cover/flickr.html | 18 ++++++++++++++ apps/cover/urls.py | 2 ++ apps/cover/views.py | 31 +++++++++++++++++++++++++ redakcja/settings/common.py | 1 + redakcja/static/js/wiki/view_summary.js | 2 ++ 5 files changed, 54 insertions(+) create mode 100644 apps/cover/templates/cover/flickr.html diff --git a/apps/cover/templates/cover/flickr.html b/apps/cover/templates/cover/flickr.html new file mode 100644 index 00000000..fcff1c5c --- /dev/null +++ b/apps/cover/templates/cover/flickr.html @@ -0,0 +1,18 @@ +{% extends "catalogue/base.html" %} + + +{% block content %} +

Flickr

+ +
+{% csrf_token %} +URL: + +
+ + +{% endblock %} diff --git a/apps/cover/urls.py b/apps/cover/urls.py index 24d7448a..5e6ffc54 100644 --- a/apps/cover/urls.py +++ b/apps/cover/urls.py @@ -9,4 +9,6 @@ urlpatterns = patterns('cover.views', 'preview', name='cover_preview'), url(r'^preview/(?P[^/]+)/(?P[^/]+)/(?P\d+)/$', 'preview', name='cover_preview'), + + url(r'^flickr/$', 'flickr'), ) diff --git a/apps/cover/views.py b/apps/cover/views.py index 29fd117a..19d81c22 100644 --- a/apps/cover/views.py +++ b/apps/cover/views.py @@ -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'Some rights reserved', 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'By ([^<]*)', html) + if m: + author = m.group(1) + + url_size = url.rstrip('/') + '/sizes/o/' + html = urlopen(url_size).read() + m = re.search(r'
\s*