class Appointments(EndpointsModel): start_dt = EndpointsDateTimeProperty(required=True) end_dt = EndpointsDateTimeProperty(required=True) cancelled = ndb.BooleanProperty(default=False) request_user = ndb.KeyProperty(kind='User', required=True) admission_officer = ndb.KeyProperty(kind='AdmissionsOfficer', required=True) scheduled = EndpointsDateTimeProperty(auto_now_add=True)
class TimelineItem(EndpointsModel): """Model for timeline cards. Since the created property is auto_now_add=True, Cards will document when they were inserted immediately after being stored. """ class TimelineContact(EndpointsModel): class ContactType(messages.Enum): INDIVIDUAL = 1 GROUP = 2 acceptTypes = ndb.StringProperty(repeated=True) displayName = ndb.StringProperty() id = ndb.StringProperty(required=True) imageUrls = ndb.StringProperty(repeated=True) phoneNumber = ndb.StringProperty() source = ndb.StringProperty() type = msgprop.EnumProperty(ContactType) _message_fields_schema = ("id", "attachments", "bundleId", "canonicalUrl", "created", "displayTime", "html", "htmlPages", "inReplyTo", "isBundleCover", "isDeleted", "isPinned", "menuItems", "recipients", "sourceItemId", "speakableText", "text", "title", "updated") user = EndpointsUserProperty(required=True, raise_unauthorized=True) attachments = ndb.StructuredProperty(Attachment, repeated=True) bundleId = ndb.StringProperty() canonicalUrl = ndb.StringProperty() created = EndpointsDateTimeProperty(auto_now_add=True) displayTime = EndpointsDateTimeProperty() html = ndb.TextProperty() htmlPages = ndb.TextProperty(repeated=True) inReplyTo = ndb.IntegerProperty() isBundleCover = ndb.BooleanProperty(default=False) isDeleted = ndb.BooleanProperty(default=False) isPinned = ndb.BooleanProperty(default=False) menuItems = ndb.LocalStructuredProperty(MenuItem, repeated=True) recipients = ndb.LocalStructuredProperty(TimelineContact, repeated=True) sourceItemId = ndb.StringProperty() speakableText = ndb.TextProperty() text = ndb.StringProperty() title = ndb.StringProperty() updated = EndpointsDateTimeProperty(auto_now=True)
class Meeting(BaseModel): _message_fields_schema = ('created', 'id', 'owner_id', 'venue_forsquare_id', 'location', 'earliest_possible_start', 'latest_possible_start', 'topic', 'type', 'tags') owner = ndb.KeyProperty(kind=UserData, required=True) venue_forsquare_id = ndb.StringProperty(required=True) location = ndb.GeoPtProperty() earliest_possible_start = EndpointsDateTimeProperty( required=True, string_format=DATE_FORMAT_STR) latest_possible_start = EndpointsDateTimeProperty( string_format=DATE_FORMAT_STR) topic = ndb.StringProperty(required=True) type = ndb.StringProperty(required=True, choices=['drink', 'lunch', 'brunch']) tags = ndb.StringProperty(repeated=True) @EndpointsAliasProperty(property_type=messages.IntegerField) def owner_id(self): return self.owner.id()
class AdmissionsOfficer(EndpointsModel, webapp2_extras.appengine.auth.models.User): """ Admissions Officer Model """ _message_fields_schema = ('id', 'verified', 'school', 'school_type', 'location', 'rating', 'alias', 'hours_consulted', 'last_active', 'knowledge_areas', 'whoami', 'job_title', 'howcanihelp', 'college_rank') email = ndb.StringProperty(required=True) first_name = ndb.StringProperty(required=True) last_name = ndb.StringProperty(required=True) phone = ndb.StringProperty(required=True) stripeCustId = ndb.StringProperty(default=None) alias = ndb.StringProperty(default=None) appointments = ndb.KeyProperty(kind='Appointments', default=None, repeated=True) verified = ndb.BooleanProperty(default=False) paymentStuff = ndb.StringProperty(default='') school = ndb.StringProperty(default='') school_type = ndb.StringProperty(default='') location = ndb.StringProperty(default='') rating = ndb.FloatProperty(default=5.0) hours_consulted = ndb.IntegerProperty(default=0) last_active = EndpointsDateTimeProperty(auto_now=True) knowledge_areas = ndb.StringProperty(repeated=True) whoami = ndb.StringProperty(default='') howcanihelp = ndb.StringProperty(default='') job_title = ndb.StringProperty(default='') college_rank = ndb.StringProperty(default='Top 40') def id_setter(self, value): # Allocate IDs if DNE if value == '' or value is None or value == 'None': first, last = AdmissionsOfficer.allocate_ids(2) self.UpdateFromKey(ndb.Key('AdmissionsOfficer', first)) elif not isinstance(value, basestring) and not isinstance(value, int): raise endpoints.BadRequestException('ID not string or int') else: self.UpdateFromKey(ndb.Key('AdmissionsOfficer', value)) @EndpointsAliasProperty(setter=id_setter, required=True) def id(self): if self.key is not None: return str(self.key.id())
class Location(EndpointsModel): """Model for location""" _latest = False _message_fields_schema = ( "id", "timestamp", "latitude", "longitude", "accuracy", "displayName", "address" ) user = EndpointsUserProperty(required=True, raise_unauthorized=True) timestamp = EndpointsDateTimeProperty(auto_now_add=True) latitude = ndb.FloatProperty() longitude = ndb.FloatProperty() accuracy = ndb.FloatProperty() displayName = ndb.StringProperty() address = ndb.StringProperty() def IdSet(self, value): if not isinstance(value, basestring): raise TypeError("ID must be a string.") if value == "latest": self._latest = True loc_query = Location.query().order(-Location.timestamp) loc_query = loc_query.filter(Location.user == self.user) loc = loc_query.get() if loc is not None: self.UpdateFromKey(loc.key) return if value.isdigit(): self.UpdateFromKey(ndb.Key(Location, int(value))) @EndpointsAliasProperty(setter=IdSet, required=False) def id(self): if self._latest: return "latest" if self.key is not None: return str(self.key.integer_id())
class TimelineItem(EndpointsModel): """Model for timeline cards. Since the created property is auto_now_add=True, Cards will document when they were inserted immediately after being stored. """ class Attachment(EndpointsModel): """Attachment to a timeline card Due to limitations in Cloud Endpoints this works a bit differently than the attachments in the official API. Normally you would add attachments by uploading the media data (as image/audio/video). Attachments in this implementation can only by of type image and are represented either as URL or Data-URI and can be added/retrieved/updated directly by filling the attachments field in the timeline.insert method. """ id = ndb.StringProperty() contentType = ndb.StringProperty() contentUrl = ndb.StringProperty() isProcessingContent = ndb.BooleanProperty(default=False) class TimelineContact(EndpointsModel): class ContactType(messages.Enum): INDIVIDUAL = 1 GROUP = 2 acceptTypes = ndb.StringProperty(repeated=True) displayName = ndb.StringProperty() id = ndb.StringProperty(required=True) imageUrls = ndb.StringProperty(repeated=True) phoneNumber = ndb.StringProperty() source = ndb.StringProperty() type = msgprop.EnumProperty(ContactType) class Notification(EndpointsModel): level = ndb.StringProperty(default="DEFAULT") deliveryTime = EndpointsDateTimeProperty() _message_fields_schema = ("id", "attachments", "bundleId", "canonicalUrl", "created", "creator", "displayTime", "html", "htmlPages", "inReplyTo", "isBundleCover", "isDeleted", "isPinned", "location", "menuItems", "notification", "pinScore", "recipients", "sourceItemId", "speakableText", "text", "title", "updated") user = EndpointsUserProperty(required=True, raise_unauthorized=True) attachments = ndb.LocalStructuredProperty(Attachment, repeated=True) bundleId = ndb.StringProperty() canonicalUrl = ndb.StringProperty() created = EndpointsDateTimeProperty(auto_now_add=True) creator = ndb.LocalStructuredProperty(TimelineContact) displayTime = EndpointsDateTimeProperty() html = ndb.TextProperty() htmlPages = ndb.TextProperty(repeated=True) inReplyTo = ndb.IntegerProperty() isBundleCover = ndb.BooleanProperty() isDeleted = ndb.BooleanProperty() isPinned = ndb.BooleanProperty() location = ndb.LocalStructuredProperty(Location) menuItems = ndb.LocalStructuredProperty(MenuItem, repeated=True) notification = ndb.LocalStructuredProperty(Notification) pinScore = ndb.IntegerProperty() recipients = ndb.LocalStructuredProperty(TimelineContact, repeated=True) sourceItemId = ndb.StringProperty() speakableText = ndb.TextProperty() text = ndb.StringProperty() title = ndb.StringProperty() updated = EndpointsDateTimeProperty(auto_now=True) def IncludeDeletedSet(self, value): """ If value is true all timelineItems will be returned. Otherwise a filter for non-deleted items is necessary for the query. """ if value is None or value is False: self._endpoints_query_info._AddFilter( TimelineItem.isDeleted == False) @EndpointsAliasProperty(setter=IncludeDeletedSet, property_type=messages.BooleanField, default=False) def includeDeleted(self): """ includedDeleted is only used as parameter in query_methods so there should never be a reason to actually retrieve the value """ return None def PinnedOnlySet(self, value): """ If value is true only pinned timelineItems will be returned. Otherwise all timelineItems are returned. """ if value is True: self._endpoints_query_info._AddFilter( TimelineItem.isPinned == True) @EndpointsAliasProperty(setter=PinnedOnlySet, property_type=messages.BooleanField, default=False) def pinnedOnly(self): """ pinnedOnly is only used as parameter in query_methods so there should never be a reason to actually retrieve the value """ return None def MaxResultsSet(self, value): """Setter to be used for default limit EndpointsAliasProperty. Simply sets the limit on the entity's query info object, and the query info object handles validation. Args: value: The limit value to be set. """ self._endpoints_query_info.limit = value @EndpointsAliasProperty(setter=MaxResultsSet, property_type=messages.IntegerField, default=20) def maxResults(self): """Getter to be used for default limit EndpointsAliasProperty. Uses the ProtoRPC property_type IntegerField since a limit. Returns: The integer (or null) limit from the query info on the entity. """ return self._endpoints_query_info.limit
class Notification(EndpointsModel): level = ndb.StringProperty(default="DEFAULT") deliveryTime = EndpointsDateTimeProperty()