Exemple #1
0
def admin_events(request, association_name):

    association = get_object_or_404(Association, name=association_name)
    current_year = association.signing_year  # util.get_current_year()

    # The connected user must be a board member (status < 5)
    if not Member.objects.filter(
            user=request.user.id, association=association.id,
            year=current_year, status__lt=5).exists():
        raise PermissionDenied

    events = Event.objects.filter(organizer=association.id)

    upcoming_events = events.filter(
        day__gte=datetime.today()).order_by('day', 'start_time')

    past_events = events.filter(
        day__lt=datetime.today()).order_by('day', 'start_time')

    # TODO rename form var name
    form = NewEventForm(request.POST or None, request.FILES or None)
    active_forms = {}  # TODO remove unsused form sets

    if 'action' in request.POST and request.POST['action'] == "new_event":
        if form.is_valid():
            new_event = form.save(commit=False)
            new_event.organizer_id = association.id
            form.save()

            announcement = Announcement(
                title=u"Participez à l'événement « %s » !" % new_event.title,
                category=0,
                content=u"""L'association %s vous invite à participer à son
                        événement « <b>%s</b> », venez vous inscrire
                        <a href="%s">ici</a>.""" % (association.name, new_event.title,
                            reverse('events.views.display_event', args=(new_event.id,))))
            announcement.save()
        else:
            active_forms['new_event'] = True

    return render_to_response(
        "admin_events.html",
        {
            'request': request,
            'association': association,
            'upcoming_events': upcoming_events,
            'past_events': past_events,
            'active_forms': active_forms,
            'form': form
        },
        context_instance=RequestContext(request))
Exemple #2
0
def admin_events_edit(request, association_name, event_id, *args):
    
    association = get_object_or_404(Association, name=association_name)
    current_year = association.signing_year  # util.get_current_year()

    # The connected user must be a board member (status < 5)
    if not Member.objects.filter(
            user=request.user.id, association=association.id,
            year=current_year, status__lt=5).exists():
        raise PermissionDenied

    participants = Registration.objects.filter(event=event_id)
    paid = participants.filter(paid=True)
    unpaid = participants.filter(paid=False)

    active_forms = {}  # TODO remove unsused form sets

    if 'action' in request.POST and request.POST['action'] == "edit_event":
        form = NewEventForm(request.POST or None, request.FILES or None)
        event = get_object_or_404(
            Event, id=event_id, organizer=association.id)

        if form.is_valid():
            new_event = form.save(commit=False)
            new_event.id = event_id
            new_event.organizer_id = association.id
            form.save()
        else:
            active_forms['new_event'] = True

    else:
        event = get_object_or_404(
            Event, id=event_id, organizer=association.id)
        form = NewEventForm(instance=event)

    return render_to_response(
        "admin_events_edit.html",
        {
            'request': request,
            'association': association,
            'event': event,
            'participants': participants,
            'paid': paid,
            'unpaid': unpaid,
            'form': form,
            'active_forms': active_forms,
            'tab': args[0]['tab'] if args else False
        },
        context_instance=RequestContext(request))