<s> from flask import request , session <EOL> from flask import Blueprint <EOL> import api <EOL> import json <EOL> import mimetypes <EOL> import os . path <EOL> import api . auth <EOL> import api . team <EOL> from api . annotations import * <EOL> from api . common import flat_multi <EOL> from api . exceptions import * <EOL> blueprint = Blueprint ( "<STR_LIT>" , __name__ ) <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:GET>" ] ) <EOL> @ api_wrapper <EOL> def team_public_info_hook ( ) : <EOL> teamname = request . args . get ( "<STR_LIT>" ) <EOL> if api . team . get_team ( teamname = teamname ) is None : <EOL> raise WebException ( "<STR_LIT>" ) <EOL> data = api . team . public_info ( teamname = teamname ) <EOL> data [ "<STR_LIT>" ] = api . problem . get_max_points ( ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:data>" : data } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> def team_create_hook ( ) : <EOL> tid = api . team . create ( api . common . flat_multi ( request . form ) ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:message>" : "<STR_LIT>" } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:GET>" ] ) <EOL> @ api_wrapper <EOL> def team_members_hook ( ) : <EOL> members = api . team . members ( ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:data>" : members } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> def team_join_hook ( ) : <EOL> if request . form . get ( "<STR_LIT>" ) is None or len ( request . form . get ( "<STR_LIT>" ) ) < <NUM_LIT:1> : <EOL> raise WebException ( "<STR_LIT>" ) <EOL> join_code = request . form . get ( "<STR_LIT>" ) <EOL> message = api . team . join ( join_code ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:message>" : message } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:GET>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> @ require_team <EOL> def team_join_code_hook ( ) : <EOL> code = api . team . join_code ( ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:data>" : code } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> @ require_team <EOL> def team_join_code_new_hook ( ) : <EOL> code = api . team . join_code ( force = True ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:data>" : code } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> @ require_team <EOL> def team_remove_hook ( ) : <EOL> if api . auth . is_logged_in ( ) and api . user . in_team ( ) : <EOL> uid = request . form . get ( "<STR_LIT>" ) <EOL> user = api . user . get_user ( ) <EOL> if uid == user [ "<STR_LIT>" ] : <EOL> confirm = request . form . get ( "<STR_LIT>" ) <EOL> team = api . team . get_team ( ) <EOL> if confirm != team [ "<STR_LIT>" ] : <EOL> raise WebException ( "<STR_LIT>" ) <EOL> message = api . team . remove ( uid ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:message>" : message } <EOL> else : <EOL> raise WebException ( "<STR_LIT>" ) <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:GET>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> def team_info_hook ( ) : <EOL> team = api . team . get_team ( ) <EOL> team_info = { <EOL> "<STR_LIT>" : team [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : team [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : api . team . members ( ) , <EOL> } <EOL> if "<STR_LIT>" in team : team_info [ "<STR_LIT>" ] = team [ "<STR_LIT>" ] <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:data>" : team_info } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:POST>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> def team_update_hook ( ) : <EOL> updated = api . team . update ( api . common . flat_multi ( request . form ) ) <EOL> if updated : return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:message>" : "<STR_LIT>" } <EOL> else : return { "<STR_LIT:success>" : <NUM_LIT:0> , "<STR_LIT:message>" : "<STR_LIT>" } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:GET>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> def team_schools_hook ( ) : <EOL> schools = api . team . get_schools ( ) <EOL> return { "<STR_LIT:success>" : <NUM_LIT:1> , "<STR_LIT:data>" : schools } <EOL> @ blueprint . route ( "<STR_LIT>" , methods = [ "<STR_LIT:GET>" ] ) <EOL> @ api_wrapper <EOL> @ require_login <EOL> def team_shell_hook ( ) : <EOL> team = api . team . get_team ( ) <EOL> if "<STR_LIT>" in team and "<STR_LIT>" in team : <EOL> return { <EOL> "<STR_LIT:success>" : <NUM_LIT:1> , <EOL> "<STR_LIT:user>" : team [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : team [ "<STR_LIT>" ] <EOL> } <EOL> else : <EOL> shell_account = api . team . assign_shell_account ( team [ "<STR_LIT>" ] ) <EOL> print ( shell_account ) <EOL> return { <EOL> "<STR_LIT:success>" : <NUM_LIT:1> , <EOL> "<STR_LIT:user>" : shell_account [ "<STR_LIT:username>" ] , <EOL> "<STR_LIT>" : shell_account [ "<STR_LIT:password>" ] <EOL> } </s>
