<s> from piston . handler import BaseHandler , rc <EOL> from systems . models import UserProfile <EOL> import re <EOL> try : <EOL> import json <EOL> except : <EOL> from django . utils import simplejson as json <EOL> from middleware . restrict_by_api_token import AuthenticatedAPI <EOL> from settings import API_ACCESS <EOL> from django . contrib . auth . models import User <EOL> class OncallHandler ( BaseHandler ) : <EOL> allowed_methods = API_ACCESS <EOL> def read ( self , request , oncall_type , display_type = None ) : <EOL> oncall = '<STR_LIT>' <EOL> if oncall_type == '<STR_LIT>' : <EOL> if display_type == '<STR_LIT:email>' : <EOL> result = User . objects . select_related ( ) . filter ( userprofile__current_desktop_oncall = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> oncall = { '<STR_LIT:user>' : result . username , '<STR_LIT>' : result . get_profile ( ) . pager_type , '<STR_LIT>' : result . get_profile ( ) . epager_address , '<STR_LIT>' : result . get_profile ( ) . pager_number } <EOL> elif display_type == '<STR_LIT>' : <EOL> result = User . objects . select_related ( ) . filter ( userprofile__current_desktop_oncall = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> oncall = { '<STR_LIT:user>' : result . get_profile ( ) . irc_nick , '<STR_LIT>' : result . get_profile ( ) . pager_type , '<STR_LIT>' : result . get_profile ( ) . epager_address , '<STR_LIT>' : result . get_profile ( ) . pager_number } <EOL> elif display_type == '<STR_LIT:all>' : <EOL> oncall = [ ] <EOL> list = User . objects . select_related ( ) . filter ( userprofile__is_desktop_oncall = <NUM_LIT:1> ) <EOL> for u in list : <EOL> oncall . append ( { '<STR_LIT:user>' : u . get_profile ( ) . irc_nick , '<STR_LIT>' : u . get_profile ( ) . pager_type , '<STR_LIT>' : u . get_profile ( ) . pager_number } ) <EOL> elif oncall_type == '<STR_LIT>' : <EOL> if display_type == '<STR_LIT:email>' : <EOL> result = User . objects . select_related ( ) . filter ( userprofile__current_sysadmin_oncall = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> oncall = { '<STR_LIT:user>' : result . username , '<STR_LIT>' : result . get_profile ( ) . pager_type , '<STR_LIT>' : result . get_profile ( ) . epager_address , '<STR_LIT>' : result . get_profile ( ) . pager_number } <EOL> elif display_type == '<STR_LIT>' : <EOL> result = User . objects . select_related ( ) . filter ( userprofile__current_sysadmin_oncall = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> oncall = { '<STR_LIT:user>' : result . get_profile ( ) . irc_nick , '<STR_LIT>' : result . get_profile ( ) . pager_type , '<STR_LIT>' : result . get_profile ( ) . epager_address , '<STR_LIT>' : result . get_profile ( ) . pager_number } <EOL> elif display_type == '<STR_LIT:all>' : <EOL> oncall = [ ] <EOL> list = User . objects . select_related ( ) . filter ( userprofile__is_sysadmin_oncall = <NUM_LIT:1> ) <EOL> for u in list : <EOL> oncall . append ( { '<STR_LIT:user>' : u . get_profile ( ) . irc_nick , '<STR_LIT>' : u . get_profile ( ) . pager_type , '<STR_LIT>' : u . get_profile ( ) . pager_number } ) <EOL> elif oncall_type == '<STR_LIT>' : <EOL> if display_type == '<STR_LIT:email>' : <EOL> result = User . objects . select_related ( ) . filter ( userprofile__current_services_oncall = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> oncall = { '<STR_LIT:user>' : result . username , '<STR_LIT>' : result . get_profile ( ) . pager_type , '<STR_LIT>' : result . get_profile ( ) . epager_address , '<STR_LIT>' : result . get_profile ( ) . pager_number } <EOL> elif display_type == '<STR_LIT>' : <EOL> result = User . objects . select_related ( ) . filter ( userprofile__current_services_oncall = <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> oncall = { '<STR_LIT:user>' : result . get_profile ( ) . irc_nick , '<STR_LIT>' : result . get_profile ( ) . pager_type , '<STR_LIT>' : result . get_profile ( ) . epager_address , '<STR_LIT>' : result . get_profile ( ) . pager_number } <EOL> elif display_type == '<STR_LIT:all>' : <EOL> oncall = [ ] <EOL> list = User . objects . select_related ( ) . filter ( userprofile__is_services_oncall = <NUM_LIT:1> ) <EOL> for u in list : <EOL> oncall . append ( { '<STR_LIT:user>' : u . get_profile ( ) . irc_nick , '<STR_LIT>' : u . get_profile ( ) . pager_type , '<STR_LIT>' : u . get_profile ( ) . pager_number } ) <EOL> else : <EOL> resp = rc . NOT_FOUND <EOL> return resp <EOL> return oncall <EOL> def update ( self , request , oncall_type = None , display_type = None ) : <EOL> user = display_type <EOL> from django . db import connection , transaction <EOL> if request . method == '<STR_LIT>' : <EOL> if oncall_type == '<STR_LIT>' : <EOL> cursor = connection . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> transaction . commit_unless_managed ( ) <EOL> if re . match ( "<STR_LIT>" , user ) : <EOL> new_oncall = User . objects . get ( username = user ) <EOL> else : <EOL> new_oncall = User . objects . get ( userprofile__irc_nick = user ) <EOL> new_oncall . get_profile ( ) . current_desktop_oncall = <NUM_LIT:1> <EOL> new_oncall . get_profile ( ) . save ( ) <EOL> new_oncall . save ( ) <EOL> resp = rc . ALL_OK <EOL> return resp <EOL> elif oncall_type == '<STR_LIT>' : <EOL> cursor = connection . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> transaction . commit_unless_managed ( ) <EOL> if re . match ( "<STR_LIT>" , user ) : <EOL> new_oncall = User . objects . get ( username = user ) <EOL> else : <EOL> new_oncall = User . objects . get ( userprofile__irc_nick = user ) <EOL> new_oncall . get_profile ( ) . current_sysadmin_oncall = <NUM_LIT:1> <EOL> new_oncall . get_profile ( ) . save ( ) <EOL> new_oncall . save ( ) <EOL> resp = rc . ALL_OK <EOL> return resp <EOL> elif oncall_type == '<STR_LIT>' : <EOL> cursor = connection . cursor ( ) <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> transaction . commit_unless_managed ( ) <EOL> if re . match ( "<STR_LIT>" , user ) : <EOL> new_oncall = User . objects . get ( username = user ) <EOL> else : <EOL> new_oncall = User . objects . get ( userprofile__irc_nick = user ) <EOL> new_oncall . get_profile ( ) . current_services_oncall = <NUM_LIT:1> <EOL> new_oncall . get_profile ( ) . save ( ) <EOL> new_oncall . save ( ) <EOL> resp = rc . ALL_OK <EOL> return resp <EOL> else : <EOL> resp = rc . NOT_FOUND <EOL> return resp <EOL> def delete ( self , request , oncall_type = None ) : <EOL> pass </s>
