Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions zeeguu/api/endpoints/audio_lessons.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,11 @@ def check_daily_lesson_feasibility():
"feasible": true/false,
"available_words": 5,
"required_words": 2,
"has_feature_access": true,
"learned_language": "de",
"message": "Ready to generate lesson" | "Not enough words available" | "Feature not available"
"message": "Ready to generate lesson" | "Not enough words available"
}
"""
user = User.find_by_id(flask.g.user_id)

# Check if user has access to daily audio lessons
has_feature_access = user.has_feature("daily_audio")
if not has_feature_access:
return json_result({
"feasible": False,
"available_words": 0,
"required_words": 2,
"has_feature_access": False,
"learned_language": user.learned_language.code if user.learned_language else None,
"message": "Daily audio lessons feature not available for this user"
})

# Import the word selector to check available words
from zeeguu.core.audio_lessons.word_selector import select_words_for_audio_lesson
Expand All @@ -192,7 +179,6 @@ def check_daily_lesson_feasibility():
"feasible": feasible,
"available_words": available_words,
"required_words": required_words,
"has_feature_access": has_feature_access,
"learned_language": user.learned_language.code if user.learned_language else None,
"message": message
})
Expand Down
45 changes: 0 additions & 45 deletions zeeguu/core/audio_lessons/daily_lesson_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ def generate_daily_lesson_for_user(self, user, timezone_offset=0):
f"[generate_daily_lesson_for_user] Starting for user {user.id} ({user.name}), timezone_offset={timezone_offset}"
)

# Check if user has access to daily audio lessons
if not user.has_feature("daily_audio"):
log(
f"[generate_daily_lesson_for_user] User {user.id} does not have daily_audio feature"
)
return {
"error": "Daily audio lessons are not available for your account",
"status_code": 403,
}

# Check if a lesson already exists for today
log(f"[generate_daily_lesson_for_user] Checking for existing lesson today")
existing_lesson = self.get_todays_lesson_for_user(user, timezone_offset)
Expand Down Expand Up @@ -384,16 +374,6 @@ def generate_daily_lesson(
log(f"[generate_daily_lesson] Traceback: {traceback.format_exc()}")
return {"error": f"Unexpected error: {str(e)}"}

def _check_user_access(self, user):
"""Check if user has access to daily audio lessons."""
if not user.has_feature("daily_audio"):

return {
"error": "Daily audio lessons are not available for your account",
"status_code": 403,
}
return None

def _get_user_day_range_utc(self, timezone_offset=0):
"""
Get the start and end of today in the user's timezone, converted to UTC.
Expand Down Expand Up @@ -489,11 +469,6 @@ def get_daily_lesson_for_user(self, user, lesson_id=None):
Returns:
Dictionary with lesson details or error information
"""
# Check user access
access_error = self._check_user_access(user)
if access_error:
return access_error

if lesson_id:
# Get specific lesson by ID
try:
Expand Down Expand Up @@ -529,11 +504,6 @@ def get_todays_lesson_for_user(self, user, timezone_offset=0):
Returns:
Dictionary with lesson details or message if no lesson today
"""
# Check user access
access_error = self._check_user_access(user)
if access_error:
return access_error

# Get today's date range in UTC
start_of_today_utc, end_of_today_utc = self._get_user_day_range_utc(
timezone_offset
Expand Down Expand Up @@ -566,11 +536,6 @@ def delete_todays_lesson_for_user(self, user, timezone_offset=0):
Returns:
Dictionary with success message or error information
"""
# Check user access
access_error = self._check_user_access(user)
if access_error:
return access_error

# Get today's date range in UTC
start_of_today_utc, end_of_today_utc = self._get_user_day_range_utc(
timezone_offset
Expand Down Expand Up @@ -632,11 +597,6 @@ def get_past_daily_lessons_for_user(
Returns:
Dictionary with lessons list and pagination info or error information
"""
# Check user access
access_error = self._check_user_access(user)
if access_error:
return access_error

try:
# Get today's start time in UTC to exclude today's lessons
start_of_today_utc, _ = self._get_user_day_range_utc(timezone_offset)
Expand Down Expand Up @@ -744,11 +704,6 @@ def update_lesson_state_for_user(self, user, lesson_id, state_data):
Returns:
Dictionary with success message or error information
"""
# Check user access
access_error = self._check_user_access(user)
if access_error:
return access_error

try:
# Find the lesson
lesson = DailyAudioLesson.query.filter_by(
Expand Down
39 changes: 39 additions & 0 deletions zeeguu/core/model/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def details_as_dictionary(self):
and not any([c.cohort_id in [93, 459] for c in self.cohorts]),
is_anonymous=self.is_anonymous(),
bookmark_count=bookmark_count,
daily_audio_status=self.get_daily_audio_status(),
)

for each in UserLanguage.query.filter_by(user=self):
Expand Down Expand Up @@ -1101,6 +1102,44 @@ def has_feature(self, feature_name):

return is_feature_enabled_for_user(feature_name, self)

def get_daily_audio_status(self):
"""
Get the status of daily audio lesson for this user.
Returns: "available", "generating", "ready", "in_progress", "completed"
"""
from zeeguu.core.model import AudioLessonGenerationProgress, DailyAudioLesson
from datetime import datetime, timezone, timedelta

# Check if generation is in progress
active_progress = AudioLessonGenerationProgress.find_active_for_user(self)
if active_progress:
return "generating"

# Check for today's lesson (using UTC for simplicity)
today_start = datetime.now(timezone.utc).replace(
hour=0, minute=0, second=0, microsecond=0
).replace(tzinfo=None)
today_end = today_start + timedelta(days=1)

lesson = (
DailyAudioLesson.query.filter_by(
user_id=self.id, language_id=self.learned_language_id
)
.filter(DailyAudioLesson.created_at >= today_start)
.filter(DailyAudioLesson.created_at < today_end)
.first()
)

if not lesson:
return "available" # No lesson yet, user can generate one

if lesson.is_completed:
return "completed"
elif lesson.is_paused or (lesson.pause_position_seconds or 0) > 0:
return "in_progress"
else:
return "ready"

@classmethod
def find_all(cls):
query = zeeguu.core.model.db.session.query(User)
Expand Down
5 changes: 0 additions & 5 deletions zeeguu/core/user_feature_toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def _feature_map():
"no_audio_exercises": _no_audio_exercises,
"tiago_exercises": _tiago_exercises,
"new_topics": _new_topics,
"daily_audio": _daily_audio,
}


Expand Down Expand Up @@ -55,7 +54,3 @@ def _extension_experiment_1(user):
or user.id in [3372, 3373, 2953, 3427, 2705]
or user.id > 3555
)


def _daily_audio(user):
return True