0

Possible Duplicate:
Bottle framework and OOP, using a method instead of a function

I want to wrap my bottle.py routes into class, like this:

from bottle import *
import users

class Routes:
    user = None

    @root.route('/')
    @view('index')
    def index_page( self ): #index page display
        self.user = users.User()
        return {}

But I cannot do this because bottle is trying to get self as if it was a route variable.

The goal of this is to set a class-wide object user so I could make AJAX API calls and verify my user, like this:

@root.route('/api/login/')
def user_login( self ): #user login api
    if self.user.authenticate( request.POST.get( 'username' ) , request.POST.get( 'password' )  ):
        return True
    return {'error': 'error'}

PS: I'm using signed cookies to authenticate user. This cookies contains non-critical information ( user's DB record id ) to manipulate this user's data.

Is there maybe a more convenient way to do this?

Community
  • 1
  • 1
bbrodriges
  • 703
  • 1
  • 10
  • 24

0 Answers0