示例#1
0
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))
示例#2
0
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))
示例#3
0
def edit(request, id, template='edit.html', redirect='..'):
    p = Planning.objects.get(id=int(id))
    if p.user != get_user(request):
        raise Exception('Not authorized.')
    pset = PlanningSettings.objects.get(planning=p, name='default')
    types = TypeEvent.objects.all()
    if request.method == 'POST':
        form1 = PlanningForm(request.POST, instance=p)
        form = PlanningSettingsForm(request.POST, instance=pset)
        if form.is_valid() and form1.is_valid():
            # Do form processing here...
            return HttpResponseRedirect(redirect)
    else:
        form1 = PlanningForm(instance=p)
        form = PlanningSettingsForm(instance=pset)
    return render_to_response(
        template, {
            'form':
            form,
            'form1':
            form1,
            'planning_url':
            'http://%s/planning/%s/' % (request.META['HTTP_HOST'], p.code),
            'types':
            types
        })
示例#4
0
def edit(request, id, template='edit.html', redirect='..'):
    p = Planning.objects.get(id=int(id))
    if p.user != get_user(request):
        raise Exception('Not authorized.')
    pset = PlanningSettings.objects.get(planning=p, name='default')
    types = TypeEvent.objects.all()
    if request.method == 'POST':
        form1 = PlanningForm(request.POST, instance=p)
        form = PlanningSettingsForm(request.POST, instance=pset)
        if form.is_valid() and form1.is_valid():
            # Do form processing here...
            return HttpResponseRedirect(redirect)
    else:
        form1 = PlanningForm(instance=p)
        form = PlanningSettingsForm(instance=pset)
    return render_to_response(template, {'form': form,
                                         'form1': form1,
                                         'planning_url':'http://%s/planning/%s/' % (request.META['HTTP_HOST'], p.code),
                                         'types':types})