Example #1
0
def add_schedule(request, c):
    err = False
    if request.method == 'POST':
        data = {}
        try:
            data = {"s_start": request.POST["s_start"],
                    "s_end": request.POST["s_end"],
                    "force": request.POST["force"],
                    "rdate": datetime.datetime.min}
        except:
            pass
        form = PartialScheduleForm(data)
        if form.is_valid():
            try:
                sched = form.save(commit=False)
                sched.route = Route.objects.get(pk=c)
                sched.save()
            except:
                pass
        else:
            err =True
    else:
        form = PartialScheduleForm()
    
    return render_to_response("sched.html", {"pk": c, "err": err, "form": form}, RequestContext(request))
Example #2
0
def add_route(request):
    err = False
    if request.method == 'POST':
        data = {}
        try:
            data = {"label": request.POST["label"],
                    "origin": request.POST["origin"],
                    "dest": request.POST["dest"],
                    "start": request.POST["start"],
                    "end": request.POST["end"],
                    "state": 0,
                    "s_start": request.POST["s_start"],
                    "s_end": request.POST["s_end"],
                    "force": request.POST["force"],
                    "rdate": datetime.datetime.min}
        except:
            pass
        
        form = NewRouteForm(data)
        form2 = PartialScheduleForm(data)
        if form.is_valid() and form2.is_valid():
            try:
                route = form.save()
                sched = form2.save(commit=False)
                sched.route = route
                sched.save()
            except:
                pass
        else:
            err =True
    else:
        form = NewRouteForm()
        form2 = PartialScheduleForm()
    
    return render_to_response("route.html", {"err": err, "form": form, "form2": form2}, RequestContext(request))