Turbogears2 session management

153 views Asked by At

In theory i did what i'm supposed to do in order to store some data in session variables but my controllers can't reach them. Here's the code:

    @expose('')
    @require(predicates.not_anonymous())
    def savecustomer(self, customer=None, **kw):
    if customer is None:
        flash(_('Select a customer!'), 'error')
        redirect('/')
    customer = DBSession.query(Customer).filter_by(customer_id=customer).first()
    session.delete()
    session['customer'] = True
    session['customer_id'] = customer.customer_id
    session['customer_name'] = customer.customer_name
    ...
    session.save()

and here is my view code:

  {% if request.identity %}
      {% if session['customer'] %}
        <div class="customer"><i>{{ session['customer_name'] }}
              {% if session['customer_type'] %} {{ session['customer_type'] }} {% endif %}
              </i></div>
      {% else %}
        <div class="nocustomer">No customer selected</div>
      {% endif %}
  {% endif %}

and here's my "debugging":

for i in session.iterkeys():
    print i
for i in session.itervalues():
    print i
customer
customer_id
customer_name
True
3
Ciccio Pasticcio S.p.a.

and if i run the same code in another controller it gives me this:

_id
832f62d3bc5140c4a9f3ba36bc3e876a

What am i doing wrong? (this used to work until i "fixed" something else :) )

1

There are 1 answers

0
eeeee On

I solved the error by removing

session.delete()