Пример #1
0
    def _annotate(
        self,
        insight: ProductInsight,
        annotation: int,
        update: bool = True,
        data: Optional[Dict] = None,
        auth: Optional[OFFAuthentication] = None,
        automatic: bool = False,
    ) -> AnnotationResult:
        if self.is_data_required() and data is None:
            return DATA_REQUIRED_RESULT

        username: Optional[str] = None
        if auth is not None:
            username = auth.get_username()

        insight.username = username
        insight.annotation = annotation
        insight.completed_at = datetime.datetime.utcnow()

        if automatic:
            insight.automatic_processing = True

        insight.save()

        if annotation == 1 and update:
            return self.process_annotation(insight, data=data, auth=auth)

        return SAVED_ANNOTATION_RESULT
Пример #2
0
    def annotate(
        self,
        insight: ProductInsight,
        annotation: int,
        update=True,
        auth: Optional[OFFAuthentication] = None,
    ) -> AnnotationResult:
        username: Optional[str] = None
        if auth is not None:
            username = auth.username

            if auth.session_cookie:
                username = extract_username(auth.session_cookie)

        with db.atomic():
            insight.annotation = annotation
            insight.completed_at = datetime.datetime.utcnow()
            insight.save()

            if username:
                UserAnnotation.create(insight=insight, username=username)

        if annotation == 1 and update:
            return self.update_product(insight, auth=auth)

        return SAVED_ANNOTATION_RESULT
Пример #3
0
    def annotate(self, insight: ProductInsight, annotation: int, update=True) \
            -> AnnotationResult:
        insight.annotation = annotation
        insight.completed_at = datetime.datetime.utcnow()
        insight.save()

        if annotation == 1 and update:
            return self.update_product(insight)

        return SAVED_ANNOTATION_RESULT
Пример #4
0
    def annotate(self,
                 insight: ProductInsight,
                 annotation: int,
                 update=True,
                 session_cookie: Optional[str] = None) -> AnnotationResult:
        insight.annotation = annotation
        insight.completed_at = datetime.datetime.utcnow()
        insight.save()

        if annotation == 1 and update:
            return self.update_product(insight, session_cookie=session_cookie)

        return SAVED_ANNOTATION_RESULT