#NEWLINE# @ login_required ( ) #NEWLINE# @ require_POST #NEWLINE# def bug_report( req ) : #NEWLINE# #INDENT# report = dict ( [ ( key , req . POST . get ( key , '' ) ) for key in ( 'subject' , 'username' , 'domain' , 'url' , 'message' , 'app_id' , 'cc' , 'email' , '500traceback' ) ] ) #NEWLINE# report [ 'user_agent' ] = req . META [ 'HTTP_USER_AGENT' ] #NEWLINE# report [ 'datetime' ] = datetime . utcnow ( ) #NEWLINE# report [ 'feature_flags' ] = toggles . toggles_dict ( username = report [ 'username' ] , domain = report [ 'domain' ] ) . keys ( ) #NEWLINE# report [ 'feature_previews' ] = feature_previews . previews_dict ( report [ 'domain' ] ) . keys ( ) #NEWLINE# try : #NEWLINE# #INDENT# couch_user = CouchUser . get_by_username ( report [ 'username' ] ) #NEWLINE# full_name = couch_user . full_name #NEWLINE# if couch_user . is_commcare_user ( ) : #NEWLINE# #INDENT# email = report [ 'email' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# email = couch_user . get_email ( ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception : #NEWLINE# #INDENT# full_name = None #NEWLINE# email = report [ 'email' ] #NEWLINE# #UNINDENT# report [ 'full_name' ] = full_name #NEWLINE# report [ 'email' ] = ( email or report [ 'username' ] ) #NEWLINE# matching_subscriptions = Subscription . objects . filter ( is_active = True , subscriber__domain = report [ 'domain' ] ) #NEWLINE# if ( len ( matching_subscriptions ) >= 1 ) : #NEWLINE# #INDENT# report [ 'software_plan' ] = matching_subscriptions [ 0 ] . plan_version #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# report [ 'software_plan' ] = 'domain has no active subscription' #NEWLINE# #UNINDENT# subject = '{subject} ({domain})' . format ( ** report ) #NEWLINE# message = 'username: {username}\nfull name: {full_name}\ndomain: {domain}\nsoftware plan: {software_plan}\nurl: {url}\ndatetime: {datetime}\nUser Agent: {user_agent}\nFeature Flags: {feature_flags}\nFeature Previews: {feature_previews}\nMessage:\n\n{message}\n' . format ( ** report ) #NEWLINE# cc = report [ 'cc' ] . strip ( ) . split ( ',' ) #NEWLINE# cc = filter ( None , cc ) #NEWLINE# if ( full_name and ( not any ( [ ( c in full_name ) for c in '<>"' ] ) ) ) : #NEWLINE# #INDENT# reply_to = '"{full_name}" <{email}>' . format ( ** report ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# reply_to = report [ 'email' ] #NEWLINE# #UNINDENT# if ( settings . HQ_ACCOUNT_ROOT in reply_to ) : #NEWLINE# #INDENT# reply_to = settings . SERVER_EMAIL #NEWLINE# #UNINDENT# if req . POST . get ( 'five-hundred-report' ) : #NEWLINE# #INDENT# extra_message = "This messge was reported from a 500 error page! Please fix this ASAP (as if you wouldn't anyway)..." #NEWLINE# traceback_info = cache . cache . get ( report [ '500traceback' ] ) #NEWLINE# cache . cache . delete ( report [ '500traceback' ] ) #NEWLINE# traceback_info = ( 'Traceback of this 500: \n%s' % traceback_info ) #NEWLINE# message = ( '%s \n\n %s \n\n %s' % ( message , extra_message , traceback_info ) ) #NEWLINE# #UNINDENT# email = EmailMessage ( subject = subject , body = message , to = settings . BUG_REPORT_RECIPIENTS , headers = { #NEWLINE# #INDENT# 'Reply-To' : reply_to , #NEWLINE# #UNINDENT# } , cc = cc ) #NEWLINE# uploaded_file = req . FILES . get ( 'report_issue' ) #NEWLINE# if uploaded_file : #NEWLINE# #INDENT# filename = uploaded_file . name #NEWLINE# content = uploaded_file . read ( ) #NEWLINE# email . attach ( filename = filename , content = content ) #NEWLINE# #UNINDENT# if re . search ( '@dimagi\\.com$' , report [ 'username' ] ) : #NEWLINE# #INDENT# email . from_email = report [ 'username' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# email . from_email = settings . CCHQ_BUG_REPORT_EMAIL #NEWLINE# #UNINDENT# email . send ( fail_silently = False ) #NEWLINE# if req . POST . get ( 'five-hundred-report' ) : #NEWLINE# #INDENT# messages . success ( req , 'Your CommCare HQ Issue Report has been sent. We are working quickly to resolve this problem.' ) #NEWLINE# return HttpResponseRedirect ( reverse ( 'homepage' ) ) #NEWLINE# #UNINDENT# return HttpResponse ( )