<s> from flask import request <EOL> from modularodm import Q <EOL> from framework . auth . decorators import must_be_logged_in <EOL> from website . models import CitationStyle <EOL> from website . project . decorators import ( <EOL> must_have_addon , must_be_addon_authorizer , <EOL> must_have_permission , must_not_be_registration , <EOL> must_be_valid_project , must_be_contributor_or_public <EOL> ) <EOL> def list_citation_styles ( ) : <EOL> query = None <EOL> term = request . args . get ( '<STR_LIT:q>' ) <EOL> if term : <EOL> query = ( <EOL> Q ( '<STR_LIT>' , '<STR_LIT>' , term ) | <EOL> Q ( '<STR_LIT:title>' , '<STR_LIT>' , term ) | <EOL> Q ( '<STR_LIT>' , '<STR_LIT>' , term ) <EOL> ) <EOL> return { <EOL> '<STR_LIT>' : [ style . to_json ( ) for style in CitationStyle . find ( query ) ] , <EOL> } <EOL> @ must_be_contributor_or_public <EOL> def node_citation ( ** kwargs ) : <EOL> node = kwargs [ '<STR_LIT>' ] or kwargs [ '<STR_LIT>' ] <EOL> return { node . csl [ '<STR_LIT:id>' ] : node . csl } <EOL> class GenericCitationViews ( object ) : <EOL> """<STR_LIT>""" <EOL> addon_short_name = None <EOL> Provider = None <EOL> def __init__ ( self , addon_short_name , Provider ) : <EOL> self . addon_short_name = addon_short_name <EOL> self . Provider = Provider <EOL> def account_list ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_be_logged_in <EOL> def _account_list ( auth ) : <EOL> """<STR_LIT>""" <EOL> return Provider ( ) . user_accounts ( auth . user ) <EOL> _account_list . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _account_list <EOL> def get_config ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_be_logged_in <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT>' ) <EOL> @ must_be_valid_project <EOL> @ must_have_permission ( '<STR_LIT>' ) <EOL> def _get_config ( auth , node_addon , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> provider = Provider ( ) <EOL> result = provider . serializer ( <EOL> node_settings = node_addon , <EOL> user_settings = auth . user . get_addon ( addon_short_name ) <EOL> ) . serialized_node_settings <EOL> result [ '<STR_LIT>' ] = provider . check_credentials ( node_addon ) <EOL> return { '<STR_LIT:result>' : result } <EOL> _get_config . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _get_config <EOL> def set_config ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_not_be_registration <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT:user>' ) <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT>' ) <EOL> @ must_be_addon_authorizer ( addon_short_name ) <EOL> @ must_have_permission ( '<STR_LIT>' ) <EOL> def _set_config ( node_addon , user_addon , auth , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> provider = Provider ( ) <EOL> args = request . get_json ( ) <EOL> external_list_id = args . get ( '<STR_LIT>' ) <EOL> external_list_name = args . get ( '<STR_LIT>' ) <EOL> provider . set_config ( <EOL> node_addon , <EOL> auth . user , <EOL> external_list_id , <EOL> external_list_name , <EOL> auth , <EOL> ) <EOL> return { <EOL> '<STR_LIT:result>' : provider . serializer ( <EOL> node_settings = node_addon , <EOL> user_settings = auth . user . get_addon ( addon_short_name ) , <EOL> ) . serialized_node_settings <EOL> } <EOL> _set_config . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _set_config <EOL> def import_auth ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_not_be_registration <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT:user>' ) <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT>' ) <EOL> @ must_have_permission ( '<STR_LIT>' ) <EOL> def _import_auth ( auth , node_addon , user_addon , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> provider = Provider ( ) <EOL> external_account_id = request . get_json ( ) . get ( '<STR_LIT>' ) <EOL> return provider . add_user_auth ( node_addon , auth . user , external_account_id ) <EOL> _import_auth . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _import_auth <EOL> def deauthorize_node ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_not_be_registration <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT>' ) <EOL> @ must_have_permission ( '<STR_LIT>' ) <EOL> def _deauthorize_node ( auth , node_addon , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> provider = Provider ( ) <EOL> return provider . remove_user_auth ( node_addon , auth . user ) <EOL> _deauthorize_node . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _deauthorize_node <EOL> def widget ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_be_contributor_or_public <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT>' ) <EOL> def _widget ( node_addon , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Provider ( ) . widget ( node_addon ) <EOL> _widget . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _widget <EOL> def citation_list ( self ) : <EOL> addon_short_name = self . addon_short_name <EOL> Provider = self . Provider <EOL> @ must_be_contributor_or_public <EOL> @ must_have_addon ( addon_short_name , '<STR_LIT>' ) <EOL> def _citation_list ( auth , node_addon , list_id = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> show = request . args . get ( '<STR_LIT>' , '<STR_LIT:all>' ) <EOL> return Provider ( ) . citation_list ( node_addon , auth . user , list_id , show ) <EOL> _citation_list . __name__ = '<STR_LIT>' . format ( addon_short_name ) <EOL> return _citation_list </s>
