<s> from django . shortcuts import render <EOL> from django . http import HttpResponse <EOL> from oncall . models import OncallAssignment <EOL> from oncall . forms import OncallForm <EOL> from oncall . constants import ONCALL_TYPES <EOL> import simplejson as json <EOL> def getoncall ( request , oncall_type ) : <EOL> """<STR_LIT>""" <EOL> if oncall_type not in ONCALL_TYPES : <EOL> return HttpResponse ( '<STR_LIT>' ) <EOL> profile = OncallAssignment . objects . get ( <EOL> oncall_type = oncall_type <EOL> ) . user . get_profile ( ) <EOL> format = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if format == '<STR_LIT>' : <EOL> response = profile . irc_nick <EOL> elif format in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> attrs = ( <EOL> ( "<STR_LIT>" , profile . irc_nick or '<STR_LIT>' ) , <EOL> ( "<STR_LIT>" , profile . user . username or '<STR_LIT>' ) , <EOL> ( "<STR_LIT>" , profile . pager_type or '<STR_LIT>' ) , <EOL> ( "<STR_LIT>" , profile . pager_number or '<STR_LIT>' ) , <EOL> ( "<STR_LIT>" , profile . epager_address or '<STR_LIT>' ) <EOL> ) <EOL> if format == '<STR_LIT>' : <EOL> response = json . dumps ( dict ( attrs ) ) <EOL> elif format == '<STR_LIT>' : <EOL> response = '<STR_LIT::>' . join ( [ el [ <NUM_LIT:1> ] for el in attrs ] ) <EOL> elif format == '<STR_LIT>' : <EOL> response = '<STR_LIT::>' . join ( [ el [ <NUM_LIT:0> ] for el in attrs ] ) <EOL> return HttpResponse ( response ) <EOL> def oncall ( request ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = OncallForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> else : <EOL> return render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : form } <EOL> ) <EOL> initial = { } <EOL> for onct in ONCALL_TYPES : <EOL> try : <EOL> cur = OncallAssignment . objects . get ( oncall_type = onct ) <EOL> cur_onc_name = cur . user . username <EOL> except OncallAssignment . DoesNotExist : <EOL> cur_onc_name = '<STR_LIT>' <EOL> initial [ onct ] = cur_onc_name <EOL> form = OncallForm ( initial = initial ) <EOL> return render ( <EOL> request , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT>' : form } <EOL> ) </s>
