Exemplo n.º 1
0
def new_event_start(request):
    team = request.user.profile.personal_team

    new_event = Event(team=team, created_by=request.user.profile)

    if request.method == 'GET':
        form = NewEventForm(instance=new_event)

        context = {
            'event': new_event,
            'team': team,
            'event_form': form,
        }
        return render(request, 'get_together/new_event/create_event.html', context)
    elif request.method == 'POST':
        form = NewEventForm(request.POST, instance=new_event)
        if form.is_valid:
            new_event = form.save()
            Attendee.objects.create(event=new_event, user=request.user.profile, role=Attendee.HOST, status=Attendee.YES)

            messages.add_message(request, messages.SUCCESS, message=_('Your event has been scheduled! Next, find a place for your event.'))
            ga.add_event(request, action='new_event', category='activity', label=new_event.get_full_url())

            return redirect('new-event-add-place', new_event.id)
        else:
            context = {
                'event': new_event,
                'team': team,
                'event_form': form,
            }
            return render(request, 'get_together/new_event/create_event.html', context)
    else:
        return redirect('home')
Exemplo n.º 2
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))
Exemplo n.º 3
0
def new_event_start(request):
    team = request.user.profile.personal_team

    new_event = Event(team=team, created_by=request.user.profile)

    if request.method == "GET":
        form = NewEventForm(instance=new_event)

        context = {"event": new_event, "team": team, "event_form": form}
        return render(request, "get_together/new_event/create_event.html", context)
    elif request.method == "POST":
        form = NewEventForm(request.POST, instance=new_event)
        if form.is_valid:
            new_event = form.save()
            Attendee.objects.create(
                event=new_event,
                user=request.user.profile,
                role=Attendee.HOST,
                status=Attendee.YES,
            )

            messages.add_message(
                request,
                messages.SUCCESS,
                message=_(
                    "Your event has been scheduled! Next, find a place for your event."
                ),
            )
            ga.add_event(
                request,
                action="new_event",
                category="activity",
                label=new_event.get_full_url(),
            )

            return redirect("new-event-add-place", new_event.id)
        else:
            context = {"event": new_event, "team": team, "event_form": form}
            return render(request, "get_together/new_event/create_event.html", context)
    else:
        return redirect("home")
Exemplo n.º 4
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))