From 8bc6cf4cf21131267b98317caa094a50a534d7ff Mon Sep 17 00:00:00 2001 From: nik Date: Sun, 22 Dec 2024 11:56:57 +0200 Subject: [PATCH] Address comments --- .../users/migrations/0010_userproducttour.py | 8 +++--- label_studio/users/product_tours/api.py | 4 +-- label_studio/users/product_tours/models.py | 25 +++++++++++-------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/label_studio/users/migrations/0010_userproducttour.py b/label_studio/users/migrations/0010_userproducttour.py index ffe9395c64f7..0238f2aad40d 100644 --- a/label_studio/users/migrations/0010_userproducttour.py +++ b/label_studio/users/migrations/0010_userproducttour.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.15 on 2024-12-17 18:56 +# Generated by Django 4.2.15 on 2024-12-22 09:54 from django.conf import settings from django.db import migrations, models @@ -16,9 +16,9 @@ class Migration(migrations.Migration): name='UserProductTour', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(help_text='Unique identifier for the product tour. Name must match the config name.', max_length=256)), - ('state', models.CharField(choices=[('ready', 'ready'), ('completed', 'completed'), ('skipped', 'skipped')], default='ready', help_text='Current state of the tour for this user: "ready" when tour is initiated, "completed" when user finishes the tour, "skipped" when user cancels the tour.', max_length=32)), - ('interaction_data', models.JSONField(blank=True, default=dict, help_text='Additional data about user interaction with the tour')), + ('name', models.CharField(help_text='Unique identifier for the product tour. Name must match the config name.', max_length=256, verbose_name='Name')), + ('state', models.CharField(choices=[('ready', 'Ready'), ('completed', 'Completed'), ('skipped', 'Skipped')], default='ready', help_text='Current state of the tour for this user. Available options: ready (Ready), completed (Completed), skipped (Skipped)', max_length=32, verbose_name='State')), + ('interaction_data', models.JSONField(blank=True, default=dict, help_text='Additional data about user interaction with the tour', verbose_name='Interaction Data')), ('created_at', models.DateTimeField(auto_now_add=True, help_text='When this tour record was created')), ('updated_at', models.DateTimeField(auto_now=True, help_text='When this tour record was last updated')), ('user', models.ForeignKey(help_text='User who interacted with the tour', on_delete=django.db.models.deletion.CASCADE, related_name='tours', to=settings.AUTH_USER_MODEL)), diff --git a/label_studio/users/product_tours/api.py b/label_studio/users/product_tours/api.py index ac8462001c0a..5643435ab81c 100644 --- a/label_studio/users/product_tours/api.py +++ b/label_studio/users/product_tours/api.py @@ -34,11 +34,11 @@ def get_object(self): tour = UserProductTour.objects.filter(user=self.request.user, name=name).first() if not tour: - logger.info(f'Product tour {name} not found for user {self.request.user.id}. Creating new tour.') + logger.debug(f'Product tour {name} not found for user {self.request.user.id}. Creating new tour.') tour_serializer = self.get_serializer(data={'user': self.request.user.id, 'name': name}) tour_serializer.is_valid(raise_exception=True) tour = tour_serializer.save() else: - logger.info(f'Product tour {name} requested for user {self.request.user.id}.') + logger.debug(f'Product tour {name} requested for user {self.request.user.id}.') return tour diff --git a/label_studio/users/product_tours/models.py b/label_studio/users/product_tours/models.py index d196eb353178..a117455a926a 100644 --- a/label_studio/users/product_tours/models.py +++ b/label_studio/users/product_tours/models.py @@ -1,14 +1,14 @@ from enum import Enum from typing import Any, Dict, Optional - +from django.utils.translation import gettext_lazy as _ from django.db import models from pydantic import BaseModel, Field -class ProductTourState(str, Enum): - READY = 'ready' - COMPLETED = 'completed' - SKIPPED = 'skipped' +class ProductTourState(models.TextChoices): + READY = 'ready', _('Ready') + COMPLETED = 'completed', _('Completed') + SKIPPED = 'skipped', _('Skipped') class ProductTourInteractionData(BaseModel): @@ -31,18 +31,23 @@ class UserProductTour(models.Model): ) name = models.CharField( - max_length=256, help_text='Unique identifier for the product tour. Name must match the config name.' + _('Name'), + max_length=256, + help_text='Unique identifier for the product tour. Name must match the config name.' ) state = models.CharField( + _('State'), max_length=32, - choices=[(state.value, state.value) for state in ProductTourState], - default=ProductTourState.READY.value, - help_text='Current state of the tour for this user: "ready" when tour is initiated, "completed" when user finishes the tour, "skipped" when user cancels the tour.', + choices=ProductTourState.choices, + default=ProductTourState.READY, + help_text=f'Current state of the tour for this user. Available options: {", ".join(f"{k} ({v})" for k,v in ProductTourState.choices)}', ) interaction_data = models.JSONField( - default=dict, blank=True, help_text='Additional data about user interaction with the tour' + _('Interaction Data'), + default=dict, blank=True, + help_text='Additional data about user interaction with the tour' ) created_at = models.DateTimeField(auto_now_add=True, help_text='When this tour record was created')