mirror of
https://github.com/barkeser2002/offline-db.git
synced 2026-09-25 02:19:59 +03:00
- Added `UserBadgeListAPIView`, `BadgeSerializer`, `UserBadgeSerializer` to expose user badges. - Added URL path `/api/users/badges/`. - Added logic for 'Night Owl' badge in `users/services.py` (watching between 2 AM and 5 AM). - Added data migration `0005_seed_night_owl.py`. - Added tests for Night Owl logic and API in `users/tests/test_badges.py` and `users/tests/test_badges_api.py`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
26 lines
767 B
Python
26 lines
767 B
Python
from django.db import migrations
|
|
|
|
def create_night_owl_badge(apps, schema_editor):
|
|
Badge = apps.get_model('users', 'Badge')
|
|
if not Badge.objects.filter(slug='night-owl').exists():
|
|
Badge.objects.create(
|
|
slug='night-owl',
|
|
name='Night Owl',
|
|
description='Watched an episode between 2 AM and 5 AM',
|
|
icon_url='/static/badges/night-owl.png'
|
|
)
|
|
|
|
def remove_night_owl_badge(apps, schema_editor):
|
|
Badge = apps.get_model('users', 'Badge')
|
|
Badge.objects.filter(slug='night-owl').delete()
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('users', '0004_notification'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(create_night_owl_badge, remove_night_owl_badge),
|
|
]
|