Ejemplo n.º 1
0
def edit_doc(request, doc_id):
    "Edit document"
    doc = Document.objects.get(pk=doc_id)
    DocForm = form_for_instance(doc)
    if request.method == "POST":
        doc_form = DocForm(request.POST)
        if doc_form.is_valid():
            # сохраняем новый документ
            doc = doc_form.save(True)
            save_instance(doc_form, doc, True)
            
            # теперь распарсим строки документа
            i = 1
            while True:
                if request.has_key("card_name%i" % i):
                    card_name = request.POST["card_name%i" % i]
                    if card_name=="":
                        break
                    card_number = request.POST["card_number%i" % i]
                    card_credit = request.POST["card_credit%i" % i]
                    card_note = request.POST["card_note%i" % i]
                    have_pin = False
                    if request.has_key("have_pin%i" % i):
                        have_pin = True
                    
                    if request.has_key("card_id%i" % i):
                        card_id = request.POST["card_id%i" % i]
                        item = CardItem.objects.get(pk=card_id)
                        item.name = card_name
                        item.number = card_number
                        item.credit_number = card_credit
                        item.have_pin = have_pin
                        item.note=card_note
                        item.save()
                    else:
                        # сохраняем новую карточку
                        new_item = CardItem(name=card_name, number=card_number, credit_number=card_credit, have_pin=have_pin, note=card_note, doc=doc)
                        new_item.save()
                    
                    # индекс следующей строки
                    i=i+1
            
        return HttpResponseRedirect("/edit_docs/%s/" % doc.id)
    else:
        doc_form = DocForm()
        items = CardItem.objects.filter(doc=doc).order_by("id")
    
    content = {
               "doc": doc,
               "doc_form": doc_form,
               "items": items,
               }
    
    return default_renderer(request, "card_edit", content)
Ejemplo n.º 2
0
def new_doc(request):
    "Creates a new document"
    
    DocForm = form_for_model(Document)
    
    if request.method == "POST":
        doc_form = DocForm(request.POST)
        if doc_form.is_valid():
            # сохраняем новый документ
            doc = doc_form.save(True)
            
            # теперь распарсим строки документа
            i = 1
            while True:
                if request.has_key("card_name%i" % i):
                    card_name = request.POST["card_name%i" % i]
                    if card_name=="":
                        break
                    card_number = request.POST["card_number%i" % i]
                    card_credit = request.POST["card_credit%i" % i]
                    card_note = request.POST["card_note%i" % i]
                    have_pin = False
                    if request.has_key("have_pin%i" % i):
                        have_pin = True
                    
                    # сохраняем карточку
                    new_item = CardItem(name=card_name, number=card_number, credit_number=card_credit, have_pin=have_pin, note=card_note, doc=doc)
                    new_item.save()
                    
                    # индекс следующей строки
                    i=i+1
            
        return HttpResponseRedirect("/edit_docs/%s/" % doc.id)
    else:
        doc_form = DocForm()
        #items = Enterprise.objects.all()
    
    return default_renderer(request, "card_deed", {'doc_form':doc_form})