# Path: boilerplate/models.py
# class User(User):
#     """
#     Universal user model. Can be used with App Engine's default users API,
#     own auth or third party authentication methods (OpenID, OAuth etc).
#     based on https://gist.github.com/kylefinley
#     """
# 
#     #: Creation date.
#     created = ndb.DateTimeProperty(auto_now_add=True)
#     #: Modification date.
#     updated = ndb.DateTimeProperty(auto_now=True)
#     #: User defined unique name, also used as key_name.
#     # Not used by OpenID
#     username = ndb.StringProperty()
#     #: User Name
#     name = ndb.StringProperty()
#     #: User Last Name
#     last_name = ndb.StringProperty()
#     #: User email
#     email = ndb.StringProperty()
#     #: Hashed password. Only set for own authentication.
#     # Not required because third party authentication
#     # doesn't use password.
#     password = ndb.StringProperty()
#     #: User Country
#     country = ndb.StringProperty()
#     #: Account activation verifies email
#     activated = ndb.BooleanProperty(default=False)
#     #
#     uuid = ndb.StringProperty()
#     #
#     currency = ndb.StringProperty()
#     
#     @classmethod
#     def get_by_email(cls, email):
#         """Returns a user object based on an email.
# 
#         :param email:
#             String representing the user email. Examples:
# 
#         :returns:
#             A user object.
#         """
#         return cls.query(cls.email == email).get()
# 
#     @classmethod
#     def create_resend_token(cls, user_id):
#         entity = cls.token_model.create(user_id, 'resend-activation-mail')
#         return entity.token
# 
#     @classmethod
#     def validate_resend_token(cls, user_id, token):
#         return cls.validate_token(user_id, 'resend-activation-mail', token)
# 
#     @classmethod
#     def delete_resend_token(cls, user_id, token):
#         cls.token_model.get_key(user_id, 'resend-activation-mail', token).delete()
# 
#     def get_social_providers_names(self):
#         social_user_objects = SocialUser.get_by_user(self.key)
#         result = []
# #        import logging
#         for social_user_object in social_user_objects:
# #            logging.error(social_user_object.extra_data['screen_name'])
#             result.append(social_user_object.provider)
#         return result
# 
#     def get_social_providers_info(self):
#         providers = self.get_social_providers_names()
#         result = {'used': [], 'unused': []}
#         for k,v in SocialUser.PROVIDERS_INFO.items():
#             if k in providers:
#                 result['used'].append(v)
#             else:
#                 result['unused'].append(v)
#         return result


import math
import uuid
from collections import OrderedDict
from google.appengine.ext import ndb
from google.appengine.ext import blobstore
from google.appengine.api.images import get_serving_url
from boilerplate.models import User
            q = Part.query(Part.subsystem_names == subsys.name, ancestor=self.key)\
                    .order(Part.name)
            for part in q.iter():
                if not by_subsystem.has_key(subsys.name):
                    by_subsystem[subsys.name] = []
                by_subsystem[subsys.name].append(part)
        return by_subsystem




class BomLikes(ndb.Model):
    user_key = ndb.KeyProperty(kind=User, required=True)
    bom_key = ndb.KeyProperty(kind=Bom, required=True)

    @classmethod
    def new(cls, user_key, bom_key):
        return cls(parent=bom_key, bom_key=bom_key, user_key=user_key)


class BomWatches(ndb.Model):
    user_key = ndb.KeyProperty(kind=User, required=True)
    bom_key = ndb.KeyProperty(kind=Bom, required=True)

    @classmethod
    def new(cls, user_key, bom_key):
        return cls(parent=bom_key, bom_key=bom_key, user_key=user_key)


class BomRoughs(ndb.Model):

# Path: boilerplate/models.py
# class User(User):
#     """
#     Universal user model. Can be used with App Engine's default users API,
#     own auth or third party authentication methods (OpenID, OAuth etc).
#     based on https://gist.github.com/kylefinley
#     """
# 
#     #: Creation date.
#     created = ndb.DateTimeProperty(auto_now_add=True)
#     #: Modification date.
#     updated = ndb.DateTimeProperty(auto_now=True)
#     #: User defined unique name, also used as key_name.
#     # Not used by OpenID
#     username = ndb.StringProperty()
#     #: User Name
#     name = ndb.StringProperty()
#     #: User Last Name
#     last_name = ndb.StringProperty()
#     #: User email
#     email = ndb.StringProperty()
#     #: Hashed password. Only set for own authentication.
#     # Not required because third party authentication
#     # doesn't use password.
#     password = ndb.StringProperty()
#     #: User Country
#     country = ndb.StringProperty()
#     #: Account activation verifies email
#     activated = ndb.BooleanProperty(default=False)
#     #
#     uuid = ndb.StringProperty()
#     #
#     currency = ndb.StringProperty()
#     
#     @classmethod
#     def get_by_email(cls, email):
#         """Returns a user object based on an email.
# 
#         :param email:
#             String representing the user email. Examples:
# 
#         :returns:
#             A user object.
#         """
#         return cls.query(cls.email == email).get()
# 
#     @classmethod
#     def create_resend_token(cls, user_id):
#         entity = cls.token_model.create(user_id, 'resend-activation-mail')
#         return entity.token
# 
#     @classmethod
#     def validate_resend_token(cls, user_id, token):
#         return cls.validate_token(user_id, 'resend-activation-mail', token)
# 
#     @classmethod
#     def delete_resend_token(cls, user_id, token):
#         cls.token_model.get_key(user_id, 'resend-activation-mail', token).delete()
# 
#     def get_social_providers_names(self):
#         social_user_objects = SocialUser.get_by_user(self.key)
#         result = []
# #        import logging
#         for social_user_object in social_user_objects:
# #            logging.error(social_user_object.extra_data['screen_name'])
#             result.append(social_user_object.provider)
#         return result
# 
#     def get_social_providers_info(self):
#         providers = self.get_social_providers_names()
#         result = {'used': [], 'unused': []}
#         for k,v in SocialUser.PROVIDERS_INFO.items():
#             if k in providers:
#                 result['used'].append(v)
#             else:
#                 result['unused'].append(v)
#         return result


# Path: web/models.py
import math
import uuid
from collections import OrderedDict
from google.appengine.ext import ndb
from google.appengine.ext import blobstore
from google.appengine.api.images import get_serving_url
from boilerplate.models import User

            q = Part.query(Part.subsystem_names == subsys.name, ancestor=self.key)\
                    .order(Part.name)
            for part in q.iter():
                if not by_subsystem.has_key(subsys.name):
                    by_subsystem[subsys.name] = []
                by_subsystem[subsys.name].append(part)
        return by_subsystem




class BomLikes(ndb.Model):
    user_key = ndb.KeyProperty(kind=User, required=True)
    bom_key = ndb.KeyProperty(kind=Bom, required=True)

    @classmethod
    def new(cls, user_key, bom_key):
        return cls(parent=bom_key, bom_key=bom_key, user_key=user_key)


class BomWatches(ndb.Model):
    user_key = ndb.KeyProperty(kind=User, required=True)
    bom_key = ndb.KeyProperty(kind=Bom, required=True)

    @classmethod
    def new(cls, user_key, bom_key):
        return cls(parent=bom_key, bom_key=bom_key, user_key=user_key)


class BomRoughs(ndb.Model):

    user_key = ndb.KeyProperty(kind=User, required=True)