Ejemplo n.º 1
0
def create(request):
    if request.method == "POST":  # If the form has been submitted...
        form = EventForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # TODO(xingjie): Process the data in form.cleaned_data
            new_event = form.save()
            return HttpResponseRedirect(reverse("event.views.preview", args=(new_event.id,)))  # Redirect after POST
    else:
        form = EventForm()  # An unbound form

    return render_to_response("event/create.html", {"form": form}, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def events(id=None):
    if id:
        event = Event.objects.get(pk=id)
        event.update_timezone()
        add_form = EventForm(request.form, obj=event)
        title_aside = u'Éditer l\'événement'
    else:
        event = Event()
        add_form = EventForm()
        title_aside = u'Créer un événement'

    if add_form.organisations.data:
        add_form.organisations.choices = make_choices(add_form.orgas_choices, selected=add_form.organisations.data, name='Organisations')

    if add_form.places.data:
        add_form.places.choices = make_choices(add_form.places_choices, selected=add_form.places.data, name='Lieux')

    if add_form.validate_on_submit():
        event.title = add_form.title.data
        event.description = add_form.description.data
        event.organisations = add_form.organisations.data
        event.places = add_form.places.data

        if not event.author:
            event.author = current_user.to_dbref()

        event.datetime_first = arrow.get(add_form.datetime_first.data).datetime
        event.datetime_last = arrow.get(add_form.datetime_last.data).datetime
        event.update_timezone()

        if current_user.has_role('Administrateur') or current_user.has_role('Éditeur'):
            event.status = 'published' if 'publish' in request.form else 'draft'
        else:
            event.status = 'validation' if 'publish' in request.form else 'draft'

        event.save()
        if id:
            return redirect('/events')

    # Filter the events for non-admin users
    if not current_user.has_role('Administrateur'):
        filter_role = {'organisations__in': current_user.associations}
    else:
        filter_role = {}

    today = arrow.now().date()
    events_draft = Event.objects(status='draft', **filter_role).order_by('datetime_first')
    events_validation = Event.objects(status='validation', datetime_first__gte=today, **filter_role).order_by('datetime_first')
    events_published = Event.objects(status='published', datetime_first__gte=today).order_by('datetime_first')

    return render_template('events.html', events_draft=events_draft, events_validation=events_validation, events_published=events_published, add_form=add_form, title_aside=title_aside, icons=icons)
Ejemplo n.º 3
0
def event_new(request):
    event_types = EventType.objects.all()
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save()
            messages.success(request, _("Created new event"))
            return HttpResponseRedirect(reverse('event', args=[event.id]))
    elif 'date' in request.GET:
        form = EventForm(initial={'date': request.GET['date']})
    else:
        form = EventForm()
    return render_to_response('event/event_new.html', {
        'form': form,
        'event_types': event_types,
        },
        context_instance=RequestContext(request),
    )
Ejemplo n.º 4
0
def event_edit(request, event_id):
    event = get_object_or_404(Event, pk=event_id)
    event_types = EventType.objects.all()

    if request.method == 'POST':
        form = EventForm(request.POST, instance=event)
        if form.is_valid():
            form.save()
            messages.success(request, _("Saved changes"))
            return HttpResponseRedirect(reverse('event', args=[event.id]))
    else:
        form = EventForm(instance=event)
    return render_to_response('event/event_edit.html', {
        'form': form,
        'event': event,
        'event_types': event_types,
        },
        context_instance=RequestContext(request),
    )