# Path: groups/models.py
# def group_uri2id( group_uri ):
# def group_id2uri( group_id ):
# def create_group( address, description, sequence ):
# def _group2json(group_db):
# def get_group( group_uri ):
# def get_groups( sequence=None ):
# def get_member_groups( member_email ):
# def add_group_member( group_uri, member_email ):
# def remove_group_member( group_uri, member_email ):
# def sync_group_with_mailgun( group_uri ):


from models import get_bios_by_email
from groups import models as group_model
from PIL import Image
from boto.s3.key import Key
from django.conf import settings
import requests
import math
import boto
        x = index%width
        y = index/width
        try:
            avatar = Image.open(image)
            avatar.thumbnail(avatar_size, Image.ANTIALIAS)
            collage.paste(avatar, (x*avatar_size[0], y*avatar_size[1]))
        except Exception as e:
            print(e)
    return collage


def make_group_photo(group_uri):
    group = group_model.get_group(group_uri)
    bios = get_bios_by_email(group['sequence'], group['members'])
    group_photo = combine_photos(bios)
    file_name = u'gf_{0}.jpg'.format(group_uri.strip('/').split('/')[-1])
    group_photo.save(file_name, u'JPEG')
    return file_name


def upload_to_s3(filename, bucket):
    c = boto.connect_s3()
    b = c.get_bucket(bucket)
    k = Key(b)
    k.key = filename
    k.set_contents_from_filename(filename, policy='public-read')
    return k.generate_url(expires_in=0, query_auth=False, force_http=True)


def make_group_photos(sequence):

# Path: groups/models.py
# def group_uri2id( group_uri ):
# def group_id2uri( group_id ):
# def create_group( address, description, sequence ):
# def _group2json(group_db):
# def get_group( group_uri ):
# def get_groups( sequence=None ):
# def get_member_groups( member_email ):
# def add_group_member( group_uri, member_email ):
# def remove_group_member( group_uri, member_email ):
# def sync_group_with_mailgun( group_uri ):


# Path: classphoto/group_photo.py
from models import get_bios_by_email
from groups import models as group_model
from PIL import Image
from boto.s3.key import Key
from django.conf import settings
import requests
import math
import boto

        x = index%width
        y = index/width
        try:
            avatar = Image.open(image)
            avatar.thumbnail(avatar_size, Image.ANTIALIAS)
            collage.paste(avatar, (x*avatar_size[0], y*avatar_size[1]))
        except Exception as e:
            print(e)
    return collage


def make_group_photo(group_uri):
    group = group_model.get_group(group_uri)
    bios = get_bios_by_email(group['sequence'], group['members'])
    group_photo = combine_photos(bios)
    file_name = u'gf_{0}.jpg'.format(group_uri.strip('/').split('/')[-1])
    group_photo.save(file_name, u'JPEG')
    return file_name


def upload_to_s3(filename, bucket):
    c = boto.connect_s3()
    b = c.get_bucket(bucket)
    k = Key(b)
    k.key = filename
    k.set_contents_from_filename(filename, policy='public-read')
    return k.generate_url(expires_in=0, query_auth=False, force_http=True)


def make_group_photos(sequence):

    groups = group_model.get_groups(sequence)