<s> """<STR_LIT>""" <EOL> from bombolone . core . utils import ensure_objectid <EOL> from bombolone . core . validators import CheckValue <EOL> import bombolone . model . ranks <EOL> import bombolone . model . users <EOL> check = CheckValue ( ) <EOL> def show ( rank_id = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if rank_id is None : <EOL> list_ranks = model . ranks . find ( sorted_by = '<STR_LIT>' , expand_number = True ) <EOL> data = { <EOL> "<STR_LIT:success>" : True , <EOL> "<STR_LIT>" : list_ranks <EOL> } <EOL> else : <EOL> rank = model . ranks . find ( rank_id = rank_id , expand_number = True ) <EOL> data = { <EOL> "<STR_LIT:success>" : True , <EOL> "<STR_LIT>" : rank <EOL> } <EOL> return data <EOL> def create ( name = None , rank = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> error_code = None <EOL> if name is None or len ( name ) == <NUM_LIT:0> : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif rank is None : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif check . is_integer ( rank ) == False : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> rank = int ( rank ) <EOL> rank = model . ranks . create ( name = name , rank = rank ) <EOL> data = { <EOL> "<STR_LIT:success>" : True , <EOL> } <EOL> return data <EOL> data = { <EOL> "<STR_LIT:success>" : False , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:code>" : error_code <EOL> } ] <EOL> } <EOL> return data <EOL> def update ( rank_id = None , name = None , rank = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> error_code = None <EOL> if ensure_objectid ( rank_id ) is None : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif name is None or len ( name ) == <NUM_LIT:0> : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif rank is None : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif check . is_integer ( rank ) == False : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> rank = int ( rank ) <EOL> result = model . ranks . update ( rank_id = rank_id , name = name , rank = rank ) <EOL> if result : <EOL> data = { <EOL> "<STR_LIT:success>" : True , <EOL> } <EOL> return data <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = { <EOL> "<STR_LIT:success>" : False , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:code>" : error_code <EOL> } ] <EOL> } <EOL> return data <EOL> def remove ( rank_id = None , my_rank = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> error_code = None <EOL> if rank_id is None : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif my_rank is None : <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> result = model . ranks . remove ( rank_id = rank_id , my_rank = my_rank ) <EOL> if result : <EOL> data = { <EOL> "<STR_LIT:success>" : True , <EOL> } <EOL> return data <EOL> error_code = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> data = { <EOL> "<STR_LIT:success>" : False , <EOL> "<STR_LIT>" : [ { <EOL> "<STR_LIT:code>" : error_code <EOL> } ] <EOL> } <EOL> return data </s>
