# Path: errors.py
# class NoSuchLoveLink(Exception):
#     pass
# 
# Path: models/love_link.py
# class LoveLink(ndb.Model):
#     """Models an instance of a Love Link."""
#     hash_key = ndb.StringProperty()
#     message = ndb.TextProperty()
#     recipient_list = ndb.TextProperty()
#     timestamp = ndb.DateTimeProperty(auto_now_add=True)
# 
#     @property
#     def seconds_since_epoch(self):
#         return int(mktime(self.timestamp.timetuple()))
# 
#     @property
#     def url(self):
#         return config.APP_BASE_URL + 'l/' + self.hash_key
# 
# Path: models/employee.py
# class Employee(ndb.Model, Pagination):
#     """Models an Employee."""
#     department = ndb.StringProperty(indexed=True)
#     first_name = ndb.StringProperty(indexed=False)
#     last_name = ndb.StringProperty(indexed=False)
#     photo_url = ndb.TextProperty()
#     terminated = ndb.BooleanProperty(default=False)
#     timestamp = ndb.DateTimeProperty(auto_now_add=True)
#     user = ndb.UserProperty()
#     username = ndb.StringProperty()
#     office = ndb.StringProperty(indexed=True)
# 
#     @classmethod
#     def get_current_employee(cls):
#         user = users.get_current_user()
#         user_email = user.email()
#         employee = cls.query(cls.user == user, cls.terminated == False).get()  # noqa
#         if employee is None:
#             raise NoSuchEmployee('Couldn\'t find a Google Apps user with email {}'.format(user_email))
#         return employee
# 
#     @classmethod
#     def create_from_dict(cls, d, persist=True):
#         new_employee = cls()
#         new_employee.username = d['username']
#         new_employee.user = users.User('{user}@{domain}'.format(user=new_employee.username, domain=config.DOMAIN))
#         new_employee.update_from_dict(d)
# 
#         if persist is True:
#             new_employee.put()
# 
#         return new_employee
# 
#     @classmethod
#     def key_to_username(cls, key):
#         return cls.query(cls.key == key).get().username
# 
#     @classmethod
#     @memoized
#     def get_key_for_username(cls, username):
#         key = cls.query(cls.username == username, cls.terminated == False).get(keys_only=True)  # noqa
#         if key is None:
#             raise NoSuchEmployee("Couldn't find a Google Apps user with username {}".format(username))
#         return key
# 
#     def update_from_dict(self, d):
#         self.first_name = d['first_name']
#         self.last_name = d['last_name']
#         self.photo_url = d.get('photo_url')
#         if d.get('photos'):
#             self.photo_url = d['photos']['ms'].replace('http://', 'https://', 1)
#         self.department = d.get('department')
#         self.office = d['office']
# 
#     def get_gravatar(self):
#         """Creates gravatar URL from email address."""
#         m = hashlib.md5()
#         m.update(self.user.email())
#         encoded_hash = base64.b16encode(m.digest()).lower()
#         return 'https://gravatar.com/avatar/{}?s=200'.format(encoded_hash)
# 
#     def get_photo_url(self):
#         """Return an avatar photo URL (depending on Gravatar config). This still could
#         be empty, in which case the theme needs to provide an alternate photo.
#         """
#         if config.GRAVATAR == 'always':
#             return self.get_gravatar()
#         elif config.GRAVATAR == 'backup' and not self.photo_url:
#             return self.get_gravatar()
#         else:
#             return self.photo_url
# 
#     @property
#     def full_name(self):
#         """Return user's full name (first name + ' ' + last name)."""
#         return u'{} {}'.format(self.first_name, self.last_name)


import datetime
import logging
import random
import string
import logic.alias
from errors import NoSuchLoveLink
from models import LoveLink
from models import Employee
from google.appengine.ext import ndb
        raise NoSuchLoveLink("Couldn't Love Link with id {}".format(hash_key))
    return loveLink


def generate_link_id():
    link_id = ''.join(random.choice(string.ascii_letters) for _ in range(5))
    return link_id


def create_love_link(recipients, message):
    logging.info('Creating love link')
    link_id = generate_link_id()
    new_love_link = LoveLink(
        hash_key=link_id,
        recipient_list=recipients,
        message=message,
    )
    logging.info(new_love_link)
    new_love_link.put()

    return new_love_link


def add_recipient(hash_key, recipient):
    loveLink = LoveLink.query(LoveLink.hash_key == hash_key).get()
    if (loveLink is None):
        raise NoSuchLoveLink("Couldn't Love Link with id {}".format(hash_key))

    # check that user exists, get_key_for_username throws an exception if not
    recipient_username = logic.alias.name_for_alias(recipient)

