# Path: errors.py
# class NoSuchEmployee(Exception):
#     pass
# 
# Path: util/pagination.py
# class Pagination(object):
#     ITEMS_PER_PAGE = 20
# 
#     @classmethod
#     def paginate(cls, order_by, prev_cursor_str, next_cursor_str):
#         if not prev_cursor_str and not next_cursor_str:
#             objects, next_cursor, more = cls.query().order(order_by).fetch_page(cls.ITEMS_PER_PAGE)
#             prev_cursor_str = ''
#             if next_cursor:
#                 next_cursor_str = next_cursor.urlsafe()
#             else:
#                 next_cursor_str = ''
#             next_ = True if more else False
#             prev = False
#         elif next_cursor_str:
#             cursor = Cursor(urlsafe=next_cursor_str)
#             objects, next_cursor, more = cls.query().order(order_by).fetch_page(
#                 cls.ITEMS_PER_PAGE,
#                 start_cursor=cursor,
#             )
#             prev_cursor_str = next_cursor_str
#             next_cursor_str = next_cursor.urlsafe()
#             prev = True
#             next_ = True if more else False
#         elif prev_cursor_str:
#             cursor = Cursor(urlsafe=prev_cursor_str)
#             objects, next_cursor, more = cls.query().order(-order_by).fetch_page(
#                 cls.ITEMS_PER_PAGE,
#                 start_cursor=cursor,
#             )
#             objects.reverse()
#             next_cursor_str = prev_cursor_str
#             prev_cursor_str = next_cursor.urlsafe()
#             prev = True if more else False
#             next_ = True
# 
#         return PaginationResult(
#             collection=objects,
#             prev_cursor=prev_cursor_str,
#             next_cursor=next_cursor_str,
#             prev=prev,
#             next=next_,
#         )


import base64
import hashlib
import functools
import config
from google.appengine.ext import ndb
from google.appengine.api import users
from errors import NoSuchEmployee
from util.pagination import Pagination
    @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:

# Path: errors.py
# class NoSuchEmployee(Exception):
#     pass
# 
# Path: util/pagination.py
# class Pagination(object):
#     ITEMS_PER_PAGE = 20
# 
#     @classmethod
#     def paginate(cls, order_by, prev_cursor_str, next_cursor_str):
#         if not prev_cursor_str and not next_cursor_str:
#             objects, next_cursor, more = cls.query().order(order_by).fetch_page(cls.ITEMS_PER_PAGE)
#             prev_cursor_str = ''
#             if next_cursor:
#                 next_cursor_str = next_cursor.urlsafe()
#             else:
#                 next_cursor_str = ''
#             next_ = True if more else False
#             prev = False
#         elif next_cursor_str:
#             cursor = Cursor(urlsafe=next_cursor_str)
#             objects, next_cursor, more = cls.query().order(order_by).fetch_page(
#                 cls.ITEMS_PER_PAGE,
#                 start_cursor=cursor,
#             )
#             prev_cursor_str = next_cursor_str
#             next_cursor_str = next_cursor.urlsafe()
#             prev = True
#             next_ = True if more else False
#         elif prev_cursor_str:
#             cursor = Cursor(urlsafe=prev_cursor_str)
#             objects, next_cursor, more = cls.query().order(-order_by).fetch_page(
#                 cls.ITEMS_PER_PAGE,
#                 start_cursor=cursor,
#             )
#             objects.reverse()
#             next_cursor_str = prev_cursor_str
#             prev_cursor_str = next_cursor.urlsafe()
#             prev = True if more else False
#             next_ = True
# 
#         return PaginationResult(
#             collection=objects,
#             prev_cursor=prev_cursor_str,
#             next_cursor=next_cursor_str,
#             prev=prev,
#             next=next_,
#         )


# Path: models/employee.py
import base64
import hashlib
import functools
import config
from google.appengine.ext import ndb
from google.appengine.api import users
from errors import NoSuchEmployee
from util.pagination import Pagination

    @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))