def planning(request): error = False if request.method == "POST": form = PlanningForm(request.POST) if form.is_valid(): plan = form.save(commit=False) plan.user = request.user plan.save() logger.info("Planning for user %s" % request.user.username) messages.info(request, "New plan was added.") if not request.is_ajax(): return HttpResponseRedirect(reverse("dashboard")) else: error = True else: form = PlanningForm() data = { "form": form, } if request.method == "POST" and request.is_ajax(): return HttpResponse(json.dumps({ 'response': 'error' if error else 'ok', 'html': render_to_string("planning/plan-add.html", data) }), mimetype='application/json') else: return render_to_response("planning/plan-add.html", data, RequestContext(request))
def add_planning(request, redirect='..'): if request.method == 'POST': form1 = PlanningForm(request.POST) form = PlanningSettingsForm(request.POST) if form.is_valid(): p = form1.save(commit=False) p.user = get_user(request) p.save() pset = form.save(commit=False) pset.planning = p pset.save() request.session['planning_code'] = p.code redirect = redirect % p.id return HttpResponseRedirect(redirect) else: form1 = PlanningForm() form = PlanningSettingsForm() return render_to_response('add_planning.html', {'form': form, 'form1': form1, 'user_id':request.session['user_id']})
def add_planning(request, redirect='..'): if request.method == 'POST': form1 = PlanningForm(request.POST) form = PlanningSettingsForm(request.POST) if form.is_valid(): p = form1.save(commit=False) p.user = get_user(request) p.save() pset = form.save(commit=False) pset.planning = p pset.save() request.session['planning_code'] = p.code redirect = redirect % p.id return HttpResponseRedirect(redirect) else: form1 = PlanningForm() form = PlanningSettingsForm() return render_to_response('add_planning.html', { 'form': form, 'form1': form1, 'user_id': request.session['user_id'] })