I am trying to make a complex redirection:

Each transaction can have multiple transactions lines. For each
transaction, the user can create a new transaction line or edit an
existing one.

When the user has posted a new transaction line or edited an existing
one, the page should redirect to the page showing a transaction which
is linked to this specific transaction line. Is it possible?
Please note that in the code (controler) new_transaction_line and
edit_transaction_line, I redirect to next=URL
(r=request,f='edit_transaction/1/')), however instead of 1, it should
be the id number of the transaction or the equivalent which would be
transaction_line.transac.
How can we do that?


Please see model

db.define_table('transac',
                SQLField('description', length=100),
                SQLField('date','date',default=now)
                )

db.define_table('transaction_line',
   #             SQLField('date',db.transac.date),
                SQLField('transac', db.transac),
                SQLField('dc', length=1), #(d) debit or (c) credit
                SQLField('account',db.account_from_chart),
                SQLField('amount_transaction_currency', 'integer'),
                SQLField('currency_transaction', db.currency),
                SQLField('amount_functional_currency','integer')
                )



Please see controler

# coding: utf8
# try something like
def index(): return dict(message="hello from accounting.py")


def list_transactions():
    currencies=cache.ram('currencies',lambda: dict([(row.id,row.code)
for row in db(db.currency.id>0).select()]), 5000)
    cash_acc_code=lambda id: currencies[id]
    transacs=db().select(db.transac.ALL,orderby=db.transac.date)
    return dict(transacs=transacs,cash_acc_code=cash_acc_code)

def new_transaction():
#    form=SQLFORM(db.transac,fields=['title','description',\
#                               'category','instructions'])
    transacs=db().select(db.transac.ALL,orderby=db.transac.date)
    form = crud.create(db.transac,
                       next=URL(r=request,f='list_transactions'))
    if form.accepts(request.vars,session):
        redirect(URL(r=request,f='list_transactions'))
    return dict(form=form,transacs=transacs)

def edit_transaction():
    transac = db.transac[request.args[0]]
    form = crud.update(db.transac,transac,
                       next=URL(r=request,f='list_transactions'))
    if form.accepts(request.vars,session):
        redirect(URL(r=request,f='list_transactions'))
    return dict(form = form,id=request.args[0],transac=transac)

def new_transaction_line():
#    form=SQLFORM(db.transac,fields=['title','description',\
#                               'category','instructions'])
    form = crud.create(db.transaction_line,
                       next=URL(r=request,f='edit_transaction/1/'))
## where I need to make a correction
    if form.accepts(request.vars,session):
        redirect(URL(r=request,f='edit_transaction/1/')) ## where i
need to make a correction
    return dict(form=form)

def edit_transaction_line():
    transaction_line = db.transaction_line[request.args[0]]
    form = crud.update(db.transaction_line,transaction_line,
                       next=URL(r=request,f='edit_transaction/1/'))
    return dict(form = form,id=request.args
[0],transaction_line=transaction_line)



HTML: accounting/edit_transaction

{{extend 'layout.html'}}
<h1>This is the accounting/edit_transaction.html template</h1>
{{=form}}

<a href="/{{=request.application}}/accounting/
new_transaction_line"><button type="button">Create new transaction
line</button></a>
        </b>
<BR/>
<BR/>

    <b><TR> transaction n. {{=transac.id}}
   {{transaction_lines = db
(db.transaction_line.transac==transac.id).select
(orderby=db.transaction_line.dc)}}
 <BR/>
     {{for transaction_line in transaction_lines:}}
             {{if transaction_line.dc=="d" or
transaction_line.dc=="D":}}   {{else:}} {{pass}}
                 {{=transaction_line.dc}}
{{=transaction_line.account}}
{{=transaction_line.amount_transaction_currency}}
{{=transaction_line.currency_transaction}}
                <a href="/{{=request.application}}/accounting/
edit_transaction_line/{{=transaction_line.id}}"> <button
type="button">Edit</button>  </a> <BR/>
                {{pass}}


          <br/>
          <br/>


HTML: accounting/edit_transaction_line and accounting/
new_transaction_line

{{extend 'layout.html'}}
<h1>This is the accounting/new_transaction_line.html template</h1>
{{=form}}



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to