49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
from django.core.paginator import Paginator
|
|
from django.http import JsonResponse
|
|
from django.shortcuts import get_object_or_404, render
|
|
from django.views.decorators.cache import never_cache
|
|
|
|
from apps.lottery.format import plm_text
|
|
from apps.lottery.models import LotteryConfig, Round
|
|
from apps.lottery.proof import round_proof
|
|
from apps.lottery.rules import WINNER_PERCENT
|
|
|
|
PAGE_SIZE = 20
|
|
|
|
|
|
def results(request):
|
|
"""Concluded rounds, newest first (WEB-12): who won is only ever an address of the public draw list."""
|
|
rounds = Round.objects.filter(status=Round.Status.CLOSED).order_by("-id")
|
|
page = Paginator(rounds, PAGE_SIZE).get_page(request.GET.get("pagina"))
|
|
rows = [{"id": r.pk, "closed_at": r.closed_at, "pool_text": plm_text(r.pool_amount_sats or 0),
|
|
"winner_text": plm_text(r.winner_amount_sats) if r.winner_amount_sats else "",
|
|
"has_winner": r.winner_id is not None} for r in page]
|
|
return render(request, "web/results.html", {"rows": rows, "page": page})
|
|
|
|
|
|
@never_cache
|
|
def result_detail(request, round_id):
|
|
round_ = get_object_or_404(Round.objects.select_related("payout_transaction"), pk=round_id)
|
|
return render(request, "web/result_detail.html", {"p": round_proof(round_), "round": round_})
|
|
|
|
|
|
@never_cache
|
|
def result_proof_json(request, round_id):
|
|
round_ = get_object_or_404(Round.objects.select_related("payout_transaction"), pk=round_id)
|
|
return JsonResponse(round_proof(round_))
|
|
|
|
|
|
def _terms():
|
|
config = LotteryConfig.get()
|
|
return {"bet_text": plm_text(config.bet_amount_sats), "winner_percent": WINNER_PERCENT,
|
|
"platform_percent": 100 - WINNER_PERCENT, "duration_minutes": max(1, config.round_duration_seconds // 60),
|
|
"confirmations": config.draw_confirmations}
|
|
|
|
|
|
def guide(request):
|
|
return render(request, "web/guide.html", _terms())
|
|
|
|
|
|
def rules(request):
|
|
return render(request, "web/rules.html", _terms())
|