Exemplo n.º 1
0
class MedicationHistory(grumble.Model):
    timestamp = grumble.DateProperty(auto_now_add=True)
    current = grumble.BooleanProperty()
    medication = grumble.ReferenceProperty(Medication)
    dose = grumble.TextProperty()
    units = grumble.TextProperty("mg", "tablets", "g", "Other")
    frequency = grumble.TextProperty(choices=[
        "Daily", "Twice a day", "Three times a day", "Four times a day",
        "Other"
    ])
    experiences = grumble.TextProperty(multiline=True)
Exemplo n.º 2
0
class UserCreate(grumble.Model):
    userid = grumble.TextProperty()
    display_name = grumble.TextProperty()
    password = grumble.TextProperty()
    confirm = grumble.BooleanProperty()

    user_exists = grudge.Status()
    user_created = grudge.Status()
    mail_sent = grudge.Status()
    confirmed = grudge.Status()
    user_activated = grudge.Status()

    def create_user(self):
        try:
            um = grit.Session.get_usermanager()
            if not self.password:
                self.password = gripe.auth.generate_password()
            um.add(self.userid,
                   password=self.password,
                   display_name=self.display_name)
            self.put()
            logger.debug("Create User OK")
            return self.user_created if not self.confirm else self.confirmed
        except gripe.auth.UserExists:
            return self.user_exists
        except gripe.Error as e:
            logger.debug("Create user Error: %s" % e)
            raise

    def prepare_message(self, msg, ctx):
        msg.set_header(
            "X-ST-URL", "%s/um/confirmreset/%s" %
            (Config.app.config.application_url, self.id()))
        return ctx

    def activate_user(self):
        um = grit.Session.get_usermanager()
        try:
            user = um.get(self.userid)
            if user:
                user.confirm()
                logger.debug("Activate User OK")
                return self.user_activated
            else:
                raise gripe.auth.UserDoesntExists(self.userid)
        except gripe.Error as e:
            logger.debug("Activate user Error: %s" % e)
            raise
Exemplo n.º 3
0
class UploadActivity(grumble.Model):
    uploadedFile = grumble.ReferenceProperty(grit.upload.UploadedFile)
    athlete = grumble.ReferenceProperty(grizzle.User)
    filename = grumble.property.StringProperty()
    converted = grumble.BooleanProperty(default=False)
    error = grumble.TextProperty()

    done = grudge.Status()

    def check(self):
        logger.debug("UploadActivity(%s).check", self.filename)
        uploaded = self.uploadedFile
        user = uploaded.get_user()
        if not user.has_role("athlete"):
            logger.debug(
                "UploadActivity(%s).check: User %s cannot upload activities because they don't have the 'athlete' role",
                self.filename, user.uid())
            self.error = "User %s cannot upload activities because they don't not have the 'athlete' role" % user.uid(
            )
            self.put()
            return False
        q = UploadActivity.query('"filename" =', uploaded.filename,
                                 '"athlete" =', user, '"converted" = ', True)
        already_uploaded = q.get()
        if already_uploaded:
            logger.debug(
                "UploadActivity(%s).check: User '%s' already uploaded file",
                self.filename, user.uid())
            self.error = "User '%s' already uploaded file '%s'" % (
                user.uid(), uploaded.filename)
            self.put()
            return False
        self.filename = uploaded.filename
        self.athlete = user
        self.put()
        logger.debug("UploadActivity(%s).check OK", self.filename)
        return True

    def import_file(self):
        logger.debug("UploadActivity(%s).import_file", self.filename)
        uploaded = self.uploadedFile
        try:
            parser = sweattrails.device.get_parser(uploaded.filename)
            parser.set_athlete(self.athlete)
            parser.parse(uploaded.content.adapted)
            logger.debug("UploadActivity(%s).import_file: file parsed",
                         self.filename)
            self.converted = True
        except exceptions.Exception as e:
            logger.exception("Exception parsing file %s", self.filename)
            self.error = traceback.format_exc()
        self.put()

    def cleanup(self):
        logger.debug("UploadActivity(%s).cleanup", self.filename)
        grumble.model.delete(self.uploadedFile)
        self.uploadedFile = None
        self.put()

    def invoke(self):
        logger.debug("UploadActivity(%s).invoke", self.filename)
        if self.check():
            self.import_file()
        self.cleanup()
Exemplo n.º 4
0
 class Test3Sub(Test3):
     light_switch = grumble.BooleanProperty(default=False)