Exemple #1
0
    def on_get(self, req: falcon.Request, resp: falcon.Response, logo_id: int):
        logo = LogoAnnotation.get_or_none(id=logo_id)

        if logo is None:
            resp.status = falcon.HTTP_404
            return

        logo_dict = logo.to_dict()
        image_prediction = logo_dict.pop("image_prediction")
        logo_dict["image"] = image_prediction["image"]
        resp.media = logo_dict
Exemple #2
0
    def on_put(self, req: falcon.Request, resp: falcon.Response, logo_id: int):
        logo = LogoAnnotation.get_or_none(id=logo_id)

        if logo is None:
            resp.status = falcon.HTTP_404
            return

        type_ = req.media["type"]
        value = req.media["value"] or None
        updated = False

        if type_ != logo.annotation_type:
            logo.annotation_type = type_
            updated = True

        if value != logo.annotation_value:
            logo.annotation_value = value

            if value is not None:
                value_tag = get_tag(value)
                logo.annotation_value_tag = value_tag
                logo.taxonomy_value = match_unprefixed_value(value_tag, type_)
            else:
                logo.annotation_value_tag = None
                logo.taxonomy_value = None

            updated = True

        if updated:
            auth = parse_auth(req)
            username = None if auth is None else auth.get_username()
            logo.username = username
            logo.completed_at = datetime.datetime.utcnow()
            logo.save()

        resp.status = falcon.HTTP_204