Exemplo n.º 1
0
def create(request):
    if request.method=='POST':
        form=RecordForm(request.POST)
        if form.is_valid():
            record=Record.objects.create(
            	name =form.cleaned_data['name'],
                flight_company = form.cleaned_data['flight_company'],
                flight_no=form.cleaned_data['flight_no'],
                depart=form.cleaned_data['depart'],
                arrive=form.cleaned_data['arrive'],
                depart_airport=form.cleaned_data['depart_airport'],
                arrive_airport=form.cleaned_data['arrive_airport'],
                qq=form.cleaned_data['qq'],
                email=form.cleaned_data['email'],
                phone=form.cleaned_data['phone'],
                package=form.cleaned_data['package'],
                need_room=form.cleaned_data['need_room'],
                expect_district=form.cleaned_data['expect_district'],
                )
            request.session['record']=record
            return HttpResponseRedirect(reverse('success'))
    else:
        form=RecordForm()

    return render_to_response('record_form.html', {
        'form': form,
        }, context_instance=RequestContext(request))
Exemplo n.º 2
0
def record_all_detail(request, pk):
    """拜访记录详情"""
    record = get_object_or_404(Record, pk=pk, is_valid=True)
    form = RecordForm(instance=record)
    return render(request, 'record_all_detail.html', {
        'form': form,
    })
Exemplo n.º 3
0
def index(request):

    form = RecordForm()

    return {
        'form': form,
        'greetings': Setting.objects.get_value('greetings', default=u'Привет')
    }
Exemplo n.º 4
0
def customer_detail_record(request, pk):
    """客户详情里查看拜访记录"""
    record = get_object_or_404(Record, pk=pk, is_valid=True)
    form = RecordForm(instance=record)
    return render(request, 'customer_detail_record.html', {
        'form': form,
        'record': record
    })
Exemplo n.º 5
0
def add_record(request):
    """ Add a record to the web."""
    # POST request
    if request.method == "POST":
        record_form = RecordForm(request.POST, request.FILES)
        if record_form.is_valid():
            # from ipdb import set_trace; set_trace()
            new_record = record_form.save(commit=False)
            new_record.adder = request.user
            new_record.save()
            request.user.message_set.create(message=_("You have saved book '%(title)s'"))
            return HttpResponseRedirect(reverse("record.views.records"))
    # GET request
    else:
        record_form = RecordForm()
        return render_to_response("record/add.html", {
            "record_form":record_form,
            }, context_instance=RequestContext(request))
    # generic case
    return render_to_response("record/add.html", {
        "record_form": record_form,
        }, context_instance=RequestContext(request))
Exemplo n.º 6
0
def record_edit(request, pk):
    """拜访记录修改"""
    user = request.session.get('user_id')
    record = get_object_or_404(Record, pk=pk, user=user, is_valid=True)
    if request.method == 'POST':
        form = RecordForm(data=request.POST, instance=record)
        if form.is_valid():
            form.save()
            return redirect('record')
        else:
            print(form.errors.as_json)
    else:
        form = RecordForm(instance=record)
    return render(request, 'record_edit.html', {'form': form, 'pk': pk})
Exemplo n.º 7
0
def record_add(request):
    """拜访记录添加"""
    user_id = request.session.get('user_id')
    customers = Customer.objects.filter(user=user_id)
    if request.method == 'POST':
        form = RecordForm(data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('record')
        else:
            print(form.errors.as_json)
    else:
        form = RecordForm()
    return render(request, 'record_add.html', {
        'form': form,
        'customers': customers
    })
Exemplo n.º 8
0
def customer_add_record(request, pk):
    """客户详情里添加拜访记录"""
    customer = get_object_or_404(Customer, pk=pk, is_valid=True)
    if request.method == 'POST':
        form = RecordForm(data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('customer_detail', pk)
        else:
            print(form.errors.as_json)
    else:
        form = RecordForm()
    return render(request, 'customer_add_record.html', {
        'form': form,
        'customer': customer,
        'pk': pk,
    })
Exemplo n.º 9
0
def customer_edit_record(request, pk):
    """客户详情里修改拜访记录"""
    user = request.session.get('user_id')
    record = get_object_or_404(Record, pk=pk, user=user, is_valid=True)
    if request.method == 'POST':
        form = RecordForm(data=request.POST, instance=record)
        if form.is_valid():
            form.save()
            return redirect('customer_detail', record.customer.pk)
        else:
            print(form.errors.as_json)
    else:
        form = RecordForm(instance=record)
    return render(request, 'customer_edit_record.html', {
        'form': form,
        'record': record,
        'pk': pk,
    })
Exemplo n.º 10
0
def update_record(request, record_id):
    """ Update a record given its id. """
    record = Record.objects.get(id=record_id)
    if request.method == "POST":
        record_form = RecordForm(request.POST, request.FIFLES, instance=record)
        record_form.is_update = True
        if request.user == record.adder:
            # from ipdb import set_trace; set_trace()
            if record_form.save():
                record_form.save()
                request.user.message_set.create(message=_("You have updated record '%(title)s'") % {'title':record.title})
                return HttpResponseRedirect(reverse("record.views.records"))
    else:
        record_form = RecordForm(instance=record)
        return render_to_response("record/update.html", {
            "record_form":record_form,
            "record":record,
            }, context_instance=RequestContext(request))