Exemple #1
0
def go_out(request):
    if  request.user is not None and request.user.is_active:
        user_now = request.user.username
        if request.method == 'POST':
            plan_form = PlanForm(request.POST)
            if plan_form.is_valid():
                new_plan = Travel_plan()
                
                new_plan.Username = Account.objects.get(Username=user_now)
                new_plan.Destination = request.POST['Destination_province'] + " " + request.POST['Destination_city']
                new_plan.Start_place = request.POST['Start_place_province'] + " " + request.POST['Start_place_city']
                new_plan.Start_date = plan_form.cleaned_data['Start_date']
                new_plan.End_date = plan_form.cleaned_data['End_date']
                new_plan.People_amount = plan_form.cleaned_data['People_amount']
                new_plan.Budget = plan_form.cleaned_data['Budget']
                new_plan.Demand = plan_form.cleaned_data['Demand']
                new_plan.save()
                return HttpResponse('travel plan post success')
            
        else:
            plan_form = PlanForm()
    
        return render_to_response('go_out.html',locals())
    else:
        return HttpResponse('please login first')
Exemple #2
0
def go_out(request):
    if  request.user is not None and request.user.is_active:
        user_now = request.user.username
        travel_plan = Travel_plan.objects.filter(Username=Account.objects.get(Username=user_now))
        for plan in travel_plan:
            my_plan = plan
            my_group = Group.objects.filter(Travel_plan=plan)

        if request.method == 'POST':
            if travel_plan:
                for new_plan in travel_plan:
                    new_plan.Username = Account.objects.get(Username=user_now)
                    new_plan.Destination = request.POST['Destination_province'] + " " + request.POST['Destination_city']
                    new_plan.Start_place = request.POST['Start_place_province'] + " " + request.POST['Start_place_city']
                    new_plan.Start_date = request.POST['Start_date']
                    new_plan.End_date = request.POST['End_date']
                    new_plan.People_amount = request.POST['People_amount']
                    new_plan.Budget = request.POST['Budget']
                    try:
                        new_plan.Demand = request.POST['Demand']
                    except:
                        pass
                    new_plan.save()
            else:
                plan_form = PlanForm(request.POST)
                if plan_form.is_valid():
                    new_plan = Travel_plan()
                    
                    new_plan.Username = Account.objects.get(Username=user_now)
                    new_plan.Destination = request.POST['Destination_province'] + " " + request.POST['Destination_city']
                    new_plan.Start_place = request.POST['Start_place_province'] + " " + request.POST['Start_place_city']
                    new_plan.Start_date = plan_form.cleaned_data['Start_date']
                    new_plan.End_date = plan_form.cleaned_data['End_date']
                    new_plan.People_amount = plan_form.cleaned_data['People_amount']
                    new_plan.Budget = plan_form.cleaned_data['Budget']
                    new_plan.Demand = plan_form.cleaned_data['Demand']
                    new_plan.save()
            

                return HttpResponseRedirect("../../go_out.html/",locals())

            
        else:
            plan_form = PlanForm()
    
        return render_to_response('go_out.html',locals())
    else:
        return HttpResponse('please login first')