"""
This module contains the views needed for the photo gallery features
of the website
"""

from flaskext.flask_login import current_user, login_required

from application import app

from flask import render_template, flash, url_for, redirect, request, make_response, jsonify

from flaskext import wtf

import json, urlparse, urllib

import datetime as dt

import models
import forms

from application.facebook import facebook as fb
from application.facebook import models as fb_models

from application.accounts.accounts import require_roles
from application.accounts.models import UserRoleModel, RoleModel

from google.appengine.api import urlfetch

import facebooksdk as fbsdk

@app.route('/photos/albums/list')
@login_required
def photos_album_list():
    """
    View for displaying a list of all albums
    """

    query = UserRoleModel.all()
    query.filter('user =', current_user.key())

    can_edit = None
    uroles = query.fetch(query.count())
    for urole in uroles:
        if urole.role.name == 'webmaster':
            can_edit=True
            break

    query = fb_models.AlbumModel.all()
    query.filter('display =', True)

    albums = query.fetch(query.count())

    return render_template('photos/list_albums.html',
                           can_edit=can_edit,