Exemplo n.º 1
0
    def add_fields(
        insight: ProductInsight,
        product: Product,
        timestamp: datetime.datetime,
        server_domain: str,
        server_type: str,
    ):
        """Add mandatory insight fields."""
        barcode = insight.barcode
        insight.reserved_barcode = is_reserved_barcode(barcode)
        insight.server_domain = server_domain
        insight.server_type = server_type
        insight.id = str(uuid.uuid4())
        insight.timestamp = timestamp
        insight.countries = product.countries_tags
        insight.brands = product.brands_tags
        insight.n_votes = 0

        if insight.automatic_processing:
            insight.process_after = timestamp + datetime.timedelta(
                minutes=settings.INSIGHT_AUTOMATIC_PROCESSING_WAIT)
Exemplo n.º 2
0
def validate_insight(
    insight: ProductInsight,
    validator: Optional[InsightValidator],
    product: Optional[Product] = None,
) -> InsightValidationResult:
    if validator is None:
        return InsightValidationResult.unchanged

    if not validator.is_valid(insight, product=product):
        insight.delete_instance()
        return InsightValidationResult.deleted

    if not insight.latent:
        latent = validator.is_latent(insight, product)

        if latent is not None and latent:
            insight.latent = True
            insight.process_after = None
            insight.save()
            return InsightValidationResult.updated

    return InsightValidationResult.unchanged