Exemplo n.º 1
0
def user_detail(request, user_id):
    """
    Show/edit/save GTS_User instance
    (!) В данный момент не используется.
    Пользователи редактируюся в админ-части Джанго-сайта.
    """
    error_message = ""
    user = GTS_User.objects.get(pk=user_id)
    
    if request.method == "POST":
        UserForm = form_for_model(GTS_User)
        user_form = UserForm(request.POST)
        if user_form.is_valid():
            save_instance(user_form, user, True)

            return HttpResponseRedirect('/users/')
        else:
            error_message = "Form contain errors!"  # % account_form.errors 
    else:
        UserForm = form_for_instance(user)
        user_form = UserForm() 
    
    content = {"user" : user,
               "user_form" : user_form,
               "error_message" : error_message,
               }

    return render_to_response("user_detail.html", content)
Exemplo n.º 2
0
def device_detail(request, device_id):
    "Show/edit/save Device instance"
    
    account = request.user.gts_user.account
    
    error_message = ""
    device = Device.objects.get(pk=device_id)
    
    if request.method == "POST":
        DeviceForm = form_for_model(Device)
        device_form = DeviceForm(request.POST)
        if device_form.is_valid():
            save_instance(device_form, device, True)
#            new_device = save_instance(device_form, device, False)
#            new_device.account = account
#            new_device.save()

            return HttpResponseRedirect('/devices/')
        else:
            error_message = "Form contain errors!"  # % account_form.errors 
    else:
        DeviceForm = form_for_instance(device)
        device_form = DeviceForm()
        
    content = {"device" : device,
               "device_form" : device_form,
               "error_message" : error_message,
               }

    return render_to_response("device_detail.html", content)
Exemplo n.º 3
0
def account_detail(request, account_id=0):
    """
    Отображает информацию о текущем Аккаунте.
    Ее можно изменить и сохранить.
    Аккаунт берется из request, при залогиневшеся юзере там появляется переменная user.
    """
    
    error_message = ""

    #if account_id == 0:
    account = request.user.gts_user.account
    #else:
    #    account = Account.objects.get(pk=account_id)
    
    if request.method == "POST":
        AccountForm = form_for_model(Account)
        account_form = AccountForm(request.POST)
        if account_form.is_valid():
            account_form.clean_data['id'] = account.id 
            save_instance(account_form, account, True)

            return HttpResponseRedirect('/gts_accounts/')
        else:
            error_message = "Form contain errors!"  # % account_form.errors 
    else:
        AccountForm = form_for_instance(account)
        
        account_form = AccountForm()
        
    content = {"account" : account,
               "account_form" : account_form,
               "error_message" : error_message,
               }

    return render_to_response("account_detail.html", content)
Exemplo n.º 4
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)
Exemplo n.º 5
0
def edit_atm_doc(request, doc_id):
    "Edit ATM Document"
    doc = AtmDocument.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]
                    arrival_date = request.POST["arrival_date%i" % i]
                    delivery_date = request.POST["delivery_date%i" % i]
                    card_note = request.POST["card_note%i" % i]
                    
                    if request.has_key("card_id%i" % i):
                        card_id = request.POST["card_id%i" % i]
                        item = AtmCardItem.objects.get(pk=card_id)
                        item.name = card_name
                        item.number = card_number
                        item.arrival_date = arrival_date
                        item.delivery_date = delivery_date
                        item.note=card_note
                        item.save()
                    else:
                        # сохраняем новую карточку
                        new_item = AtmCardItem(name=card_name, number=card_number, delivery_date=delivery_date, arrival_date=arrival_date, note=card_note, doc=doc)
                        new_item.save()
                    
                    # индекс следующей строки
                    i=i+1
            
        return HttpResponseRedirect("/edit_docs_atm/%s/" % doc.id)
    else:
        doc_form = DocForm()
        items = AtmCardItem.objects.filter(doc=doc).order_by("id")
    
    content = {
               "doc": doc,
               "doc_form": doc_form,
               "items": items,
               }
    
    return default_renderer(request, "atm_edit", content)