Skip to content

Commit

Permalink
fix state check
Browse files Browse the repository at this point in the history
  • Loading branch information
nik committed Jan 16, 2025
1 parent 1f3f0b6 commit ad42079
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions label_studio/users/product_tours/serializers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import logging
import pathlib
import yaml
from functools import cached_property

import yaml
from core.utils.db import fast_first
from rest_framework import serializers

from .models import ProductTourInteractionData, UserProductTour
from .models import ProductTourInteractionData, ProductTourState, UserProductTour

logger = logging.getLogger(__name__)

PRODUCT_TOURS_CONFIGS_DIR = pathlib.Path(__file__).parent / 'configs'

Expand Down Expand Up @@ -36,18 +40,19 @@ def load_tour_config(self):
filepath = PRODUCT_TOURS_CONFIGS_DIR / f'{self.context["name"]}.yml'
with open(filepath, 'r') as f:
return yaml.safe_load(f)

def get_awaiting(self, obj):
config = self.load_tour_config()
config = self.load_tour_config
dependencies = config.get('dependencies', [])
for dependency in dependencies:
tour = fast_first(UserProductTour.objects.filter(user=self.context['request'].user, name=dependency))
if not tour or tour.status != UserProductTour.Status.COMPLETED:
if not tour or tour.state != ProductTourState.COMPLETED:
logger.info(f'Tour {dependency} is not completed: skipping tour {self.context["name"]}')
return True
return False

def get_steps(self, obj):
config = self.load_tour_config()
config = self.load_tour_config
return config.get('steps', [])

def validate_interaction_data(self, value):
Expand Down

0 comments on commit ad42079

Please sign in to comment.