def post(self): """ Handles adding tokens and creating private boards. TODO: Refactor this into a couple of handlers, and include the public board handling as well to make the code more succinct and extensible. This method is too long and unwieldy. """ token = self.request.get('token') user = users.get_current_user() if not user: self.redirect('/') user_obj = utils.get_user(user) if token: # Adding a token for a user if utils.verify_token(token): user_obj.auth_token = token user_obj.put() self.redirect('/privatefeeds') else: args = constants.TOKEN_ARGS auth_url = "https://trello.com/1/authorize?%s" % urlencode(args) self.render('private.html', actions=constants.ACTIONS, incorrect_token=True, auth_url=auth_url, signout=constants.SIGNOUT) else: # Adding a board for a user board_id = self.request.get('board') title = self.request.get('title') link = self.request.get('link') description = self.request.get('description') actions = [x for x in constants.ACTIONS if self.request.get(x)] if actions: get_all = False if board_id == 'all': get_all = True board_id = None feed_url = utils.create_feed( user,board_id, title,link, description,actions, public_board=False, get_all=get_all, token=user_obj.auth_token) self.render('congrats.html',feed_url=feed_url,signout=constants.SIGNOUT) else: # They missed some required info user_boards = utils.find_boards(user_obj) self.render('private.html', actions=constants.ACTIONS, check_error=True, user_boards=user_boards, link=link, description=description, title=title, signout=constants.SIGNOUT)
def get(self): user = users.get_current_user() if user: user_obj = utils.get_user(user) user_boards = None if user_obj.auth_token is None: # We need an auth token for this user args = constants.TOKEN_ARGS auth_url = "https://trello.com/1/authorize?%s" % urlencode(args) self.render('private.html', actions=constants.ACTIONS, auth_url=auth_url, signout=constants.SIGNOUT) else: user_boards = utils.find_boards(user_obj) self.render('private.html', actions=constants.ACTIONS, user_boards=user_boards, link="http://trello.com", title="My Trello RSS", description="My Trello RSS Feed", signout=constants.SIGNOUT) else: self.redirect('/')