# Path: errors.py
# class NoSuchLoveLink(Exception):
#     pass
# 
# Path: models/love_link.py
# class LoveLink(ndb.Model):
#     """Models an instance of a Love Link."""
#     hash_key = ndb.StringProperty()
#     message = ndb.TextProperty()
#     recipient_list = ndb.TextProperty()
#     timestamp = ndb.DateTimeProperty(auto_now_add=True)
# 
#     @property
#     def seconds_since_epoch(self):
#         return int(mktime(self.timestamp.timetuple()))
# 
#     @property
#     def url(self):
#         return config.APP_BASE_URL + 'l/' + self.hash_key
# 
# Path: models/employee.py
# class Employee(ndb.Model, Pagination):
#     """Models an Employee."""
#     department = ndb.StringProperty(indexed=True)
#     first_name = ndb.StringProperty(indexed=False)
#     last_name = ndb.StringProperty(indexed=False)
#     photo_url = ndb.TextProperty()
#     terminated = ndb.BooleanProperty(default=False)
#     timestamp = ndb.DateTimeProperty(auto_now_add=True)
#     user = ndb.UserProperty()
#     username = ndb.StringProperty()
#     office = ndb.StringProperty(indexed=True)
# 
#     @classmethod
#     def get_current_employee(cls):
#         user = users.get_current_user()
#         user_email = user.email()
#         employee = cls.query(cls.user == user, cls.terminated == False).get()  # noqa
#         if employee is None:
#             raise NoSuchEmployee('Couldn\'t find a Google Apps user with email {}'.format(user_email))
#         return employee
# 
#     @classmethod
#     def create_from_dict(cls, d, persist=True):
#         new_employee = cls()
#         new_employee.username = d['username']
#         new_employee.user = users.User('{user}@{domain}'.format(user=new_employee.username, domain=config.DOMAIN))
#         new_employee.update_from_dict(d)
# 
#         if persist is True:
#             new_employee.put()
# 
#         return new_employee
# 
#     @classmethod
#     def key_to_username(cls, key):
#         return cls.query(cls.key == key).get().username
# 
#     @classmethod
#     @memoized
#     def get_key_for_username(cls, username):
#         key = cls.query(cls.username == username, cls.terminated == False).get(keys_only=True)  # noqa
#         if key is None:
#             raise NoSuchEmployee("Couldn't find a Google Apps user with username {}".format(username))
#         return key
# 
#     def update_from_dict(self, d):
#         self.first_name = d['first_name']
#         self.last_name = d['last_name']
#         self.photo_url = d.get('photo_url')
#         if d.get('photos'):
#             self.photo_url = d['photos']['ms'].replace('http://', 'https://', 1)
#         self.department = d.get('department')
#         self.office = d['office']
# 
#     def get_gravatar(self):
#         """Creates gravatar URL from email address."""
#         m = hashlib.md5()
#         m.update(self.user.email())
#         encoded_hash = base64.b16encode(m.digest()).lower()
#         return 'https://gravatar.com/avatar/{}?s=200'.format(encoded_hash)
# 
#     def get_photo_url(self):
#         """Return an avatar photo URL (depending on Gravatar config). This still could
#         be empty, in which case the theme needs to provide an alternate photo.
#         """
#         if config.GRAVATAR == 'always':
#             return self.get_gravatar()
#         elif config.GRAVATAR == 'backup' and not self.photo_url:
#             return self.get_gravatar()
#         else:
#             return self.photo_url
# 
#     @property
#     def full_name(self):
#         """Return user's full name (first name + ' ' + last name)."""
#         return u'{} {}'.format(self.first_name, self.last_name)


# Path: logic/love_link.py
import datetime
import logging
import random
import string
import logic.alias
from errors import NoSuchLoveLink
from models import LoveLink
from models import Employee
from google.appengine.ext import ndb

        raise NoSuchLoveLink("Couldn't Love Link with id {}".format(hash_key))
    return loveLink


def generate_link_id():
    link_id = ''.join(random.choice(string.ascii_letters) for _ in range(5))
    return link_id


def create_love_link(recipients, message):
    logging.info('Creating love link')
    link_id = generate_link_id()
    new_love_link = LoveLink(
        hash_key=link_id,
        recipient_list=recipients,
        message=message,
    )
    logging.info(new_love_link)
    new_love_link.put()

    return new_love_link


def add_recipient(hash_key, recipient):
    loveLink = LoveLink.query(LoveLink.hash_key == hash_key).get()
    if (loveLink is None):
        raise NoSuchLoveLink("Couldn't Love Link with id {}".format(hash_key))

    # check that user exists, get_key_for_username throws an exception if not
    recipient_username = logic.alias.name_for_alias(recipient)

    Employee.get_key_for_username(recipient_username)