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})
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 HttpResponseRedirect("/schedule/lasttime/" + 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 })
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 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)
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 })
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})
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)