--- /dev/null
+{% 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">
+<dc:relation.coverImage.url xmlns:dc="http://purl.org/dc/elements/1.1/">{{ image_url }}</dc:relation.coverImage.url>
+<dc:relation.coverImage.attribution xmlns:dc="http://purl.org/dc/elements/1.1/">{{ author }}@Flickr, {{ license_name }}</dc:relation.coverImage.attribution>
+<dc:relation.coverImage.source xmlns:dc="http://purl.org/dc/elements/1.1/">{{ url }}</dc:relation.coverImage.source>
+</textarea>
+{% endblock %}
'preview', name='cover_preview'),
url(r'^preview/(?P<book>[^/]+)/(?P<chunk>[^/]+)/(?P<rev>\d+)/$',
'preview', name='cover_preview'),
+
+ url(r'^flickr/$', 'flickr'),
)
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())
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');
}
});
};