Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nik committed Dec 22, 2024
1 parent b93490b commit 8bc6cf4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
8 changes: 4 additions & 4 deletions label_studio/users/migrations/0010_userproducttour.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)),
Expand Down
4 changes: 2 additions & 2 deletions label_studio/users/product_tours/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Check warning on line 40 in label_studio/users/product_tours/api.py

View check run for this annotation

Codecov / codecov/patch

label_studio/users/product_tours/api.py#L35-L40

Added lines #L35 - L40 were not covered by tests
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}.')

Check warning on line 42 in label_studio/users/product_tours/api.py

View check run for this annotation

Codecov / codecov/patch

label_studio/users/product_tours/api.py#L42

Added line #L42 was not covered by tests

return tour

Check warning on line 44 in label_studio/users/product_tours/api.py

View check run for this annotation

Codecov / codecov/patch

label_studio/users/product_tours/api.py#L44

Added line #L44 was not covered by tests
25 changes: 15 additions & 10 deletions label_studio/users/product_tours/models.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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')
Expand Down

0 comments on commit 8bc6cf4

Please sign in to comment.