Exemplo n.º 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))
Exemplo n.º 2
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
        })
Exemplo n.º 3
0
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']})
Exemplo n.º 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})
Exemplo n.º 5
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))
Exemplo n.º 6
0
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']
    })