Ejemplo n.º 1
0
def new_schedule(request):
    try:
        if request.method == 'POST':
            form = NewScheduleForm(data=request.POST)
            if form.is_valid():
                new_schedule = form.save(commit=False)
                new_schedule.user = request.user
                new_schedule.save()
                messages.success(request, 'new schedule added')
                return HttpResponseRedirect(reverse('dashboard'))
        else:
            form = NewScheduleForm(request.user)

            return render_to_response('contacts/new_schedule.html', {'dashboard_active':'active', 'form':form},
                                    context_instance=RequestContext(request))
    except Exception, e:
        return general_error(request, title='Error Creating Schedule', message=e.message, redirect='contacts.views.dashboard')
Ejemplo n.º 2
0
def edit_schedule(request, schedule_id):
    try:
        if request.method == 'POST':
            form = NewScheduleForm(data=request.POST)
            if form.is_valid():
                cs = form.save(commit=False)
                cs.id = schedule_id
                cs.user_id = request.user.id
                cs.save()

                messages.success(request, "schedule edited")
                return HttpResponseRedirect(reverse('dashboard'))
        else:
            cs = ContactSchedules.objects.get(id=schedule_id, user=request.user)
            form = NewScheduleForm(instance=cs)

            return render_to_response('contacts/edit_schedule.html', {'dashboard_active':'active', 'form':form, 'schedule':cs},
                                        context_instance=RequestContext(request))
    except Exception, e:
        return general_error(request, title='Error Editing Schedule', message=e.message, redirect='contacts.views.dashboard')