class AuthDelegationSubtoken(ndb.Model): """Represents a delegation subtoken. Used to track what tokens are issued. Root entity. ID is autogenerated. """ # Serialized delegation_pb2.Subtoken proto. subtoken = ndb.BlobProperty() # Serialized config_pb2.DelegationConfig.Rule that allowed this token. rule = ndb.BlobProperty() # Intent supplied when creating the token. intent = ndb.StringProperty() # IP address the minting request came from. caller_ip = ndb.StringProperty() # Version of the auth_service that created the subtoken. auth_service_version = ndb.StringProperty() # Fields below are extracted from 'subtoken', for indexing purposes. # Whose authority the token conveys. delegated_identity = ndb.StringProperty() # When the token was created. creation_time = ndb.DateTimeProperty() # List of services that accept the token (or ['*'] if all). services = ndb.StringProperty(repeated=True) # Who initiated the minting request. requestor_identity = ndb.StringProperty()
class Game(ndb.Model): id = ndb.StringProperty() alt_ids = ndb.StringProperty(repeated=True) platforms = ndb.StringProperty(repeated=True) tech = ndb.StringProperty(repeated=True) title = ndb.StringProperty() short_title = ndb.StringProperty() abbr_title = ndb.StringProperty() description = ndb.TextProperty() short_description = ndb.TextProperty() embed_code = ndb.TextProperty() release_date = ndb.StringProperty() version = ndb.StringProperty() status = ndb.StringProperty() credits = ndb.TextProperty() changelog = ndb.TextProperty() icon = ndb.BlobProperty() thumbnails = ndb.BlobProperty(repeated=True) screenshots = ndb.BlobProperty(repeated=True) thumbstrip = ndb.BlobProperty() facebook_url = ndb.StringProperty() gplus_url = ndb.StringProperty() instagram_url = ndb.StringProperty() twitter_url = ndb.StringProperty() visible = ndb.BooleanProperty() feature_rank = ndb.IntegerProperty()
class MessageModelTest(ndb.Model): string = ndb.StringProperty() repeatedString = ndb.StringProperty(repeated=True) text = ndb.TextProperty() repeatedText = ndb.TextProperty(repeated=True) blob = ndb.BlobProperty() repeatedBlob = ndb.BlobProperty(repeated=True) keyProp = ndb.KeyProperty() repeatedKey = ndb.KeyProperty(repeated=True) boolean = ndb.BooleanProperty() repeatedBoolean = ndb.BooleanProperty(repeated=True) integer = ndb.IntegerProperty() repeatedInteger = ndb.IntegerProperty(repeated=True) float = ndb.FloatProperty() repeatedFloat = ndb.FloatProperty(repeated=True) datetime = ndb.DateTimeProperty() repeatedDatetime = ndb.DateTimeProperty(repeated=True) time = ndb.TimeProperty() date = ndb.DateProperty() geopt = ndb.GeoPtProperty() repeatedGeopt = ndb.GeoPtProperty(repeated=True) blobkey = ndb.BlobKeyProperty() repeatedBlobkey = ndb.BlobKeyProperty(repeated=True) structured = ndb.StructuredProperty(InnerModel) repeatedStructured = ndb.StructuredProperty(InnerModel, repeated=True)
class Foo(ndb.Model): _use_memcache = False _use_cache = False now = ndb.DateTimeProperty(auto_now_add=True) nickname = ndb.BlobProperty(indexed=True) email = ndb.BlobProperty(indexed=True) user_id = ndb.BlobProperty(indexed=True)
class Restaurant(ndb.Model): name = ndb.StringProperty() distance = ndb.StringProperty() price = ndb.StringProperty() im1 = ndb.BlobProperty() im2 = ndb.BlobProperty() im3 = ndb.BlobProperty() numResults = ndb.IntegerProperty()
class User(ndb.Model): city = ndb.StringProperty(required=True) country = ndb.StringProperty(required=True) availability = ndb.StringProperty(required=True) time_span = ndb.StringProperty(required=True) name = ndb.StringProperty(required=True) email = ndb.StringProperty(required=True) image = ndb.BlobProperty() # images can only be stored as "BlobProperty" journies = ndb.BlobProperty(repeated=True)
class Greeting(ndb.Model): """Models a diary entry with an author, content, photo, date, etc.""" author = ndb.StringProperty() content = ndb.TextProperty() photo = ndb.BlobProperty() thumbnail = ndb.BlobProperty() date = ndb.DateTimeProperty(auto_now_add=True) photo_datetime = ndb.StringProperty() photo_latitude = ndb.FloatProperty() photo_longitude = ndb.FloatProperty()
class UserPost(ndb.Model): post_name = ndb.StringProperty(required=True) post_date = ndb.StringProperty(required=True) post_location = ndb.StringProperty(required=True) post_event = ndb.StringProperty(required=True) created_at = ndb.DateTimeProperty(auto_now_add=True) image = ndb.BlobProperty(required=False) post_user = ndb.KeyProperty(kind=JUser) post_user_id = ndb.StringProperty(required=True) post_user_image = ndb.BlobProperty() post_nickname = ndb.StringProperty()
class PasswordKeeper(ndb.Model): """Models the encrypted password entity in appengine datastore. This will be used for keeping the encrypted passwords for populating the ios profile template for multiple device configurations. """ date = ndb.DateTimeProperty(auto_now=True, required=True) encrypted_password = ndb.BlobProperty(required=True) crypto_initialization_vector = ndb.BlobProperty(required=True) @staticmethod def StorePassword(email, encrypted_password, crypto_initialization_vector): """Store the encrypted password and crypto info. Args: email: string of the user email for whom the password is being stored encrypted_password: byte string of the encrypted password crypto_initialization_vector: byte string of the crypto initialization vector """ password_keeper = PasswordKeeper(id=email) password_keeper.encrypted_password = encrypted_password password_keeper.crypto_initialization_vector = crypto_initialization_vector password_keeper.put() _LOG.info('Successfully stored encrypted password for %s.', email) @staticmethod def GetPassword(email): """Get the encrypted password for the specified email. Args: email: string of the user email Returns: datastore entity of the encrypted password """ return PasswordKeeper.get_by_id(email) @staticmethod def GetExpiredPasswords(): """Get the encrypted passwords that meets the expiration criteria. Returns: query result as a list containing password keeper entities """ cutoff_time_for_expired_passwords = (datetime.utcnow() - timedelta(minutes=15)) _LOG.debug( 'The cutoff time for passwords to be expired is: %s', cutoff_time_for_expired_passwords.strftime('%m-%d-%Y %H:%M:%S')) return PasswordKeeper.gql('WHERE date <= :1', cutoff_time_for_expired_passwords).fetch()
class OldTestModel(ndb.Model): """Old version of TestModel.""" prop_0 = ndb.StringProperty() prop_1 = ndb.BlobProperty() prop_2 = ndb.IntegerProperty() prop_3 = ndb.StringProperty(repeated=True) prop_4 = ndb.DateTimeProperty() old_prop = ndb.BlobProperty() @classmethod def _get_kind(cls): """Kind override.""" return 'TestModel'
class LastGoodConfig(ndb.Model): """Last-known valid config. Not used to store intermediate/old versions. Entity key: Root entity. Id is "<config_set>:<path>". """ content = ndb.BlobProperty() content_binary = ndb.BlobProperty() content_hash = ndb.StringProperty() proto_message_name = ndb.StringProperty() revision = ndb.StringProperty() last_access_ts = ndb.DateTimeProperty()
class DBImage(ndb.Model): title = ndb.TextProperty(required=False) picture = ndb.BlobProperty() thumb = ndb.BlobProperty(required=False) owner = ndb.IntegerProperty(required=False) # key remoteURL = ndb.StringProperty(required=False) def make_thumb(self): window_ratio = 65.0 / 55.0 height = images.Image(image_data=self.picture).height width = images.Image(image_data=self.picture).width image_ratio = float(width) / float(height) logging.info("thumb " + str(image_ratio)) if image_ratio > window_ratio: # wide new_height = 55 new_width = int(55.0 * image_ratio) self.thumb = images.resize(self.picture, new_width, new_height, output_encoding=images.JPEG, quality=55, correct_orientation=CORRECT_ORIENTATION) self.thumb = images.crop(self.thumb, left_x=0.5 - 32.0 / new_width, top_y=0.0, right_x=0.5 + 32.0 / new_width, bottom_y=1.0) else: new_width = 65 new_height = int(65.0 / image_ratio) self.thumb = images.resize(self.picture, new_width, new_height, output_encoding=images.JPEG, quality=55, correct_orientation=CORRECT_ORIENTATION) self.thumb = images.crop(self.thumb, left_x=0.0, top_y=0.5 - 27.0 / new_height, right_x=1.0, bottom_y=0.5 + 27.0 / new_height) def get_thumb(self): # get or make a thumbnail if not self.thumb: self.make_thumb() self.put() return self.thumb
class AuthDBConfigChange(AuthDBChange): # Valid for CHANGE_CONF_OAUTH_CLIENT_CHANGED. oauth_client_id = ndb.StringProperty() # Valid for CHANGE_CONF_OAUTH_CLIENT_CHANGED. oauth_client_secret = ndb.StringProperty() # Valid for CHANGE_CONF_CLIENT_IDS_ADDED and CHANGE_CONF_CLIENT_IDS_REMOVED. oauth_additional_client_ids = ndb.StringProperty(repeated=True) # Valid for CHANGE_CONF_TOKEN_SERVER_URL_CHANGED. token_server_url_old = ndb.StringProperty() # Valid for CHANGE_CONF_TOKEN_SERVER_URL_CHANGED. token_server_url_new = ndb.StringProperty() # Valid for CHANGE_CONF_SECURITY_CONFIG_CHANGED. security_config_old = ndb.BlobProperty() # Valid for CHANGE_CONF_SECURITY_CONFIG_CHANGED. security_config_new = ndb.BlobProperty()
class PrimitiveProperties(ndb.Model): integer = ndb.IntegerProperty() float = ndb.FloatProperty() boolean = ndb.BooleanProperty() string = ndb.StringProperty() text = ndb.TextProperty() indexed_blob = ndb.BlobProperty(indexed=True) blob = ndb.BlobProperty() datetime = ndb.DateTimeProperty() datastore_key = ndb.KeyProperty() blobstore_key = ndb.BlobKeyProperty() created_at = ndb.DateTimeProperty(auto_now_add=True) updated_at = ndb.DateTimeProperty(auto_now=True) python2_updated_at = ndb.DateTimeProperty(repeated=True) python3_updated_at = ndb.DateTimeProperty(repeated=True)
class Club(ndb.Model): name = ndb.StringProperty(required=True) picture = ndb.BlobProperty() #clubId = ndb.StringProperty(required=True) admin = ndb.KeyProperty(kind='Profile', required=True) description = ndb.TextProperty() members = ndb.KeyProperty(kind='Profile', repeated=True) follows = ndb.KeyProperty( kind='Profile', repeated=True ) # Only includes the set of people apart from members. By default a member of a club follows it. abbreviation = ndb.StringProperty() photo = ndb.BlobProperty() photoUrl = ndb.StringProperty() isAlumni = ndb.StringProperty(required=True) collegeId = ndb.KeyProperty(kind='CollegeDb', required=True)
class StudentOfficer(NdbBaseModel): relevant_page_urls = ["/aboutus/staff"] Createdby = ndb.UserProperty(auto_current_user_add=True) CreationDateTime = NdbUtcDateTimeProperty(auto_now_add=True) ModifiedBy = ndb.UserProperty(auto_current_user=True) ModifiedDateTime = NdbUtcDateTimeProperty(auto_now=True) DisplayOrder = ndb.IntegerProperty() Image = ndb.BlobProperty( required=True, ) Position = ndb.StringProperty( required=True, ) Name = ndb.StringProperty( required=True, ) Major = ndb.StringProperty( required=True, ) Grade = ndb.StringProperty( required=True, ) Email = ndb.StringProperty( required=True, )
class Post(EndpointModel): title = ndb.StringProperty(required=True) date = ndb.DateProperty(auto_now_add=True) text = ndb.StringProperty() image = ndb.BlobProperty() owner = ndb.ReferenceProperty(User, collection_name='users') status = ndb.BooleanProperty()
class TestModel(ndb.Model): """Test model.""" prop_0 = ndb.StringProperty() prop_1 = ndb.BlobProperty() prop_2 = ndb.IntegerProperty() prop_3 = ndb.StringProperty(repeated=True) prop_4 = ndb.DateTimeProperty()
class KeyBase(polymodel.PolyModel): reversed_fingerprint = ndb.BlobProperty('rfp', indexed=True, required=True) creation_time = ndb.DateTimeProperty('c', indexed=False) expiration_time = ndb.DateTimeProperty('e', indexed=False) flags = ndb.IntegerProperty('f', indexed=False) algorithm_type = ndb.StringProperty('a', indexed=False, required=True) bitlen = ndb.IntegerProperty('b', indexed=False) @property def fingerprint(self): return codecs.encode(self.reversed_fingerprint[::-1], 'hex').upper() def _fingerprint_suffix(self, bytelen): return codecs.encode(self.reversed_fingerprint[bytelen - 1::-1], 'hex').upper() @property def keyid(self): return self._fingerprint_suffix(8) @property def shortkeyid(self): return self._fingerprint_suffix(4) @property def stringid(self): return base64.b64encode(self.reversed_fingerprint[::-1])
class IntroFile(ndb.Model): """A user's audio intro. Ancestor: (User) The user Name: 1 """ blob = ndb.BlobProperty(required=True)
class Data(ndb.Model): title = ndb.StringProperty(required=True) desc = ndb.StringProperty(required=True) location = ndb.StringProperty(required=True) image = ndb.BlobProperty(required=False) time = ndb.DateTimeProperty(required=True) tags = ndb.StringProperty(required=False, repeated=True)
class Photo(ndb.Model): """Models a user uploaded photo entry""" #user = ndb.StringProperty() image = ndb.BlobProperty() caption = ndb.StringProperty() date = ndb.DateTimeProperty(auto_now_add=True)
class Session(ndb.Model): """Models the webapp2 session entity in appengine datastore. The reason to model the entity is for query formation. A key information in the session data is the xsrf_token. """ data = ndb.BlobProperty(required=True) updated = ndb.DateTimeProperty(auto_now=True, required=True) @staticmethod def GetExpiredSessionKeys(): """Get the keys of the sessions that meet the expiration criteria. The keys will be used to perform bulk deletion. Returns: query result as a list containing session entity keys """ cutoff_time_for_expired_sessions = (datetime.utcnow() - timedelta(hours=24)) _LOG.debug( 'The cutoff time for sessions to be expired is: %s', cutoff_time_for_expired_sessions.strftime('%m-%d-%Y %H:%M:%S')) return Session.gql( 'WHERE updated <= :1', cutoff_time_for_expired_sessions).fetch(keys_only=True)
class User(ndb.Model): username = ndb.StringProperty(required = True) last_name = ndb.StringProperty(required = False) email = ndb.StringProperty(required = True) pw_hash = ndb.StringProperty(required = False) # If google user guser_id = ndb.StringProperty(required = False) # googleUser nickname = ndb.StringProperty(required = False) # googleUser avatar = ndb.BlobProperty() # For storing images created = ndb.DateTimeProperty(auto_now_add = True) last_modified = ndb.DateTimeProperty(auto_now = True) # @decorator: # means that you can call the # object's method without instantiating the object @classmethod def by_id(cls, uid): # 'cls' refers to the User class return cls.get_by_id(uid, parent = users_key()) @classmethod def by_google_id(cls, gid): # 'cls' refers to the User class # return cls.query().filter('guser_id =', gid).get() return cls.query(cls.guser_id == gid).get() @classmethod def by_name(cls, username): # Query the db without GQL u = cls.query(cls.username == username).get() return u @classmethod def by_email(cls, email): # Query the db without GQL u = cls.query(cls.email == email).get() return u @classmethod def by_gtoken(cls, idtoken): # Query the db without GQL u = cls.query(cls.idtoken == idtoken).get() return u @classmethod def register(cls, username, last_name, pw, email): pw_hash = make_pw_hash(email, pw) return User(parent = users_key(), username = username, last_name = last_name, pw_hash = pw_hash, email = email) @classmethod def login(cls, email, password): u = cls.by_email(email) if u and valid_pw(email, password, u.pw_hash): return u
class MessageFile(ndb.Model): """An audio message. Ancestor: (User, Relationship) The sender and recipient, respectively. Name: (int) Send timestamp, in miliseconds since epoch. """ blob = ndb.BlobProperty(required=True)
class VersionedFile(ndb.Model): """Versionned entity. Root is ROOT_MODEL. id is datastore_utils.HIGH_KEY_ID - version number. """ created_ts = ndb.DateTimeProperty(indexed=False, auto_now_add=True) who = auth.IdentityProperty(indexed=False) content = ndb.BlobProperty(compressed=True) ROOT_MODEL = datastore_utils.get_versioned_root_model('VersionedFileRoot') @property def version(self): return datastore_utils.HIGH_KEY_ID - self.key.integer_id() @classmethod def fetch(cls, name): """Returns the current version of the instance.""" return datastore_utils.get_versioned_most_recent( cls, cls._gen_root_key(name)) def store(self, name): """Stores a new version of the instance.""" # Create an incomplete key. self.key = ndb.Key(self.__class__, None, parent=self._gen_root_key(name)) self.who = auth.get_current_identity() return datastore_utils.store_new_version(self, self.ROOT_MODEL) @classmethod def _gen_root_key(cls, name): return ndb.Key(cls.ROOT_MODEL, name)
class ImageFile(ndb.Model): """A user's chat image. Ancestor: (User) The user Name: 1 """ blob = ndb.BlobProperty(required=True)
class DatastoreAvator(ndb.Model): data = ndb.BlobProperty(default=None) filename = ndb.StringProperty() minetype = ndb.StringProperty() avator_link = ndb.StringProperty() user_email = ndb.StringProperty()
class FileSnapshotContentModel(base_models.BaseSnapshotContentModel): """Class for storing the content of the file snapshots (where the content is an uninterpreted bytestring). """ # Overwrite the superclass member to use a BlobProperty for raw strings. content = ndb.BlobProperty(indexed=False)
class Design(ndb.Model): filename = ndb.StringProperty() image = ndb.BlobProperty() created = ndb.DateTimeProperty(auto_now_add=True) # def uri2view(self): # enable get_serving_url # # logging.info(str(images.get_serving_url( # # self.image.key(), secure_url=True))) # # return # # images.get_serving_url("aghkZXZ-Tm9uZXITCxIGRGVzaWduGICAgICA0LsJDA", # # secure_url=True) # # return str(images.get_serving_url( # # self.image.key(), secure_url=True)) # logging.info("/design_serve/" + str(self.id)) # # return "/design_serve/" + str(self.id) # return "https://www.sockclub.com/images/squiggles.bmp" @classmethod def query_all(cls): return cls.query().order(-cls.created) @classmethod def query_20(cls): return cls.query().order(-cls.created).fetch(limit=20) @classmethod def query_20_run(cls): return cls.query().order(-cls.created).run(limit=20) @classmethod def get_all(cls): q = cls.Query() q.order('-created') return q.fetch(limit=20)