from .models import User, Portfolio, Album, Photo, AccessRight, Role, MyAnonymous
+from app import app
#from flask_login import mixins
class DBQueryException(Exception):
albums = []
if hasattr(object, '__tablename__'):
if isinstance(object, User):
- portfolios = Portfolio.query.filter_by(owner=object)
+ portfolios = Portfolio.query(user=object.id)
for p in portfolios:
albums.extend(Album.query.filter_by(portfolio=p))
elif isinstance(object, Portfolio):
- albums = Album.query.filter_by(portfolio=object)
+ albums = Album.query(portfolio=object.id)
elif isinstance(object, Photo):
albums.append(object.album)
else:
portfolios = []
if hasattr(object, '__tablename__'):
if isinstance(object, User):
- portfolios = Portfolio.query.filter_by(owner=object)
+ portfolios = Portfolio.query(user=object.id)
elif isinstance(object, Album):
portfolios.append(object.portfolio)
elif isinstance(object, Photo):
def get_owner(self, object):
if hasattr(object, '__tablename__'):
if isinstance(object, Portfolio):
- return object.owner
+ return object.user
elif isinstance(object, Album):
p = object.portfolio
- return p.owner
+ return p.user
elif isinstance(object, Photo):
a = object.album
p = a.portfolio
- return p.owner
+ return p.user
else:
raise DBQueryException("%s: not supported" % object.__tablename__)
else:
if hasattr(object, '__tablename__'):
users = []
if isinstance(object, Album):
+ # TODO: get rit of query.join
objects = AccessRight.query.join(AccessRight.album).filter(Album.id == object.id)
for o in objects:
users.append(o.user)
# Last get all visible and public albums
u = MyAnonymous()
temp = self.get_albums_for_user(u)
- print("1) Other albums: %s" % temp)
+ app.logger.info("1) Other albums: %s" % temp)
albs = []
portfolios = self.get_portfolios(user)
for p in portfolios:
if not hidden and not a.visible:
continue
albums.append(a)
- print("2) Own albums: %s" % albums)
+ app.logger.info("2) Own albums: %s" % albums)
# Remove own albums
temp = list(set(temp) - set(albs))
- print("3) Other albums: %s" % temp)
+ app.logger.info("3) Other albums: %s" % temp)
# Merge albums with temp removing duplicates
albums = albums + temp
else:
# Anonymous user
if user.is_anonymous:
# Find all albums which is public and visible
- albums = Album.query.filter_by(public=True,visible=True).all()
+ albums = Album.query(public=True, visible=True)
except AttributeError:
raise DBQueryException("%s: Not a User object" % user)
- print("Anonymous albums: %s" % albums)
+ app.logger.info("Anonymous albums: %s" % albums)
return albums
def is_safe_url(target):