Beispiel #1
0
def index(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    
    # Add urls and formatted timestamps to event list
    events = []
    for event in get_upcoming(event):
        event['formatted_time'] = awesometime.format_single(event['date'])
        if event['type'] == 1:
            event['url'] = reverse('km:compo', args=(event_id, event['id'],))
        elif event['type'] == 2:
            event['url'] = reverse('km:competition', args=(event_id, event['id'],))
        else:
            event['url'] = None
    
        # Add to list
        events.append(event)
    
    # Check if user has an associated vote code
    votecode_associated = False
    if request.user.is_authenticated():
        # See if user has a separate votecode
        try:
            VoteCode.objects.get(event=event_id, associated_to=request.user)
            votecode_associated = True
        except VoteCode.DoesNotExist:
            pass

        # See if ticket is used as votecode
        try:
            TicketVoteCode.objects.get(event=event_id, associated_to=request.user)
            votecode_associated = True
        except TicketVoteCode.DoesNotExist:
            pass
    else:
        votecode_associated = True

    # Get compos the user has not yet voted on
    not_voted_on = []
    if request.user.is_active and request.user.is_authenticated() and votecode_associated:
        for compo in Compo.objects.filter(event=event_id, active=True):
            if compo.is_voting_open():
                if Vote.objects.filter(user=request.user, compo=compo).count() == 0:
                    not_voted_on.append(compo)

    # Has profile already been checked and saved
    profile_checked = False
    if request.user.is_authenticated() and Profile.objects.filter(user=request.user).exists():
        profile_checked = True

    # All done, dump template
    return render(request, 'kompomaatti/index.html', {
        'sel_event_id': int(event_id),
        'events': events,
        'not_voted_on': not_voted_on,
        'votecode_associated': votecode_associated,
        'profile_checked': profile_checked
    })
Beispiel #2
0
def index(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    
    # Add urls and formatted timestamps to event list
    events = []
    for event in get_upcoming(event):
        event['formatted_time'] = awesometime.format_single(event['date'])
        if event['type'] == 1:
            event['url'] = reverse('km:compo', args=(event_id, event['id'],))
        elif event['type'] == 2:
            event['url'] = reverse('km:competition', args=(event_id, event['id'],))
        else:
            event['url'] = None
    
        # Add to list
        events.append(event)
    
    # Check if user has an associated vote code
    votecode_associated = False
    if request.user.is_authenticated:
        # See if ticket is used as votecode
        try:
            TicketVoteCode.objects.get(event=event_id, associated_to=request.user)
            votecode_associated = True
        except TicketVoteCode.DoesNotExist:
            pass
        # See if votecode request is accepted
        try:
            VoteCodeRequest.objects.get(event=event_id, user=request.user, status=1)
            votecode_associated = True
        except VoteCodeRequest.DoesNotExist:
            pass
    else:
        votecode_associated = True

    # Get compos the user has not yet voted on
    not_voted_on = []
    if request.user.is_active and request.user.is_authenticated and votecode_associated:
        for compo in Compo.objects.filter(event=event_id, active=True):
            if compo.is_voting_open():
                if Vote.objects.filter(user=request.user, compo=compo).count() == 0:
                    not_voted_on.append(compo)

    # Has profile already been checked and saved
    profile_checked = False
    if request.user.is_authenticated and Profile.objects.filter(user=request.user).exists():
        profile_checked = True

    # All done, dump template
    return render(request, 'kompomaatti/index.html', {
        'sel_event_id': int(event_id),
        'events': events,
        'not_voted_on': not_voted_on,
        'votecode_associated': votecode_associated,
        'profile_checked': profile_checked
    })
Beispiel #3
0
def events_api(request, hid):
    # Get event
    e = None
    try:
        e = Event.objects.get(pk=hid)
    except Event.DoesNotExist:
        return JSONResponse({'error': 1})

    # Get upcoming stuff
    events = []
    for event in get_upcoming(e):
        event['date'] = event['date'].strftime("%d.%m.%Y %H:%M")
        events.append(event)

    return JSONResponse({'events': events})
Beispiel #4
0
def events_api(request, event_id):
    e = get_object_or_404(Event, pk=event_id)

    # Get upcoming stuff
    k = 0
    events = []
    for event in get_upcoming(e):
        event['date'] = event['date'].strftime("%H:%M")
        events.append(event)

        # Only pick 5
        k += 1
        if k >= 5:
            break

    return JSONResponse({'events': events})
Beispiel #5
0
def events_api(request, event_id):
    e = get_object_or_404(Event, pk=event_id)

    # Get upcoming stuff
    k = 0
    events = []
    for event in get_upcoming(e):
        event['date'] = arrow.get(event['date']).to(settings.TIME_ZONE).format("HH:mm")
        events.append(event)
        
        # Only pick 5
        k += 1
        if k >= 5:
            break

    return JSONResponse({'events': events})
Beispiel #6
0
def events_api(request, event_id):
    e = get_object_or_404(Event, pk=event_id)

    # Get upcoming stuff
    k = 0
    events = []
    for event in get_upcoming(e):
        event['date'] = event['date'].strftime("%H:%M")
        events.append(event)
        
        # Only pick 5
        k += 1
        if k >= 5:
            break

    return JSONResponse({'events': events})
Beispiel #7
0
def index(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    
    # Add urls and formatted timestamps to eventslist
    events = []
    k = 0
    for event in get_upcoming(event):
        event['formatted_time'] = awesometime.format_single(event['date'])
        if event['type'] == 1:
            event['url'] = reverse('km:compo', args=(event_id, event['id'],))
        elif event['type'] == 2:
            event['url'] = reverse('km:competition', args=(event_id, event['id'],))
        else:
             event['url'] = None
    
        # Add to list
        events.append(event)
    
        # Only pick 10
        k = k + 1
        if k >= 10:
            break
    
    # Check if user has an associated vote code
    votecode_associated = False
    if request.user.is_authenticated():
        try:
            VoteCode.objects.get(event=event_id, associated_to=request.user)
            votecode_associated = True
        except VoteCode.DoesNotExist:
            pass
    else:
        votecode_associated = True
    
    # All done, dump template
    return render_to_response('kompomaatti/index.html', {
        'sel_event_id': int(event_id),
        'events': events,
        'votecode_associated': votecode_associated,
    }, context_instance=RequestContext(request))
Beispiel #8
0
def django_get_upcoming(event):
    return get_upcoming(event)[:5]