from gdata.photos.service import PhotosService def get_albums(): pws = PhotosService() uf = pws.GetUserFeed(user = settings.PICASAGALLERY_USER) feed = '{uri}&thumbsize={thumbsize}'.format( uri = uf.GetAlbumsUri(), thumbsize = ALBUM_THUMBSIZE ) print feed return pws.GetFeed(feed).entry def get_photos(album): feed = '{uri}&imgmax={imgmax}&thumbsize={thumbsize}'.format( uri = album.GetPhotosUri(), imgmax = PHOTO_IMGMAXSIZE, thumbsize = PHOTO_THUMBSIZE ) return PhotosService().GetFeed(feed).entry
# Picasagallery settings PICASAGALLERY_USER = 'your_email' PICASAGALLERY_PHOTO_THUMBSIZE = '128' PICASAGALLERY_PHOTO_IMGMAXSIZE = '1024' PICASAGALLERY_ALBUM_THUMBSIZE = '160c'
>>> from picasagallery.utils import get_albums, get_photos >>> my_first_album = get_albums()[0] >>> print my_first_album.title.text # >>> print my_first_album.media.thumbnail[0].url # url https://lh3.googleusercontent.com/-aWPQC60j9zQ/TwCXlTD6CtE/AAAAAAAAAJk/E90Hu9OPiyg/s160-c/FotoLife.jpg >>> my_first_photo = get_photos(my_first_album)[0] >>> print my_first_photo.media.thumbnail[0].url # url https://lh3.googleusercontent.com/-3Hb7VwUTBNg/TwCXlXqdAQI/AAAAAAAAAH8/v8ecBJtjV6k/s128/261799.jpg >>> print my_first_photo.content.src # url , imgmax
from django.shortcuts import render from django.http import Http404 from picasagallery.utils import get_albums, get_photos def gallery(request): albums = get_albums() return render(request, 'picasagallery/gallery.html', {'albums': albums}) def album_list(request, album_id): for album in get_albums(): if album.gphoto_id.text == album_id: photos = get_photos(album) return render(request, 'picasagallery/album.html', {'photos': photos}) raise Http404()
{% extends 'base.html' %} {% load extras %} {% load i18n %} {% block head %} <link rel="stylesheet" href="{{ STATIC_URL }}picasagallery/css/base.css" type="text/css" media="screen" charset="utf-8" /> {% endblock %} {% block content %} {% for album in albums %} <div class='album'> <div class='album-head'> <a href="{% url picasagallery.views.album_list album.GetAlbumId %}" > <img class="album-preview" src="{% thumbnail_url album %}"> </a> </div> <div class="album-name"> <a href="{% url picasagallery.views.album_list album.GetAlbumId %}">{{ album.title.text }}</a> </div> </div> {% endfor %} <p> <a href="/media/picasa_gdata.zip">{% trans 'Download source' %}</a> </p> {% endblock %}
{% extends 'base.html' %} {% load extras %} {% load i18n %} {% block head %} {% include 'picasagallery/pphoto.html' %} <link rel="stylesheet" href="{{ STATIC_URL }}picasagallery/css/base.css" type="text/css" media="screen" charset="utf-8" /> {% endblock %} {% block content %} <a href='{% url picasagallery.views.gallery %}' >{% trans "Back to gallery" %}</a> <p>{% trans "Album:" %} {{ album.title.text }}</p> <div class='gallery'> {% for photo in photos %} <div class='image-preview-div'> <a class='image-preview-link' style='{% thumbnail_style photo %}' rel='gallery-image[pp_gal]' href='{{ photo.content.src }}'> <img class='image-preview-img' style='{% thumbnail_style photo %}' src='{% thumbnail_url photo %}'> </a> </div> {% endfor %} <p> <a href='{{ album.GetHtmlLink.href }}' target='_blank'>{% trans "Show in Google Picasa" %}</a> </p> </div> {% endblock %}
<img ... />
from django.template import Library register = Library() def get_thumbnail(obj): return obj.media.thumbnail[0] @register.simple_tag def thumbnail_url(obj): return get_thumbnail(obj).url @register.simple_tag def thumbnail_style(obj): thumb = get_thumbnail(obj) return 'width: %spx; height: %spx;' % (thumb.width, thumb.height)
{% include 'picasagallery/pphoto.html' %}
Source: https://habr.com/ru/post/139871/
All Articles