def index(): clients = Client.query.filter_by( user_id=current_user.get_id(), is_internal=False, ).all() tokens = Token.query.options(db.joinedload('client')).filter( Token.user_id == current_user.get_id(), Token.is_personal == True, # noqa Token.is_internal == False, Client.is_internal == True, ).all() authorized_apps = Token.query.options(db.joinedload('client')).filter( Token.user_id == current_user.get_id(), Token.is_personal == False, # noqa Token.is_internal == False, Client.is_internal == False, ).all() return render_template( "oauth2server/settings/index.html", clients=clients, tokens=tokens, authorized_apps=authorized_apps, )
def sort_methods(self): """Get sort methods for collection. If not sort methods are defined for a collection the root collections sort methods are retuned. If not methods are defined for the root collection, all possible sort methods are returned. Note: Noth sorting methods and ranking methods are now defined via the sorter. """ from invenio.modules.sorter.models import BsrMETHOD, \ Collection_bsrMETHOD for coll_id in (self.id, 1): methods = Collection_bsrMETHOD.query.filter_by( id_collection=coll_id ).order_by( Collection_bsrMETHOD.score ).options( db.joinedload(Collection_bsrMETHOD.bsrMETHOD) ).all() if len(methods) > 0: return map(lambda obj: obj.bsrMETHOD, methods) return BsrMETHOD.query.order_by(BsrMETHOD.name).all()
def sort_methods(self): """Get sort methods for collection. If not sort methods are defined for a collection the root collections sort methods are retuned. If not methods are defined for the root collection, all possible sort methods are returned. Note: Noth sorting methods and ranking methods are now defined via the sorter. """ from invenio.modules.sorter.models import BsrMETHOD, \ Collection_bsrMETHOD get_method = lambda obj: obj.bsrMETHOD for coll_id in (self.id, 1): methods = Collection_bsrMETHOD.query.filter_by( id_collection=coll_id).order_by( Collection_bsrMETHOD.score).options( db.joinedload(Collection_bsrMETHOD.bsrMETHOD)).all() if len(methods) > 0: return map(get_method, methods) return BsrMETHOD.query.order_by(BsrMETHOD.name).all()
def get_by_token(cls, client_id, access_token, token_type=''): """Get RemoteAccount object for token.""" return cls.query.options(db.joinedload('remote_account')).filter( RemoteAccount.id == RemoteToken.id_remote_account, RemoteAccount.client_id == client_id, RemoteToken.token_type == token_type, RemoteToken.access_token == access_token, ).first()
def get_message(uid, msgid): """ Get a message with its status and sender nickname. @param uid: user id @param msgid: message id @return: exactly one message or raise an exception. """ return UserMsgMESSAGE.query.options(\ db.joinedload_all(UserMsgMESSAGE.message, MsgMESSAGE.user_from)).\ options(db.joinedload(UserMsgMESSAGE.user_to)).\ filter(filter_user_message(uid, msgid)).one()
def get(cls, user_id, client_id, token_type='', access_token=None): """Get RemoteToken for user.""" args = [ RemoteAccount.id == RemoteToken.id_remote_account, RemoteAccount.user_id == user_id, RemoteAccount.client_id == client_id, RemoteToken.token_type == token_type, ] if access_token: args.append(RemoteToken.access_token == access_token) return cls.query.options( db.joinedload('remote_account')).filter(*args).first()
def get(cls, user_id, client_id, token_type='', access_token=None): """Get RemoteToken for user.""" args = [ RemoteAccount.id == RemoteToken.id_remote_account, RemoteAccount.user_id == user_id, RemoteAccount.client_id == client_id, RemoteToken.token_type == token_type, ] if access_token: args.append(RemoteToken.access_token == access_token) return cls.query.options( db.joinedload('remote_account') ).filter(*args).first()
def get_all_messages_for_user(uid): """ Get all messages for a user's inbox, without the eventual non-expired reminders. @param uid: user id @return: [(message_id, id_user_from, nickname_user_from, message_subject, message_sent_date, message_status)] """ update_user_inbox_for_reminders(uid) return MsgMESSAGE.query.options(db.joinedload(MsgMESSAGE.user_from)).\ join(UserMsgMESSAGE).\ filter(filter_all_messages_from_user(uid)).\ order_by(MsgMESSAGE.sent_date).all()