Beispiel #1
0
def edit_event_view(request, eventid):
    event = get_object_or_404(Event, id=eventid)
    if event.schedule.creator != request.user:
        return render(request, "scheduler/errorpage.html", {'message':"PERMISSION DENIED"})
    if request.method == 'POST':
        form = EventForm(instance=event,data=request.POST)
        if form.is_valid():
            form.save()
            return redirect("/schedule/"+str(event.schedule.id))
        else:
            return render(request, "scheduler/createevent.html",{'form':form,'edit':'edit','event':event})
    else:
        form = EventForm(instance=event)
        return render(request, "scheduler/createevent.html",{'form':form,'edit':'edit','event':event})
Beispiel #2
0
def create_event_view(request,scheduleid):
    schedule = get_object_or_404(Schedule, id=scheduleid) # The parent schedule
    # If the current user does not own the schedule, do not allow them to create an event on it.
    if schedule.creator != request.user:
        return render(request, "scheduler/errorpage.html", {'message':"PERMISSION DENIED"})
    form = EventForm(data=request.POST) # Load the form
    if request.method == 'POST':
        if form.is_valid():
            event = form.save(commit = False) # Get an event with the form data (don't commit to db yet)
            event.schedule = schedule # Set the parent schedule
            event.save() # NOW we can save to the database.
            return redirect("/schedule/"+str(event.schedule.id)) 
        else:
            return render(request, "scheduler/createevent.html",{'form':form,'schedule':schedule})
    else:
        return render(request, "scheduler/createevent.html",{'form':form,'schedule':schedule})
def new_event():
    form = EventForm()
    if form.validate_on_submit():
        event = Event(start=form.start.data,
                      end=form.end.data,
                      subject=form.subject.data,
                      description=form.description.data,
                      author=current_user)
        db.session.add(event)
        db.session.commit()
        flash('Your event has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_event.html',
                           title='New Event',
                           form=form,
                           legend='New Event')
def load_schedule_modal(context):
    return {
        'forms': {
            'event': EventForm(),
            'appointment': AppointmentForm()
        },
    }
Beispiel #5
0
def create_event_view(request,scheduleid):
    schedule = get_object_or_404(Schedule, id=scheduleid) # The parent schedule
    # If the current user does not own the schedule, do not allow them to create an event on it.
    if schedule.creator != request.user:
        return render(request, "scheduler/errorpage.html", {'message':"PERMISSION DENIED"})
    if request.method == 'POST':
        form = EventForm(data=request.POST) # Load the form
        if form.is_valid():
            event = form.save(commit = False) # Get an event with the form data (don't commit to db yet)
            event.schedule = schedule # Set the parent schedule
            event.save() # NOW we can save to the database.
            return redirect("/schedule/"+str(event.schedule.id))
        else:
            return render(request, "scheduler/createevent.html",{'form':form,'schedule':schedule})
    else:
        form = EventForm()
        return render(request, "scheduler/createevent.html",{'form':form,'schedule':schedule})
Beispiel #6
0
def add_event(request):
    context = RequestContext(request)
    context_dict = {}
    if request.user.is_authenticated():  # make sure user is logged in
        venue_manager = UserProfile.objects.get(user=request.user)
        if venue_manager.is_venue:  # make sure manages a venue
            if request.method == 'POST':
                form = EventForm(request.POST)
                if form.is_valid():
                    venue_manager = UserProfile.objects.get(user=request.user)
                    event = form.save(commit=False)
                    event.location = venue_manager.location
                    event.begin_date = str(
                        form.cleaned_data['begin_date']) + ' ' + str(
                            form.cleaned_data['begin_time'])
                    event.end_date = str(
                        form.cleaned_data['end_date']) + ' ' + str(
                            form.cleaned_data['end_time'])
                    event.save()
                    url = '/event/' + str(event.id)
                    return redirect(url)
                else:
                    print(form.errors)
            else:
                form = EventForm()
                context_dict['form'] = form
                return render_to_response('add_event.html', context_dict,
                                          context)
        else:
            return redirect('/')

    else:
        return HttpResponseRedirect(
            '/login/')  # if user is not logged in, go to log in screen
