All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
from datetime import date
|
|
|
|
from django.shortcuts import render, redirect
|
|
from django.urls import reverse
|
|
|
|
from .models import Mineral
|
|
|
|
|
|
def daily_stone(request):
|
|
today = date.today()
|
|
day = today.timetuple().tm_yday
|
|
total = Mineral.objects.count()
|
|
|
|
if total == 0:
|
|
return render(request, 'dailystone/stone.html', {'mineral': None})
|
|
|
|
# Wrap around if we have fewer minerals than days in the year
|
|
index = (day - 1) % total + 1
|
|
mineral = Mineral.objects.filter(day_of_year=index).first()
|
|
|
|
# Fallback: pick by modulo of pk list
|
|
if not mineral:
|
|
minerals = list(Mineral.objects.all())
|
|
mineral = minerals[(day - 1) % len(minerals)]
|
|
|
|
return render(request, 'dailystone/stone.html', {
|
|
'mineral': mineral,
|
|
'today': today,
|
|
})
|
|
|
|
|
|
def random_stone(request):
|
|
mineral = Mineral.objects.order_by('?').first()
|
|
if not mineral:
|
|
return redirect('dailystone:daily_stone')
|
|
return render(request, 'dailystone/stone.html', {
|
|
'mineral': mineral,
|
|
'today': date.today(),
|
|
'is_random': True,
|
|
})
|