Exemplo n.º 1
0
def removeoldvotes(request, sel_event_id):
    # Check rights
    if not request.user.has_perms("kompomaatti.delete_vote"):
        raise Http403

    # Don't proceed if the event is still ongoing
    event = get_object_or_404(Event, pk=int(sel_event_id))
    if utils.is_event_ongoing(event):
        raise Http404

    # Find compos belonging to this event
    compo_ids = Compo.objects.filter(event_id=int(sel_event_id)).values("pk")

    # Don't allow removing votes if votes haven't yet been consolidated to entry rows (prevent data loss)
    if utils.is_votes_unoptimized(compo_ids):
        raise Http404

    # Delete votes belonging to compos in this event
    Vote.objects.filter(compo__in=compo_ids).delete()

    # Log it
    logger.info("Event old votes removed.", extra={"user": request.user, "event": event})

    # All done, redirect
    return HttpResponseRedirect(reverse("manage-arkisto:archiver", args=(sel_event_id,)))
Exemplo n.º 2
0
def removeoldvotes(request, sel_event_id):
    # Check rights
    if not request.user.has_perms('kompomaatti.delete_vote'):
        raise Http403

    # Don't proceed if the event is still ongoing
    event = get_object_or_404(Event, pk=int(sel_event_id))
    if utils.is_event_ongoing(event):
        raise Http404

    # Find compos belonging to this event
    compo_ids = Compo.objects.filter(event_id=int(sel_event_id)).values('pk')

    # Don't allow removing votes if votes haven't yet been consolidated to entry rows (prevent data loss)
    if utils.is_votes_unoptimized(compo_ids):
        raise Http404

    # Delete votes belonging to compos in this event
    Vote.objects.filter(compo__in=compo_ids).delete()

    # Log it
    logger.info('Event old votes removed.',
                extra={
                    'user': request.user,
                    'event': event
                })

    # All done, redirect
    return HttpResponseRedirect(
        reverse('manage-arkisto:archiver', args=(sel_event_id, )))
Exemplo n.º 3
0
def archiver(request, sel_event_id):
    # Get event information
    event = get_object_or_404(Event, pk=sel_event_id)

    # Get archive user information for future use
    archiveuser = get_object_or_404(User, username="******")

    # Get Compo id's belonging to this event for future use
    compo_ids = Compo.objects.filter(event_id=int(sel_event_id)).values("pk")

    # Check if there are any compo entries that are not owner by archive user
    untransferred = False
    entries = Entry.objects.filter(compo__in=compo_ids)
    for entry in entries:
        if entry.user != archiveuser:
            untransferred = True
            break

    # Check if there are any participations that are not owner by archive user
    if not untransferred:
        competition_ids = Competition.objects.filter(event_id=int(sel_event_id)).values("pk")
        participations = CompetitionParticipation.objects.filter(competition__in=competition_ids)
        for part in participations:
            if part.user != archiveuser:
                untransferred = True
                break

    # Check if voting results need to be optimized
    votes_unoptimized = utils.is_votes_unoptimized(compo_ids)

    # Check if event is still ongoing
    ongoing_activity = utils.is_event_ongoing(event)

    # See if there are any old votes left
    old_votes_found = False
    votes = Vote.objects.filter(compo__in=compo_ids)
    if len(votes) > 0:
        old_votes_found = True

    # Render response
    return admin_render(
        request,
        "admin_arkisto/archiver.html",
        {
            "selected_event_id": int(sel_event_id),
            "is_archived": event.archived,
            "untransferred": untransferred,
            "ongoing_activity": ongoing_activity,
            "votes_unoptimized": votes_unoptimized,
            "old_votes_found": old_votes_found,
        },
    )
Exemplo n.º 4
0
def archiver(request, sel_event_id):
    # Get event information
    event = get_object_or_404(Event, pk=sel_event_id)

    # Get archive user information for future use
    archiveuser = get_object_or_404(User, username="******")

    # Get Compo id's belonging to this event for future use
    compo_ids = Compo.objects.filter(event_id=int(sel_event_id)).values('pk')

    # Check if there are any compo entries that are not owner by archive user
    untransferred = False
    entries = Entry.objects.filter(compo__in=compo_ids)
    for entry in entries:
        if entry.user != archiveuser:
            untransferred = True
            break

    # Check if there are any participations that are not owner by archive user
    if not untransferred:
        competition_ids = Competition.objects.filter(
            event_id=int(sel_event_id)).values('pk')
        participations = CompetitionParticipation.objects.filter(
            competition__in=competition_ids)
        for part in participations:
            if part.user != archiveuser:
                untransferred = True
                break

    # Check if voting results need to be optimized
    votes_unoptimized = utils.is_votes_unoptimized(compo_ids)

    # Check if event is still ongoing
    ongoing_activity = utils.is_event_ongoing(event)

    # See if there are any old votes left
    old_votes_found = False
    votes = Vote.objects.filter(compo__in=compo_ids)
    if len(votes) > 0:
        old_votes_found = True

    # Render response
    return admin_render(
        request, "admin_arkisto/archiver.html", {
            'selected_event_id': int(sel_event_id),
            'is_archived': event.archived,
            'untransferred': untransferred,
            'ongoing_activity': ongoing_activity,
            'votes_unoptimized': votes_unoptimized,
            'old_votes_found': old_votes_found,
        })