コード例 #1
0
ファイル: admin.py プロジェクト: maakuth/Instanssi.org
def givecode(request, vcrid):
    # Make sure the user is superuser.
    if not request.user.is_superuser:
        raise Http404

    # Get the request
    try:
        vcr = VoteCodeRequest.objects.get(id=vcrid)
    except VoteCodeRequest.DoesNotExist:
        raise Http404

    # Add votecode for user. Bang your head to the wall until you succeed, etc.
    # Really, do something about this later!
    # TODO: Do something about this shit!
    done = False
    for i in range(25):
        try:
            c = VoteCode()
            c.key = unicode(hashlib.md5(str(random.random())).hexdigest()[:8])
            c.associated_to = vcr.user
            c.time = datetime.now()
            c.save()
            done = True
            break
        except IntegrityError:
            pass

    if not done:
        raise HttpResponse("Virhe yritettäessä lisätä satunnaista avainta ... FIXME!")

    # Delete request
    vcr.delete()

    # Return to admin page
    return HttpResponseRedirect("/kompomaatti/admin/")
コード例 #2
0
def votecoderequests_accept(request, sel_event_id, vcrid):
    # CHeck for permissions
    if not request.user.has_perm('kompomaatti.change_votecode'):
        raise Http403

    # Get the request
    vcr = get_object_or_404(VoteCodeRequest, pk=vcrid)

    # Add votecode for user. Bang your head to the wall until you succeed, etc.
    try:
        c = VoteCode()
        c.event_id = int(sel_event_id)
        c.key = str(hashlib.md5(bytes(os.urandom(8))).hexdigest()[:8])
        c.associated_to = vcr.user
        c.time = datetime.now()
        c.save()
        logger.info('Votecode request from "{}" accepted.'.format(vcr.user.username),
                    extra={'user': request.user, 'event_id': sel_event_id})
        done = True
    except IntegrityError:
        done = False

    # Didn't happen, user likely already has votecode
    if not done:
        logger.info('Votecode request from "{}" scrapped; user already has votecode.'.format(vcr.user.username),
                    extra={'user': request.user, 'event_id': sel_event_id})

    # Request handled, delete it
    vcr.delete()

    # Return to admin page
    return HttpResponseRedirect(reverse('manage-kompomaatti:votecoderequests', args=(sel_event_id,))) 
コード例 #3
0
ファイル: views.py プロジェクト: k2h/Instanssi.org
def votecoderequests_accept(request, sel_event_id, vcrid):
    # CHeck for permissions
    if not request.user.has_perm('kompomaatti.change_votecode'):
        raise Http403

    # Get the request
    vcr = get_object_or_404(VoteCodeRequest, pk=vcrid)

    # Add votecode for user. Bang your head to the wall until you succeed, etc.
    try:
        c = VoteCode()
        c.event_id = int(sel_event_id)
        c.key = str(hashlib.md5(bytes(os.urandom(8))).hexdigest()[:8])
        c.associated_to = vcr.user
        c.time = timezone.now()
        c.save()
        logger.info('Votecode request from "{}" accepted.'.format(
            vcr.user.username),
                    extra={
                        'user': request.user,
                        'event_id': sel_event_id
                    })
        done = True
    except IntegrityError:
        done = False

    # Didn't happen, user likely already has votecode
    if not done:
        logger.info(
            'Votecode request from "{}" scrapped; user already has votecode.'.
            format(vcr.user.username),
            extra={
                'user': request.user,
                'event_id': sel_event_id
            })

    # Request handled, delete it
    vcr.delete()

    # Return to admin page
    return HttpResponseRedirect(
        reverse('manage-kompomaatti:votecoderequests', args=(sel_event_id, )))
コード例 #4
0
def givecode(request, vcrid):
    # Make sure the user is superuser.
    if not request.user.is_superuser:
        raise Http404

    # Get the request
    try:
        vcr = VoteCodeRequest.objects.get(id=vcrid)
    except VoteCodeRequest.DoesNotExist:
        raise Http404

    # Add votecode for user. Bang your head to the wall until you succeed, etc.
    # Really, do something about this later!
    # TODO: Do something about this shit!
    done = False
    for i in range(25):
        try:
            c = VoteCode()
            c.key = unicode(hashlib.md5(str(random.random())).hexdigest()[:8])
            c.associated_to = vcr.user
            c.time = datetime.now()
            c.save()
            done = True
            break
        except IntegrityError:
            pass

    if not done:
        raise HttpResponse(
            "Virhe yritettäessä lisätä satunnaista avainta ... FIXME!")

    # Delete request
    vcr.delete()

    # Return to admin page
    return HttpResponseRedirect('/kompomaatti/admin/')