Ejemplo n.º 1
0
Archivo: views.py Proyecto: sk364/Ozone
def index(request):
    """
    Main view for contests page
    : Shows all the present, past, ccurrent and user's contests
    """

    upcoming = Contest.objects.filter(
        Q(start_date__gt=datetime.datetime.now())
        & Q(allowed=1)).order_by('-start_date')

    current = Contest.objects.filter(
        Q(start_date__lte=datetime.datetime.now())
        & Q(end_date__gt=datetime.datetime.now())
        & Q(allowed=1)).order_by('-start_date')

    usrs_contest = Contest.objects.filter(Q(admin=request.user))

    past_contests = Contest.objects.filter(
        Q(end_date__lt=aware(datetime.datetime.now())))

    return render(
        request, 'contests/contests.html', {
            'upcoming': upcoming,
            'current': current,
            'usrs_contest': usrs_contest,
            'past_contests': past_contests
        })
Ejemplo n.º 2
0
Archivo: views.py Proyecto: sk364/Ozone
def get_tag(request, code):
    tag = Tag.objects.get(code=code)
    now = aware(dt.now())
    problems = filter(lambda t: now > t.problem.contest.end_date,
                      ProblemTag.objects.filter(tag=tag))

    return render(request, 'practice/problems.html', {'problems': problems})
Ejemplo n.º 3
0
Archivo: views.py Proyecto: sk364/Ozone
def should_update_solved(request, problem):
    already_solved = already(request.user, problem)
    contest_started = problem.contest.start_date <= aware(
        datetime.datetime.now())
    user_not_admin = problem.contest.admin != request.user

    return not already_solved and contest_started and user_not_admin
Ejemplo n.º 4
0
Archivo: forms.py Proyecto: sk364/Ozone
    def clean_start_date(self):

        now = aware(datetime.datetime.now())

        if now >= self.cleaned_data['start_date']:
            raise forms.ValidationError("Past dates are not allowed.")

        return self.cleaned_data['start_date']
Ejemplo n.º 5
0
Archivo: forms.py Proyecto: sk364/Ozone
    def clean_end_date(self):

        now = aware(datetime.datetime.now())

        condition = self.cleaned_data['end_date'] <= self.cleaned_data['start_date']
        if now >= self.cleaned_data['end_date'] or condition:
            raise forms.ValidationError("Invalid time")

        return self.cleaned_data['end_date']
Ejemplo n.º 6
0
Archivo: views.py Proyecto: sk364/Ozone
def contest(request, code):
    """
    View which provides the main view of a particular contest
    Variables
    # con: contest asked
    # dt: difference between current time and start time of contest
    # pp: if contest has passed or not.
    """
    con = get_object_or_404(Contest, Q(contest_code=code))

    dt = aware(datetime.datetime.now()) - con.start_date
    if dt.days < 0 or dt.seconds < 0:
        pp = True
    else:
        pp = False
    return render(request, 'contests/contest.html', {'contest': con, 'pp': pp})
Ejemplo n.º 7
0
Archivo: views.py Proyecto: sk364/Ozone
def rankings(request, contest):
    """
    The view to show the ranking of a particular contest.
    Variables
    # con: The contest whose ranking is to be shown
    # data: THe sorted ranking according to effective scores of users
    """
    con = get_object_or_404(Contest, contest_code=contest)
    if (con.start_date <= aware(datetime.datetime.now())):
        data = sorted(Ranking.objects.filter(Q(contest=con)),
                      key=lambda t: (-t.effective_score, t.penalty))
        return render(request, 'contests/ranking.html', {
            'con': data,
            'contest': con
        })
    else:
        return render(request, 'contests/ranking.html', {
            'con': None,
            'contest': con
        })
Ejemplo n.º 8
0
Archivo: views.py Proyecto: sk364/Ozone
def deletec(request, contest):
    """
    View to delete a particular contest
    Returns JSON response of success of failure
    Variables
    # con: Contest to be deleted
    """
    con = get_object_or_404(Contest, contest_code=contest)

    if con.start_date >= aware(datetime.datetime.now()):
        request.user.profile.tobecon = False
        request.user.profile.save()
        import os, shutil
        for problem in con.problem_set.all():
            path_to_remove = os.path.join(os.getcwd(),
                                          f'tmp/problems/{problem.code}')
            if os.path.exists(path_to_remove):
                shutil.rmtree(path_to_remove)
        con.delete()
        return JsonResponse({'done': 'Yes, Did that.'}, status=200)
    return JsonResponse({'done': 'Nope cant do that'}, status=200)
Ejemplo n.º 9
0
Archivo: views.py Proyecto: sk364/Ozone
def editc(request, code):
    """
    This view is to edit a particular contest
    Variables
    # contest: Contest to be edited
    # allow_edit: Allow edit if allow_edit is True means allow only if contest
                  is ongoing or upcoming
    """
    contest = get_object_or_404(
        Contest,
        Q(contest_code=code)
        & Q(end_date__gte=datetime.datetime.now()))
    if contest.admin == request.user:
        if contest.end_date >= aware(datetime.datetime.now()):
            allow_edit = True
        else:
            allow_edit = False

        return render(request, 'contests/editc.html', {
            'contest': contest,
            'aled': allow_edit
        })

    return render(request, 'contests/editc.html', {'contest': False})