Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tabs -> Spaces

  • Loading branch information...
commit f889aeb90fc3b707b6361b83534dba9785e27153 1 parent c7ca308
@streeter streeter authored
View
4 admin.py
@@ -6,7 +6,7 @@
application = webapp.WSGIApplication([('.*', AdminPage)], debug=settings.DEBUG)
def main():
- run_wsgi_app(application)
+ run_wsgi_app(application)
if __name__ == "__main__":
- main()
+ main()
View
38 base.html
@@ -58,25 +58,25 @@
<!-- lightbox javascript -->
<script type="text/javascript">
- $(document).ready(function() {
- $('a.lightbox').lightBox({
- 'imageLoading': '/images/lightbox-ico-loading.gif',
- 'imageBtnClose': '/images/lightbox-btn-close.gif',
- 'imageBtnNext': '/images/lightbox-btn-next.gif',
- 'imageBtnPrev': '/images/lightbox-btn-prev.gif',
- 'imageBlank': '/images/lightbox-blank.gif',
- });
-
- if (document.location.hash) {
- $(''+document.location.hash).click();
- }
-
- window.setTimeout(function() {
- $('.message').fadeOut(800, function() {
- $(this).remove();
- });
- }, 2000);
- });
+ $(document).ready(function() {
+ $('a.lightbox').lightBox({
+ 'imageLoading': '/images/lightbox-ico-loading.gif',
+ 'imageBtnClose': '/images/lightbox-btn-close.gif',
+ 'imageBtnNext': '/images/lightbox-btn-next.gif',
+ 'imageBtnPrev': '/images/lightbox-btn-prev.gif',
+ 'imageBlank': '/images/lightbox-blank.gif',
+ });
+
+ if (document.location.hash) {
+ $(''+document.location.hash).click();
+ }
+
+ window.setTimeout(function() {
+ $('.message').fadeOut(800, function() {
+ $(this).remove();
+ });
+ }, 2000);
+ });
</script>
<!-- end lightbox javascript -->
View
54 css/gallery.css
@@ -54,7 +54,7 @@ body {
#nav-title .lightgray {
- color: #CCCCCC;
+ color: #CCCCCC;
}
#nav a:hover {
@@ -80,59 +80,59 @@ body {
}
#lightbox-nav {
- display: none;
+ display: none;
}
.product-attr-name {
- font-size: 1.2em;
- padding-bottom: 10px;
+ font-size: 1.2em;
+ padding-bottom: 10px;
}
/*****************************************************************************
* Utilities
*/
.clearfix {
- clear: both;
+ clear: both;
}
.success,
.error {
- border: 1px solid #BBB;
- border-bottom-left-radius: 6px 6px;
- border-bottom-right-radius: 6px 6px;
- border-top-left-radius: 6px 6px;
- border-top-right-radius: 6px 6px;
- margin: 1em 0px;
- padding: 0.99em;
- text-align: center;
- color: #999;
+ border: 1px solid #BBB;
+ border-bottom-left-radius: 6px 6px;
+ border-bottom-right-radius: 6px 6px;
+ border-top-left-radius: 6px 6px;
+ border-top-right-radius: 6px 6px;
+ margin: 1em 0px;
+ padding: 0.99em;
+ text-align: center;
+ color: #999;
}
.success {
- border-color: #FCEFA1;
- background-color: #FBF9EE;
+ border-color: #FCEFA1;
+ background-color: #FBF9EE;
}
.error {
- border-color: #CD0A0A;
- background-color: #FEF1EC;
+ border-color: #CD0A0A;
+ background-color: #FEF1EC;
}
#admin-form {
- border: 1px solid #BBB;
- border-bottom-left-radius: 6px 6px;
- border-bottom-right-radius: 6px 6px;
- border-top-left-radius: 6px 6px;
- border-top-right-radius: 6px 6px;
- padding: 0.99em;
+ border: 1px solid #BBB;
+ border-bottom-left-radius: 6px 6px;
+ border-bottom-right-radius: 6px 6px;
+ border-top-left-radius: 6px 6px;
+ border-top-right-radius: 6px 6px;
+ padding: 0.99em;
}
.admin-option {
- color: #999;
- margin: 5px 0;
+ color: #999;
+ margin: 5px 0;
}
.admin-option input[type="checkbox"] {
- margin-left: 4em
+ margin-left: 4em
}
/*****************************************************************************
View
118 css/jquery.lightbox-0.5.css
@@ -12,90 +12,90 @@
* @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
*/
#jquery-overlay {
- position: absolute;
- top: 0;
- left: 0;
- z-index: 90;
- width: 100%;
- height: 500px;
+ position: absolute;
+ top: 0;
+ left: 0;
+ z-index: 90;
+ width: 100%;
+ height: 500px;
}
#jquery-lightbox {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- z-index: 100;
- text-align: center;
- line-height: 0;
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ z-index: 100;
+ text-align: center;
+ line-height: 0;
}
#jquery-lightbox a img { border: none; }
#lightbox-container-image-box {
- position: relative;
- background-color: #fff;
- width: 250px;
- height: 250px;
- margin: 0 auto;
+ position: relative;
+ background-color: #fff;
+ width: 250px;
+ height: 250px;
+ margin: 0 auto;
}
#lightbox-container-image { padding: 10px; }
#lightbox-loading {
- position: absolute;
- top: 40%;
- left: 0%;
- height: 25%;
- width: 100%;
- text-align: center;
- line-height: 0;
+ position: absolute;
+ top: 40%;
+ left: 0%;
+ height: 25%;
+ width: 100%;
+ text-align: center;
+ line-height: 0;
}
#lightbox-nav {
- position: absolute;
- top: 0;
- left: 0;
- height: 100%;
- width: 100%;
- z-index: 10;
+ position: absolute;
+ top: 0;
+ left: 0;
+ height: 100%;
+ width: 100%;
+ z-index: 10;
}
#lightbox-container-image-box > #lightbox-nav { left: 0; }
#lightbox-nav a { outline: none;}
#lightbox-nav-btnPrev, #lightbox-nav-btnNext {
- width: 49%;
- height: 100%;
- zoom: 1;
- display: block;
+ width: 49%;
+ height: 100%;
+ zoom: 1;
+ display: block;
}
#lightbox-nav-btnPrev {
- left: 0;
- float: left;
+ left: 0;
+ float: left;
}
#lightbox-nav-btnNext {
- right: 0;
- float: right;
+ right: 0;
+ float: right;
}
#lightbox-container-image-data-box {
- font: 10px Verdana, Helvetica, sans-serif;
- background-color: #fff;
- margin: 0 auto;
- line-height: 1.4em;
- overflow: auto;
- width: 100%;
- padding: 0 10px 0;
+ font: 10px Verdana, Helvetica, sans-serif;
+ background-color: #fff;
+ margin: 0 auto;
+ line-height: 1.4em;
+ overflow: auto;
+ width: 100%;
+ padding: 0 10px 0;
}
#lightbox-container-image-data {
- padding: 0 10px;
- color: #666;
+ padding: 0 10px;
+ color: #666;
}
#lightbox-container-image-data #lightbox-image-details {
- width: 70%;
- float: left;
- text-align: left;
-}
+ width: 70%;
+ float: left;
+ text-align: left;
+}
#lightbox-image-details-caption { font-weight: bold; }
#lightbox-image-details-currentNumber {
- display: block;
- clear: left;
- padding-bottom: 1.0em;
-}
+ display: block;
+ clear: left;
+ padding-bottom: 1.0em;
+}
#lightbox-secNav-btnClose {
- width: 66px;
- float: right;
- padding-bottom: 0.7em;
+ width: 66px;
+ float: right;
+ padding-bottom: 0.7em;
}
View
14 flickr.py
@@ -643,7 +643,7 @@ def photos_search_pages(user_id='', auth=False, tags='', tag_mode='', text='',\
license='', per_page='', page='', sort=''):
"""Returns the number of pages for the previous function (photos_search())
"""
-
+
method = 'flickr.photos.search'
data = _doget(method, auth=auth, user_id=user_id, tags=tags, text=text,\
@@ -653,11 +653,11 @@ def photos_search_pages(user_id='', auth=False, tags='', tag_mode='', text='',\
max_taken_date=max_taken_date, \
license=license, per_page=per_page,\
page=page, sort=sort)
-
+
return data.rsp.photos.pages
-
-
-
+
+
+
#XXX: Could be class method in User
def people_findByEmail(email):
"""Returns User object."""
@@ -844,7 +844,7 @@ def _doget(method, auth=False, **params):
from google.appengine.api import memcache
result = memcache.get(url)
if result:
- return result
+ return result
result = urlopen(url).read()
memcache.set(url, result)
@@ -1023,7 +1023,7 @@ def getList(self,auth=True):
return "Unknown error!"
except AttributeError:
return "There are no blogs!"
-
+
myReturn = [bID,bName,bNeedsPword,bURL]
return myReturn
View
14 index.html
@@ -9,13 +9,13 @@
{% for photo in photos %}
<a photoid="{{ photo.id }}"
- class="thumb lightbox"
- style="width:{{ user.thumb_size }}; height:{{ user.thumb_size }};"
- title="{{ photo.name }}"
- href="{{ photo.url }}"
- thumb="{{ photo.thumb_url }}"
- height="{{ photo.height }}"
- width="{{ photo.width }}">
+ class="thumb lightbox"
+ style="width:{{ user.thumb_size }}; height:{{ user.thumb_size }};"
+ title="{{ photo.name }}"
+ href="{{ photo.url }}"
+ thumb="{{ photo.thumb_url }}"
+ height="{{ photo.height }}"
+ width="{{ photo.width }}">
<span><img border="0" title="{{ photo.name }}" alt="{{ photo.name }}" src="{{ photo.thumb_url }}" {%comment%}height="72" width="72"{%endcomment%} /></span>
</a>
{% endfor %}
View
538 models.py
@@ -5,280 +5,280 @@
from google.appengine.api import memcache
class PhotoBackend():
-
- user_id = None
- thumb_size = 72
- imgmax = 640
- thumb_cropped = True
-
- def __init__(self, user):
- self.user_id = user.GetUsername()
- self.thumb_size = user.thumb_size
- self.imgmax = user.full_size
- self.thumb_cropped = user.thumb_cropped
-
-
- def GetAllAlbums(self):
- return []
-
- def GetFeaturedAlbums(self, featured=[]):
- albums = self.GetAllAlbums()
- featured_albums = []
- for album in albums:
- if album['title'] not in featured:
- continue
-
- featured_albums.append(album)
-
- if 'all' in featured:
- featured_albums.append({'id': 'all', 'title': 'all'})
-
- return featured_albums
-
- def GetPhotosInAlbum(self, album, featured=[]):
- return []
-
- def GetSinglePhoto(self, album, photo_id):
- return None
-
- def CacheGet(self, key):
- if not settings.MEMCACHE_ENABLED or not key:
- return None
- return memcache.get(key)
-
- def CacheSet(self, key, value):
- if not settings.MEMCACHE_ENABLED or not key:
- return True
- return memcache.set(key, value)
-
- def CacheClear(self):
- pass
-
+
+ user_id = None
+ thumb_size = 72
+ imgmax = 640
+ thumb_cropped = True
+
+ def __init__(self, user):
+ self.user_id = user.GetUsername()
+ self.thumb_size = user.thumb_size
+ self.imgmax = user.full_size
+ self.thumb_cropped = user.thumb_cropped
+
+
+ def GetAllAlbums(self):
+ return []
+
+ def GetFeaturedAlbums(self, featured=[]):
+ albums = self.GetAllAlbums()
+ featured_albums = []
+ for album in albums:
+ if album['title'] not in featured:
+ continue
+
+ featured_albums.append(album)
+
+ if 'all' in featured:
+ featured_albums.append({'id': 'all', 'title': 'all'})
+
+ return featured_albums
+
+ def GetPhotosInAlbum(self, album, featured=[]):
+ return []
+
+ def GetSinglePhoto(self, album, photo_id):
+ return None
+
+ def CacheGet(self, key):
+ if not settings.MEMCACHE_ENABLED or not key:
+ return None
+ return memcache.get(key)
+
+ def CacheSet(self, key, value):
+ if not settings.MEMCACHE_ENABLED or not key:
+ return True
+ return memcache.set(key, value)
+
+ def CacheClear(self):
+ pass
+
class PicasaBackend(PhotoBackend):
- gdata = None
-
- ALBUM_FEED_URI = '/data/feed/api/user/%s/album/%s?kind=photo&thumbsize=%s&imgmax=%s'
-
- def __init__(self, user):
- PhotoBackend.__init__(self, user)
-
- import gdata.photos.service
- import gdata.alt.appengine
-
- self.gdata = gdata.photos.service.PhotosService()
- gdata.alt.appengine.run_on_appengine(self.gdata)
-
- def GetAllAlbums(self):
- logging.info('GetAllAlbums called')
-
- # check memcache
- key = 'picasa_albums'
- albums = self.CacheGet(key)
- if albums:
- return albums
-
- albums = []
- albums_feed = self.gdata.GetUserFeed(user=self.user_id, kind='album')
- for album in albums_feed.entry:
- albums.append({
- 'id': album.gphoto_id.text,
- 'title': album.title.text,
- })
-
- # set memcache
- self.CacheSet(key, albums)
-
- return albums
-
- def GetPhotosInAlbum(self, album, featured=[]):
- logging.info('GetPhotosInAlbum called')
- if self.thumb_cropped:
- thumb_size = "%dc" % self.thumb_size
- else:
- thumb_size = "%du" % self.thumb_size
-
- # check memcache
- key = "picasa_album_%s_%s_%s" % (album, thumb_size, self.imgmax)
- photos = self.CacheGet(key)
- if photos:
- return photos
-
- photos = []
- albums = []
- if album == 'all':
- all_albums = self.GetFeaturedAlbums(featured)
- for a in all_albums:
- albums.append(a['title'])
- else:
- albums.append(album)
-
- logging.info('Got albums %s' % str(albums))
-
- for a in albums:
- feed = self.ALBUM_FEED_URI % (self.user_id, a, thumb_size, self.imgmax)
- logging.info('GetPhotosInAlbum feed is %s' % feed)
- try:
- photos_feed = self.gdata.GetFeed(feed)
- for photo in photos_feed.entry:
- pic = {
- 'id': photo.gphoto_id.text,
- 'height': photo.width.text,
- 'width': photo.height.text,
- 'thumb_url': photo.media.thumbnail[0].url,
- 'url': photo.media.content[0].url,
- 'name': photo.title.text,
- }
- photos.append(pic)
- except:
- pass
-
- # set memcache
- self.CacheSet(key, photos)
-
- return photos
-
- def CacheClear(self):
- keys = []
- albums = self.GetAllAlbums()
- for a in albums:
- keys.append("picasa_album_%s_%sc_%s" % (album['title'], self.thumb_size, self.imgmax))
- keys.append("picasa_album_%s_%su_%s" % (album['title'], self.thumb_size, self.imgmax))
- albums.append('picasa_albums')
- memcache.delete_multi(keys)
+ gdata = None
+
+ ALBUM_FEED_URI = '/data/feed/api/user/%s/album/%s?kind=photo&thumbsize=%s&imgmax=%s'
+
+ def __init__(self, user):
+ PhotoBackend.__init__(self, user)
+
+ import gdata.photos.service
+ import gdata.alt.appengine
+
+ self.gdata = gdata.photos.service.PhotosService()
+ gdata.alt.appengine.run_on_appengine(self.gdata)
+
+ def GetAllAlbums(self):
+ logging.info('GetAllAlbums called')
+
+ # check memcache
+ key = 'picasa_albums'
+ albums = self.CacheGet(key)
+ if albums:
+ return albums
+
+ albums = []
+ albums_feed = self.gdata.GetUserFeed(user=self.user_id, kind='album')
+ for album in albums_feed.entry:
+ albums.append({
+ 'id': album.gphoto_id.text,
+ 'title': album.title.text,
+ })
+
+ # set memcache
+ self.CacheSet(key, albums)
+
+ return albums
+
+ def GetPhotosInAlbum(self, album, featured=[]):
+ logging.info('GetPhotosInAlbum called')
+ if self.thumb_cropped:
+ thumb_size = "%dc" % self.thumb_size
+ else:
+ thumb_size = "%du" % self.thumb_size
+
+ # check memcache
+ key = "picasa_album_%s_%s_%s" % (album, thumb_size, self.imgmax)
+ photos = self.CacheGet(key)
+ if photos:
+ return photos
+
+ photos = []
+ albums = []
+ if album == 'all':
+ all_albums = self.GetFeaturedAlbums(featured)
+ for a in all_albums:
+ albums.append(a['title'])
+ else:
+ albums.append(album)
+
+ logging.info('Got albums %s' % str(albums))
+
+ for a in albums:
+ feed = self.ALBUM_FEED_URI % (self.user_id, a, thumb_size, self.imgmax)
+ logging.info('GetPhotosInAlbum feed is %s' % feed)
+ try:
+ photos_feed = self.gdata.GetFeed(feed)
+ for photo in photos_feed.entry:
+ pic = {
+ 'id': photo.gphoto_id.text,
+ 'height': photo.width.text,
+ 'width': photo.height.text,
+ 'thumb_url': photo.media.thumbnail[0].url,
+ 'url': photo.media.content[0].url,
+ 'name': photo.title.text,
+ }
+ photos.append(pic)
+ except:
+ pass
+
+ # set memcache
+ self.CacheSet(key, photos)
+
+ return photos
+
+ def CacheClear(self):
+ keys = []
+ albums = self.GetAllAlbums()
+ for a in albums:
+ keys.append("picasa_album_%s_%sc_%s" % (album['title'], self.thumb_size, self.imgmax))
+ keys.append("picasa_album_%s_%su_%s" % (album['title'], self.thumb_size, self.imgmax))
+ albums.append('picasa_albums')
+ memcache.delete_multi(keys)
class FlickrBackend(PhotoBackend):
- flickr = None
-
- def __init__(self, user):
- PhotoBackend.__init__(self, user)
-
- flickr.API_KEY = '36fbcb5322bdab1866dff9622f161400'
-
- self.flickr = flickr.User(self.user_id)
-
- def GetAllAlbums(self):
- logging.info('GetAllAlbums called')
-
- # check memcache
- key = 'flickr_albums'
- albums = self.CacheGet(key)
- if albums:
- return albums
-
- albums = []
- sets = self.flickr.getPhotosets()
- for s in sets:
- albums.append({
- 'id': s.id,
- 'title': s.title,
- })
-
- # set memcache
- self.CacheSet(key, albums)
-
- return albums
-
- def GetPhotosInAlbum(self, album, featured=[]):
- logging.info('GetPhotosInAlbum called')
- if self.thumb_cropped:
- thumb_size = "Square"
- else:
- thumb_size = "Thumbnail"
-
- if self.imgmax < 600:
- img_size = "Medium"
- else:
- img_size = "Large"
-
- # check memcache
- key = "album_%s_%s_%s" % (album, thumb_size, img_size)
- photos = self.CacheGet(key)
- if photos:
- return photos
-
- photos = []
- sets = self.GetAllAlbums()
- set_id = None
- for s in sets:
- if s['title'] == album:
- set_id = s['id']
- break
- if not set_id:
- return photos
- logging.info('Found photoset %s with id %s' % (album, set_id))
- photoset = flickr.Photoset(set_id, album, False)
- for photo in photoset.getPhotos():
- pic = {
- 'id': photo.id,
- 'height': 480,
- 'width': 640,
- 'thumb_url': photo.getURL(size=thumb_size, urlType='source'),
- 'url': photo.getURL(size=img_size, urlType='source'),
- 'name': photo.title,
- }
- photos.append(pic)
-
- # set memcache
- self.CacheSet(key, photos)
-
- return photos
-
- def CacheClear(self):
- keys = []
- albums = self.GetAllAlbums()
- #for a in albums:
- # keys.append("album_%s_%sc_%s" % (album['title'], self.thumb_size, self.imgmax))
- # keys.append("album_%s_%su_%s" % (album['title'], self.thumb_size, self.imgmax))
- #albums.append('albums')
- #memcache.delete_multi(albums)
+ flickr = None
+
+ def __init__(self, user):
+ PhotoBackend.__init__(self, user)
+
+ flickr.API_KEY = '36fbcb5322bdab1866dff9622f161400'
+
+ self.flickr = flickr.User(self.user_id)
+
+ def GetAllAlbums(self):
+ logging.info('GetAllAlbums called')
+
+ # check memcache
+ key = 'flickr_albums'
+ albums = self.CacheGet(key)
+ if albums:
+ return albums
+
+ albums = []
+ sets = self.flickr.getPhotosets()
+ for s in sets:
+ albums.append({
+ 'id': s.id,
+ 'title': s.title,
+ })
+
+ # set memcache
+ self.CacheSet(key, albums)
+
+ return albums
+
+ def GetPhotosInAlbum(self, album, featured=[]):
+ logging.info('GetPhotosInAlbum called')
+ if self.thumb_cropped:
+ thumb_size = "Square"
+ else:
+ thumb_size = "Thumbnail"
+
+ if self.imgmax < 600:
+ img_size = "Medium"
+ else:
+ img_size = "Large"
+
+ # check memcache
+ key = "album_%s_%s_%s" % (album, thumb_size, img_size)
+ photos = self.CacheGet(key)
+ if photos:
+ return photos
+
+ photos = []
+ sets = self.GetAllAlbums()
+ set_id = None
+ for s in sets:
+ if s['title'] == album:
+ set_id = s['id']
+ break
+ if not set_id:
+ return photos
+ logging.info('Found photoset %s with id %s' % (album, set_id))
+ photoset = flickr.Photoset(set_id, album, False)
+ for photo in photoset.getPhotos():
+ pic = {
+ 'id': photo.id,
+ 'height': 480,
+ 'width': 640,
+ 'thumb_url': photo.getURL(size=thumb_size, urlType='source'),
+ 'url': photo.getURL(size=img_size, urlType='source'),
+ 'name': photo.title,
+ }
+ photos.append(pic)
+
+ # set memcache
+ self.CacheSet(key, photos)
+
+ return photos
+
+ def CacheClear(self):
+ keys = []
+ albums = self.GetAllAlbums()
+ #for a in albums:
+ # keys.append("album_%s_%sc_%s" % (album['title'], self.thumb_size, self.imgmax))
+ # keys.append("album_%s_%su_%s" % (album['title'], self.thumb_size, self.imgmax))
+ #albums.append('albums')
+ #memcache.delete_multi(albums)
class UserPrefs(db.Model):
- user = db.UserProperty(required=True)
-
- photo_backend = db.IntegerProperty(choices=settings.PHOTO_BACKENDS, default=settings.PHOTO_BACKEND_PICASA, required=True)
-
- site_title = db.StringProperty(default='photo')
- site_header = db.StringProperty(default='photo')
-
- thumb_size = db.IntegerProperty(choices=settings.THUMB_SIZES, default=settings.THUMB_SIZE_DEFAULT, required=True)
- thumb_cropped = db.BooleanProperty(default=settings.THUMB_CROPPED_DEFAULT, required=True)
-
- full_size = db.IntegerProperty(choices=settings.FULL_SIZES, default=settings.FULL_SIZE_DEFAULT, required=True)
-
- homepage_size = db.IntegerProperty(choices=settings.FULL_SIZES, default=settings.HOMEPAGE_SIZE_DEFAULT, required=True)
- homepage_album = db.StringProperty()
-
- featured_albums = db.StringListProperty()
-
- picasa_id = db.StringProperty(default='default')
- flickr_id = db.StringProperty()
-
- merchant_id = db.StringProperty()
- analytics_id = db.StringProperty()
-
- def GetUsername(self):
- if self.photo_backend == settings.PHOTO_BACKEND_PICASA:
- return self.picasa_id
- elif self.photo_backend == settings.PHOTO_BACKEND_FLICKR:
- return self.flickr_id
- else:
- return None
-
- def SetUsername(self, user_id):
- if self.photo_backend == settings.PHOTO_BACKEND_PICASA:
- self.picasa_id = user_id
- elif self.photo_backend == settings.PHOTO_BACKEND_FLICKR:
- self.flickr_id = user_id
- else:
- return None
-
- def GetPhotoBackend(self):
- if self.photo_backend == settings.PHOTO_BACKEND_PICASA:
- return PicasaBackend(self)
- elif self.photo_backend == settings.PHOTO_BACKEND_FLICKR:
- return FlickrBackend(self)
- else:
- return None
+ user = db.UserProperty(required=True)
+
+ photo_backend = db.IntegerProperty(choices=settings.PHOTO_BACKENDS, default=settings.PHOTO_BACKEND_PICASA, required=True)
+
+ site_title = db.StringProperty(default='photo')
+ site_header = db.StringProperty(default='photo')
+
+ thumb_size = db.IntegerProperty(choices=settings.THUMB_SIZES, default=settings.THUMB_SIZE_DEFAULT, required=True)
+ thumb_cropped = db.BooleanProperty(default=settings.THUMB_CROPPED_DEFAULT, required=True)
+
+ full_size = db.IntegerProperty(choices=settings.FULL_SIZES, default=settings.FULL_SIZE_DEFAULT, required=True)
+
+ homepage_size = db.IntegerProperty(choices=settings.FULL_SIZES, default=settings.HOMEPAGE_SIZE_DEFAULT, required=True)
+ homepage_album = db.StringProperty()
+
+ featured_albums = db.StringListProperty()
+
+ picasa_id = db.StringProperty(default='default')
+ flickr_id = db.StringProperty()
+
+ merchant_id = db.StringProperty()
+ analytics_id = db.StringProperty()
+
+ def GetUsername(self):
+ if self.photo_backend == settings.PHOTO_BACKEND_PICASA:
+ return self.picasa_id
+ elif self.photo_backend == settings.PHOTO_BACKEND_FLICKR:
+ return self.flickr_id
+ else:
+ return None
+
+ def SetUsername(self, user_id):
+ if self.photo_backend == settings.PHOTO_BACKEND_PICASA:
+ self.picasa_id = user_id
+ elif self.photo_backend == settings.PHOTO_BACKEND_FLICKR:
+ self.flickr_id = user_id
+ else:
+ return None
+
+ def GetPhotoBackend(self):
+ if self.photo_backend == settings.PHOTO_BACKEND_PICASA:
+ return PicasaBackend(self)
+ elif self.photo_backend == settings.PHOTO_BACKEND_FLICKR:
+ return FlickrBackend(self)
+ else:
+ return None
View
4 photography.py
@@ -6,7 +6,7 @@
application = webapp.WSGIApplication([('/(.+)/', MainPage), ('/', MainPage)], debug=settings.DEBUG)
def main():
- run_wsgi_app(application)
+ run_wsgi_app(application)
if __name__ == "__main__":
- main()
+ main()
View
4 settings.py
@@ -5,9 +5,9 @@
SERVER_SOFTWARE = os.environ['SERVER_SOFTWARE'].split('/')[0]
if SERVER_SOFTWARE == 'Development':
- DEBUG = True
+ DEBUG = True
else:
- DEBUG = False
+ DEBUG = False
THUMB_SIZES = [32, 48, 64, 72, 75, 104, 144, 150, 160]
THUMB_SIZE_DEFAULT = 72
View
440 views.py
@@ -14,229 +14,229 @@
import settings
class BasePage(webapp.RequestHandler):
- """Base class to handle requests."""
-
- gphoto_namespace = 'http://schemas.google.com/photos/2007'
- media_namespace = 'http://search.yahoo.com/mrss/'
- template_values = {}
- userprefs = None
-
+ """Base class to handle requests."""
+
+ gphoto_namespace = 'http://schemas.google.com/photos/2007'
+ media_namespace = 'http://search.yahoo.com/mrss/'
+ template_values = {}
+ userprefs = None
+
class AdminPage(BasePage):
- """Class to handle requests to the admin directory."""
-
-
- def RenderAdminPage(self):
- """Renders the admin page"""
- logging.info('RenderAdminPage called')
-
- self.template_values['title'] = self.userprefs.site_title+" gallery admin"
- self.template_values['album_name'] = "admin"
- self.template_values['logout_url'] = users.create_logout_url('/')
- if users.get_current_user() != self.userprefs.user:
- self.template_values['current_user'] = users.get_current_user()
- self.template_values['user'] = self.userprefs
- self.template_values['settings'] = settings
- self.template_values['debug'] = settings.DEBUG
-
- backend = self.userprefs.GetPhotoBackend()
-
- try:
- albums = backend.GetAllAlbums()
- except:
- albums = []
- album_list = []
- featured_albums = self.userprefs.featured_albums
- for a in albums:
- if a['title'] in featured_albums:
- a['featured'] = True
- else:
- a['featured'] = False
- album_list.append(a)
- album_list.append({'id': 'all', 'title': 'all', 'featured': ('all' in featured_albums)})
-
- self.template_values['all_albums'] = album_list
- path = os.path.join(os.path.dirname(__file__), 'admin.html')
- self.response.out.write(template.render(path, self.template_values))
-
- def InitializeUser(self):
- # Get the owner of the app
- self.userprefs = UserPrefs.all().get()
-
- if not self.userprefs:
- # Create the owner of the app
- self.userprefs = UserPrefs(user=users.get_current_user())
- self.userprefs.put()
-
- def get(self):
- """Default method called upon entry to the app."""
-
- self.InitializeUser()
-
- # Reset template values with every new request.
- self.template_values = {
- }
-
- self.RenderAdminPage()
-
- def post(self):
- """Save the admin settings."""
-
- self.InitializeUser()
-
- self.template_values = {
- }
-
- # Get the admin settings and save them
- try:
- if self.request.get('clear-cache'):
- backend = self.userprefs.GetPhotoBackend()
-
- backend.ClearCache()
-
- self.template_values['cache_cleared'] = True
- else:
- self.userprefs.photo_backend = int(self.request.get('backend'))
- self.userprefs.SetUsername(self.request.get('backend-id'))
-
- self.userprefs.site_title = self.request.get('site-title').strip()
- self.userprefs.site_header = self.request.get('site-header').strip()
-
- self.userprefs.thumb_size = int(self.request.get('thumb-size'))
- if self.userprefs.photo_backend == settings.PHOTO_BACKEND_FLICKR:
- self.userprefs.thumb_size = 75
- elif self.userprefs.photo_backend == settings.PHOTO_BACKEND_PICASA and self.userprefs.thumb_size == 75:
- self.userprefs.thumb_size = 72
- self.userprefs.thumb_cropped = bool(self.request.get('thumb-cropped'))
- self.userprefs.full_size = int(self.request.get('full-size'))
- self.userprefs.homepage_size = int(self.request.get('homepage-size'))
-
- backend = self.userprefs.GetPhotoBackend()
-
- homepage_album = self.request.get('homepage-album').strip()
- for album in backend.GetAllAlbums():
- if album['title'] == homepage_album:
- self.userprefs.homepage_album = homepage_album
-
- featured_albums = self.request.get('featured-album', allow_multiple=True)
-
- self.userprefs.featured_albums = featured_albums
-
- self.userprefs.merchant_id = self.request.get('merchant-id')
- self.userprefs.analytics_id = self.request.get('analytics-id')
-
- self.userprefs.put()
-
- self.template_values['saved'] = True
- except (TypeError, ValueError), e:
- self.template_values['error'] = True
- self.template_values['error_message'] = str(e)
-
-
- self.RenderAdminPage()
+ """Class to handle requests to the admin directory."""
+
+
+ def RenderAdminPage(self):
+ """Renders the admin page"""
+ logging.info('RenderAdminPage called')
+
+ self.template_values['title'] = self.userprefs.site_title+" gallery admin"
+ self.template_values['album_name'] = "admin"
+ self.template_values['logout_url'] = users.create_logout_url('/')
+ if users.get_current_user() != self.userprefs.user:
+ self.template_values['current_user'] = users.get_current_user()
+ self.template_values['user'] = self.userprefs
+ self.template_values['settings'] = settings
+ self.template_values['debug'] = settings.DEBUG
+
+ backend = self.userprefs.GetPhotoBackend()
+
+ try:
+ albums = backend.GetAllAlbums()
+ except:
+ albums = []
+ album_list = []
+ featured_albums = self.userprefs.featured_albums
+ for a in albums:
+ if a['title'] in featured_albums:
+ a['featured'] = True
+ else:
+ a['featured'] = False
+ album_list.append(a)
+ album_list.append({'id': 'all', 'title': 'all', 'featured': ('all' in featured_albums)})
+
+ self.template_values['all_albums'] = album_list
+ path = os.path.join(os.path.dirname(__file__), 'admin.html')
+ self.response.out.write(template.render(path, self.template_values))
+
+ def InitializeUser(self):
+ # Get the owner of the app
+ self.userprefs = UserPrefs.all().get()
+
+ if not self.userprefs:
+ # Create the owner of the app
+ self.userprefs = UserPrefs(user=users.get_current_user())
+ self.userprefs.put()
+
+ def get(self):
+ """Default method called upon entry to the app."""
+
+ self.InitializeUser()
+
+ # Reset template values with every new request.
+ self.template_values = {
+ }
+
+ self.RenderAdminPage()
+
+ def post(self):
+ """Save the admin settings."""
+
+ self.InitializeUser()
+
+ self.template_values = {
+ }
+
+ # Get the admin settings and save them
+ try:
+ if self.request.get('clear-cache'):
+ backend = self.userprefs.GetPhotoBackend()
+
+ backend.ClearCache()
+
+ self.template_values['cache_cleared'] = True
+ else:
+ self.userprefs.photo_backend = int(self.request.get('backend'))
+ self.userprefs.SetUsername(self.request.get('backend-id'))
+
+ self.userprefs.site_title = self.request.get('site-title').strip()
+ self.userprefs.site_header = self.request.get('site-header').strip()
+
+ self.userprefs.thumb_size = int(self.request.get('thumb-size'))
+ if self.userprefs.photo_backend == settings.PHOTO_BACKEND_FLICKR:
+ self.userprefs.thumb_size = 75
+ elif self.userprefs.photo_backend == settings.PHOTO_BACKEND_PICASA and self.userprefs.thumb_size == 75:
+ self.userprefs.thumb_size = 72
+ self.userprefs.thumb_cropped = bool(self.request.get('thumb-cropped'))
+ self.userprefs.full_size = int(self.request.get('full-size'))
+ self.userprefs.homepage_size = int(self.request.get('homepage-size'))
+
+ backend = self.userprefs.GetPhotoBackend()
+
+ homepage_album = self.request.get('homepage-album').strip()
+ for album in backend.GetAllAlbums():
+ if album['title'] == homepage_album:
+ self.userprefs.homepage_album = homepage_album
+
+ featured_albums = self.request.get('featured-album', allow_multiple=True)
+
+ self.userprefs.featured_albums = featured_albums
+
+ self.userprefs.merchant_id = self.request.get('merchant-id')
+ self.userprefs.analytics_id = self.request.get('analytics-id')
+
+ self.userprefs.put()
+
+ self.template_values['saved'] = True
+ except (TypeError, ValueError), e:
+ self.template_values['error'] = True
+ self.template_values['error_message'] = str(e)
+
+
+ self.RenderAdminPage()
class MainPage(BasePage):
- """Class to handle requests to the root directory."""
-
- def GetSinglePhoto(self, album_name, photo_id):
- """Retrieves URL for a specific photo.
-
- Args:
- album_name: string name of Picasa web album.
- photo_id: integer photo ID.
-
- Returns:
- String URL pointing to the large photo.
- """
-
- logging.info('GetSinglePhoto with '+album_name+' and '+photo_id)
-
- # Attempt to retrieve url from memcache, keyed on album_name + photo_id.
- photo_url = memcache.get(album_name + '_' + photo_id)
- if settings.MEMCACHE_ENABLED and photo_url is not None:
- logging.info('GetSinglePhoto memcache hit')
- return photo_url
-
- url = '%s/album/%s/photoid/%s?imgmax=800' % (self.GetApiUrl(), album_name, photo_id)
- logging.info('GetSinglePhoto url '+url)
- result = urlfetch.fetch(url)
- try:
- dom = minidom.parseString(result.content)
- for node in dom.getElementsByTagNameNS(self.media_namespace, 'content'):
- memcache.add(album_name + '_' + photo_id, node.getAttribute('url'),
- settings.MEMCACHE_PHOTO_EXPIRATION)
- logging.info('GetSinglePhoto photo url '+node.getAttribute('url'))
- return node.getAttribute('url')
- except:
- logging.info('GetSinglePhoto exception')
- return None
-
-
- def RenderAlbum(self, album_name):
- """Renders an HTML page for a specific album.
-
- Args:
- album_name: string name of Picasa album.
- """
- backend = self.userprefs.GetPhotoBackend()
-
- logging.info('RenderAlbum called')
- self.template_values['album_name'] = album_name
- self.template_values['photos'] = backend.GetPhotosInAlbum(album_name, featured=self.userprefs.featured_albums)
-
- path = os.path.join(os.path.dirname(__file__), 'index.html')
- self.response.out.write(template.render(path, self.template_values))
-
- def RenderHomepage(self):
- """Renders homepage with a single big photo"""
- logging.info('RenderHomepage called')
-
- try:
- backend = self.userprefs.GetPhotoBackend()
- backend.imgmax = self.userprefs.homepage_size
- photos = backend.GetPhotosInAlbum(self.userprefs.homepage_album)
- shuffle(photos)
- for photo in photos:
- if photo['width'] > photo['height']:
- break
-
- self.template_values['homepage_photo'] = {
- 'id': photo['id'],
- 'album': self.userprefs.homepage_album,
- 'src': photo['url'],
- }
- except Exception, e:
- logging.info("Got an error: %s" % str(e))
- path = os.path.join(os.path.dirname(__file__), 'index.html')
- self.response.out.write(template.render(path, self.template_values))
-
- def get(self, album_name=None):
- """Default method called upon entry to the app."""
- # Get the owner of the app
- if not self.userprefs:
- self.userprefs = UserPrefs.all().get()
-
- if not self.userprefs:
- # Redirect to the admin page
- self.redirect('/admin/')
- return
-
- backend = self.userprefs.GetPhotoBackend()
-
- # Reset template values with every new request.
- self.template_values = {
- 'user': self.userprefs,
- 'title': self.userprefs.site_title+" gallery",
- 'albums': backend.GetFeaturedAlbums(self.userprefs.featured_albums),
- 'debug': settings.DEBUG,
- }
- if users.is_current_user_admin():
- self.template_values['logout_url'] = users.create_logout_url('/')
-
- #album_name = self.request.get('album_name')
- if album_name:
- self.RenderAlbum(album_name)
- else:
- self.RenderHomepage()
+ """Class to handle requests to the root directory."""
+
+ def GetSinglePhoto(self, album_name, photo_id):
+ """Retrieves URL for a specific photo.
+
+ Args:
+ album_name: string name of Picasa web album.
+ photo_id: integer photo ID.
+
+ Returns:
+ String URL pointing to the large photo.
+ """
+
+ logging.info('GetSinglePhoto with '+album_name+' and '+photo_id)
+
+ # Attempt to retrieve url from memcache, keyed on album_name + photo_id.
+ photo_url = memcache.get(album_name + '_' + photo_id)
+ if settings.MEMCACHE_ENABLED and photo_url is not None:
+ logging.info('GetSinglePhoto memcache hit')
+ return photo_url
+
+ url = '%s/album/%s/photoid/%s?imgmax=800' % (self.GetApiUrl(), album_name, photo_id)
+ logging.info('GetSinglePhoto url '+url)
+ result = urlfetch.fetch(url)
+ try:
+ dom = minidom.parseString(result.content)
+ for node in dom.getElementsByTagNameNS(self.media_namespace, 'content'):
+ memcache.add(album_name + '_' + photo_id, node.getAttribute('url'),
+ settings.MEMCACHE_PHOTO_EXPIRATION)
+ logging.info('GetSinglePhoto photo url '+node.getAttribute('url'))
+ return node.getAttribute('url')
+ except:
+ logging.info('GetSinglePhoto exception')
+ return None
+
+
+ def RenderAlbum(self, album_name):
+ """Renders an HTML page for a specific album.
+
+ Args:
+ album_name: string name of Picasa album.
+ """
+ backend = self.userprefs.GetPhotoBackend()
+
+ logging.info('RenderAlbum called')
+ self.template_values['album_name'] = album_name
+ self.template_values['photos'] = backend.GetPhotosInAlbum(album_name, featured=self.userprefs.featured_albums)
+
+ path = os.path.join(os.path.dirname(__file__), 'index.html')
+ self.response.out.write(template.render(path, self.template_values))
+
+ def RenderHomepage(self):
+ """Renders homepage with a single big photo"""
+ logging.info('RenderHomepage called')
+
+ try:
+ backend = self.userprefs.GetPhotoBackend()
+ backend.imgmax = self.userprefs.homepage_size
+ photos = backend.GetPhotosInAlbum(self.userprefs.homepage_album)
+ shuffle(photos)
+ for photo in photos:
+ if photo['width'] > photo['height']:
+ break
+
+ self.template_values['homepage_photo'] = {
+ 'id': photo['id'],
+ 'album': self.userprefs.homepage_album,
+ 'src': photo['url'],
+ }
+ except Exception, e:
+ logging.info("Got an error: %s" % str(e))
+ path = os.path.join(os.path.dirname(__file__), 'index.html')
+ self.response.out.write(template.render(path, self.template_values))
+
+ def get(self, album_name=None):
+ """Default method called upon entry to the app."""
+ # Get the owner of the app
+ if not self.userprefs:
+ self.userprefs = UserPrefs.all().get()
+
+ if not self.userprefs:
+ # Redirect to the admin page
+ self.redirect('/admin/')
+ return
+
+ backend = self.userprefs.GetPhotoBackend()
+
+ # Reset template values with every new request.
+ self.template_values = {
+ 'user': self.userprefs,
+ 'title': self.userprefs.site_title+" gallery",
+ 'albums': backend.GetFeaturedAlbums(self.userprefs.featured_albums),
+ 'debug': settings.DEBUG,
+ }
+ if users.is_current_user_admin():
+ self.template_values['logout_url'] = users.create_logout_url('/')
+
+ #album_name = self.request.get('album_name')
+ if album_name:
+ self.RenderAlbum(album_name)
+ else:
+ self.RenderHomepage()
Please sign in to comment.
Something went wrong with that request. Please try again.