def update_event(event_id):
    event = Event.query.get_or_404(event_id)
    if event.author != current_user:
        abort(403)
    form = EventForm()
    if form.validate_on_submit():
        event.start = form.start.data
        event.end = form.end.data
        event.subject = form.subject.data
        event.description = form.description.data
        db.session.commit()
        flash('Your event has been updated!', 'success')
        return redirect(url_for('event', event_id=event.id))
    elif request.method == 'GET':
        form.start.data = event.start
        form.end.data = event.end
        form.subject.data = event.subject
        form.description.data = event.description
    return render_template('create_event.html',
                           title='Update Event',
                           form=form,
                           legend='Update Event')
Beispiel #8
0
def add_event(request, owner_type, owner_id):
    """ Add an event to the calendar belonging to the owner of ownder id only
    if the current user has permission to do so"""

    # Like before, get the request's context.
    context = RequestContext(request)
    event_added = False

    user = request.user
    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        verified_obj = verified_calendar(context, owner_type, owner_id, user)
        if not isinstance(verified_obj, HttpResponse):
            calendar, edit_priv = verified_obj
        else:
            return verified_obj

        # Attempt to grab information from the raw form information.
        event_form = EventForm(data=request.POST)
        if event_form.is_valid():
            # Save the event's form data to the database.
            event = event_form.save(commit=False)
            event.cal = calendar
            event.creator = user

            event.save()

            event_added = True

            #notify the subscribers
            created_event.send(sender=None,
                               owner_type=owner_type,
                               owner_id=owner_id,
                               event=event,
                               user=user)

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print event_form.errors

    # Not a HTTP POST, so we render our form using the EventForm.
    # These forms will be blank, ready for user input.
    else:
        event_form = EventForm()

    # Render the template depending on the context.
    return render_to_response('scheduler/add_event.html', {
        'event_form': event_form,
        'user': user,
        'event_added': event_added
    }, context)
Beispiel #9
0
def update_event(request, owner_type, owner_id, event_id):
    """Return the event with event_id if the current user has permission to
    view the calendar to which the event belongs"""
    # Like before, get the request's context.
    context = RequestContext(request)

    user = request.user

    verified_obj = verified_calendar(context, owner_type, owner_id, user)
    if not isinstance(verified_obj, Calendar):
        calendar = verified_obj
    else:
        return verified_obj

    event = Event.objects.get(id=int(event_id))

    #If the event mentioned doesn't belong to the calendar
    if not (event.creator.id == user.id or event.cal.id == calendar.id):
        #return HttpResponse('You do not have permission to edit this event')
        return render_permission_denied(context, 'edit this event')

    event_added = False
    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        event_form = EventForm(data=request.POST, instance=event)
        if (event_form.is_valid()):
            e = event_form.save(commit=False)
            e.save()
            event_added = True
            #notify the subscribers
            updated_event.send(sender=None,
                               owner_type=owner_type,
                               owner_id=owner_id,
                               event=event,
                               user=user)

    else:
        event_form = EventForm(instance=event)

    # Render the template depending on the context.
    return render_to_response('scheduler/update_event.html', {
        'event_form': event_form,
        'user': user,
        'event_added': event_added
    }, context)
Beispiel #10
0
def edit_event_view(request, eventid):
    event = get_object_or_404(Event, id=eventid)
    if event.schedule.creator != request.user:
        return render(request, "scheduler/errorpage.html",
                      {'message': "PERMISSION DENIED"})
    if request.method == 'POST':
        form = EventForm(instance=event, data=request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/schedule/lasttime/" +
                                        str(event.schedule.id))
        else:
            return render(request, "scheduler/createevent.html", {
                'form': form,
                'edit': 'edit',
                'event': event
            })
    else:
        form = EventForm(instance=event)
        return render(request, "scheduler/createevent.html", {
            'form': form,
            'edit': 'edit',
            'event': event
        })