<commit_before>from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.core.exceptions import PermissionDenied
from django.db import transaction, models

from app import models as data
from app.staff.forms import FastSendForm
from app.models import Card, History, user_permission


@login_required
def dashboard(request):
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if user_permission(request.user) < 3:
        return redirect('lite')
    players = data.Player.objects.all()
    cards = data.Card.objects.all()
    teams = data.Team.objects.all()
    history_entries = data.History.objects.all().order_by('-date')[:30]
    return render(request, 'staff/dashboard.html', locals())

@login_required
def leaderboard(request):
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if user_permission(request.user) < 3:
        return redirect('lite')
    players = data.Player.objects.all()
    cards = data.Card.objects.all()
    lencards = len(cards)
    lencardsgot = len([x for x in cards if x.retrieved])
    totalpoints = data.Card.objects.filter(active=True).aggregate(models.Sum('value'))["value__sum"]
    totalpointsgot = data.Card.objects.filter(retrieved=True).aggregate(models.Sum('value'))["value__sum"]
    teams = data.Team.objects.all().exclude(tid="zsh")
    sorted_teams = list(teams)
    sorted_teams.sort(key=lambda x: x.points, reverse=True)
    history_entries = data.History.objects.all().order_by('-date')[:30]
    return render(request, 'staff/leaderboard.html', locals())


@login_required
def lite(request, tt=None):
    denomination = [32, 64, 128, 256, -64]
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if tt is not None:
        try:
            tt = int(tt)
        except:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "我幫你綁好繩子了，"
                    "你要自己跳還是我推你跳呢？（本繩載重20g）"})
        if tt not in range(0, len(denomination)):
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢？"
                    "(如果是POST奇怪的資料，可能會收到彈力繩喔ˊ_>ˋ)"
                })
        with transaction.atomic():
            card = Card()
            present = request.user.first_name
            if present == "":
                present = '祝福'
            card.name = "來自 %s 的%s" % (request.user.last_name, present)<commit_msg>add more card in lite<commit_after>from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.core.exceptions import PermissionDenied
from django.db import transaction, models

from app import models as data
from app.staff.forms import FastSendForm
from app.models import Card, History, user_permission


@login_required
def dashboard(request):
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if user_permission(request.user) < 3:
        return redirect('lite')
    players = data.Player.objects.all()
    cards = data.Card.objects.all()
    teams = data.Team.objects.all()
    history_entries = data.History.objects.all().order_by('-date')[:30]
    return render(request, 'staff/dashboard.html', locals())

@login_required
def leaderboard(request):
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if user_permission(request.user) < 3:
        return redirect('lite')
    players = data.Player.objects.all()
    cards = data.Card.objects.all()
    lencards = len(cards)
    lencardsgot = len([x for x in cards if x.retrieved])
    totalpoints = data.Card.objects.filter(active=True).aggregate(models.Sum('value'))["value__sum"]
    totalpointsgot = data.Card.objects.filter(retrieved=True).aggregate(models.Sum('value'))["value__sum"]
    teams = data.Team.objects.all().exclude(tid="zsh")
    sorted_teams = list(teams)
    sorted_teams.sort(key=lambda x: x.points, reverse=True)
    history_entries = data.History.objects.all().order_by('-date')[:30]
    return render(request, 'staff/leaderboard.html', locals())


@login_required
def lite(request, tt=None):
    denomination = [32, 64, 128, 256, -16, -32, -64]
    if user_permission(request.user) < 2:
        raise PermissionDenied
    if tt is not None:
        try:
            tt = int(tt)
        except:
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "我幫你綁好繩子了，"
                    "你要自己跳還是我推你跳呢？（本繩載重20g）"})
        if tt not in range(0, len(denomination)):
            return render(
                request, "submit.html", {
                    "success": False,
                    "title": "發送卡片失敗",
                    "content": "要不要去戳戳系統管理員呢？"
                    "(如果是POST奇怪的資料，可能會收到彈力繩喔ˊ_>ˋ)"
                })
        with transaction.atomic():
            card = Card()
            present = request.user.first_name
            if present == "":
                present = '祝福'
            card.name = "來自 %s 的%s" % (request.user.last_name, present)
{'fraction_non_alphanumeric': 0.12293233082706767, 'fraction_numerical': 0.009774436090225564, 'mean_word_length': 2.5308560053085603, 'pattern_counts': {'":': 14, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4395293', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1710, 'n_words': 349}