class User(Model): service = StringProperty() username = StringProperty() commands = CommandsProperty() defaultCommand = StringProperty() def getDefaultCommand(self): if self.commands.get(self.defaultCommand) == None: return None return self.defaultCommand def setDefaultCommand(self, default_command): if default_command == None: self.defaultCommand = '' elif self.commands.get(default_command) != None: self.defaultCommand = default_command @staticmethod def fromURLSafeKey(key): user_key = Key(urlsafe=key) return user_key.get() @staticmethod def fromUsername(username): return User.query(User.username == username).get()
class State(Model): chat_id = IntegerProperty(required=True) job_name = StringProperty() step = StringProperty(indexed=False, choices=['set_style', 'processing', 'completed', 'error']) compress_result = BooleanProperty(indexed=False, required=True) content_file_id = StringProperty(indexed=False) content_message_id = IntegerProperty(indexed=False) progress_message_id = IntegerProperty(indexed=False) content_from_id = IntegerProperty() style_file_id = StringProperty(indexed=False, repeated=True) result_file_id = StringProperty(indexed=False) created = DateTimeProperty(auto_now_add=True) started = DateTimeProperty() completed = DateTimeProperty() consumed_ml_units = FloatProperty(indexed=False) parameters = StructuredProperty(JobParameters) @classmethod def get_count_last_day(cls, chat_id): return cls.query(cls.chat_id == chat_id, cls.started >= datetime.now() - timedelta(days=1)).count() @classmethod def get_by_chat_id_and_job_name(cls, chat_id, job_name): return cls.query(cls.chat_id == chat_id, cls.job_name == job_name).get()
class User(BaseModel): name = StringProperty(required=True) email = StringProperty(required=True) roles = StringProperty(repeated=True) def __init__(self, **kwargs): kwargs["id"] = kwargs.get("email") super(User, self).__init__(**kwargs)
class Configuration(Model): CACHE_TIME = datetime.timedelta(minutes=5) _INSTANCE = None _INSTANCE_AGE = None web_debug = BooleanProperty() debug_login = BooleanProperty() public_stripe_key = StringProperty() consumer_key = StringProperty() consumer_secret = StringProperty() access_token_key = StringProperty() access_token_secret = StringProperty() tweet_frequency = IntegerProperty() @classmethod def get_instance(cls): now = datetime.datetime.now() if not cls._INSTANCE or cls._INSTANCE_AGE + cls.CACHE_TIME < now: cls._INSTANCE = cls.get_or_insert('config') if not cls._INSTANCE.public_stripe_key or not cls._INSTANCE.consumer_key or not cls._INSTANCE.tweet_frequency: cls._INSTANCE.public_stripe_key = 'public key' cls._INSTANCE.web_debug = True cls._INSTANCE.debug_login = True cls._INSTANCE.consumer_key = "Key" cls._INSTANCE.consumer_secret = "Key" cls._INSTANCE.access_token_key = "Key" cls._INSTANCE.access_token_secret = "Key" cls._INSTANCE.tweet_frequency = 4 cls._INSTANCE.put() cls._INSTANCE_AGE = now return cls._INSTANCE
class Observation(BaseModel): TYPES = OrderedDict([ ("VISIT", u"Entrevista presencial"), ("TELEPHONE", u"Seguimiento telefónico") ]) DURATIONS = OrderedDict([ (5, "5 min"), (10, "10 min"), (15, "15 min"), (30, "30 min"), (45, "45 min"), (60, "1 h"), (75, "1 h 15 min"), (90, "1 h 30 min"), (105, "1 h 45 min"), (120, "2 h"), (150, "2 h 30 min"), (180, "3 h") ]) CHANNELS = OrderedDict([ ("GOOGLE", u"Anuncio en Internet"), ("STREET", u"Publicidad callejera"), ("COMMENT", u"Recomendación de otra persona"), ("OTHER", u"Otro") ]) PREGNANCY_CONFIRMATION_METHODS = [ u"Análisis de sangre", u"Ecografía", u"Síntomas", u"Test de orina" ] ABORTION_TYPES = [ u"Espontáneo", u"Provocado" ] ABORTION_METHODS = [ u"Intervención médica", u"Píldora abortiva", u"OTRO" ] ABORTION_PILLS = [ u"Misoprostol", u"Pastilla del día después", u"OTRO" ] SMOKER_TYPE = [ u"No fumadora", u"Fumadora ocasional", u"Fumadora diaria" ] type = StringProperty(required=True, choices=TYPES.keys()) date = DateProperty(required=True) companion_relationship = StringProperty() relative_firstname = StringProperty() relative_surname = StringProperty() learned_about_center = StringProperty() detail = StringProperty() pregnancy_confirmed = BooleanProperty() pregnancy_length_weeks = IntegerProperty()
class Child(SerializableModel): """Used only as StructuredProperty for Patient.""" modifiedon = DateTimeProperty(required=True) name = StringProperty(required=True) birthdate = DateProperty() known_age = IntegerProperty() def age(self): if self.birthdate: return age(self.birthdate) if self.known_age is not None: return age(self.modifiedon) + self.known_age return None def json(self, include=None, exclude=None): d = super(Child, self).json(include, exclude) if self._should_serialize("age", include, exclude): d["age"] = self.age() return d
class Chat(Model): id = IntegerProperty(indexed=True, required=True) num_iter_max = IntegerProperty(indexed=False, required=True, default=10) img_height_max = IntegerProperty(indexed=False, required=True, default=500) style_count_max = IntegerProperty(indexed=False, required=True, default=3) requests_per_day = IntegerProperty(indexed=False, required=True, default=5) default_language = StringProperty(indexed=False) created = DateTimeProperty(auto_now_add=True) state = KeyProperty(kind=State, indexed=False) last_activity = DateTimeProperty(auto_now_add=True) default_parameters = StructuredProperty(JobParameters, required=True, default=JobParameters()) @classmethod def get_by_id(cls, chat_id): return cls.query(cls.id == chat_id).get() def get_state(self): return self.state.get() if self.state else None def put_new_state(self, content_file_id, compress_result, message_id, from_id): chat_model_state = State(chat_id=self.id, parameters=self.default_parameters, step="set_style", content_file_id=content_file_id, compress_result=compress_result, content_message_id=int(message_id), content_from_id=int(from_id) if from_id else None) self.state = chat_model_state.put() self.put() return chat_model_state def set_default_language(self, default_language): if default_language: self.default_language = default_language[:2]
class Patient(BaseModel): createdon = DateTimeProperty(required=True, auto_now_add=True) modifiedon = DateTimeProperty(required=True, auto_now=True) record = IntegerProperty(required=True) firstname = StringProperty(required=True) middlename = StringProperty() surname = StringProperty() birthdate = DateProperty(required=True) nationality = StringProperty(required=True, choices=NATIONALITIES) occupation = StringProperty(required=True) children = StructuredProperty(Child, repeated=True) cellphone = StringProperty() cellphone2 = StringProperty() telephone = StringProperty() email = StringProperty() province = StringProperty(choices=PROVINCES) city = StringProperty() district = StringProperty() advisor = StructuredProperty(Advisor) coadvisors = StructuredProperty(Advisor, repeated=True) relative_firstname = StringProperty() relative_middlename = StringProperty() relative_surname = StringProperty() relative_relationship = StringProperty() relative_cellphone = StringProperty() relative_province = StringProperty(choices=PROVINCES) relative_city = StringProperty() relative_district = StringProperty() notes = TextProperty() def age(self): return age(self.birthdate) if self.birthdate else None def has_advisor(self, user): uid = user.id() return (self.advisor and self.advisor.id == uid) or\ (self.coadvisors and uid in map(lambda a: a.id, self.coadvisors)) def json(self, include=None, exclude=None): d = super(Patient, self).json(include, ["children", "advisor", "coadvisors"] + (exclude or [])) if self._should_serialize("children", include, exclude): d["children"] = [c.json(include, exclude) for c in self.children] if self.children else [] if self._should_serialize("advisor", include, exclude): d["advisor"] = self.advisor.json(include, exclude) if self.advisor else None if self._should_serialize("coadvisors", include, exclude): d["coadvisors"] = [c.json(include, exclude) for c in self.coadvisors] if self.coadvisors else [] if self._should_serialize("age", include, exclude): d["age"] = self.age() return d
class Advisor(SerializableModel): """Used only as StructuredProperty for Patient.""" id = StringProperty(required=True) name = StringProperty(required=True)
class Branch(BaseModel): name = StringProperty(required=True)