# HG changeset patch # User Lennard de Rijk # Date 1247428812 -7200 # Node ID dbc8a50dbce0c4d206b7bb8e2e4bd07d264406c8 # Parent 169d69967431f160c5abbdd43dc7571fd79775cc Refactored logErrorAndReturnOK into separate module. diff -r 169d69967431 -r dbc8a50dbce0 app/soc/tasks/helper/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/tasks/helper/__init__.py Sun Jul 12 22:00:12 2009 +0200 @@ -0,0 +1,16 @@ +# +# Copyright 2009 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This module contains Melange Task API related helper modules.""" \ No newline at end of file diff -r 169d69967431 -r dbc8a50dbce0 app/soc/tasks/helper/error_handler.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/soc/tasks/helper/error_handler.py Sun Jul 12 22:00:12 2009 +0200 @@ -0,0 +1,37 @@ +#!/usr/bin/python2.5 +# +# Copyright 2009 the Melange authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Module for handling errors while running a Task. +""" + +__authors__ = [ + '"Lennard de Rijk" ', + ] + + +import logging + +from django import http + + +def logErrorAndReturnOK(error_msg='Error found in Task'): + """Logs the given error message and returns a HTTP OK response. + + Args: + error_msg: Error message to log + """ + logging.error(error_msg) + return http.HttpResponse() diff -r 169d69967431 -r dbc8a50dbce0 app/soc/tasks/surveys.py --- a/app/soc/tasks/surveys.py Sun Jul 12 11:46:36 2009 -0500 +++ b/app/soc/tasks/surveys.py Sun Jul 12 22:00:12 2009 +0200 @@ -29,6 +29,8 @@ from django import http +from soc.tasks.helper import error_handler + def getDjangoURLPatterns(): """Returns the URL patterns for the tasks in this module. @@ -75,7 +77,7 @@ if not (program_key and survey_key and survey_type): # invalid task data, log and return OK - return logErrorAndReturnOK( + return error_handler.logErrorAndReturnOK( 'Invalid sendRemindersForProjectSurvey data: %s' % post_dict) # get the program for the given keyname @@ -83,7 +85,8 @@ if not program_entity: # invalid program specified, log and return OK - return logErrorAndReturnOK('Invalid program specified: %s' % program_key) + return error_handler.logErrorAndReturnOK( + 'Invalid program specified: %s' % program_key) # check and retrieve the project_key that has been done last if 'project_key' in post_dict: @@ -101,8 +104,8 @@ if not project_start: # invalid starting project key specified, log and return OK - return logErrorAndReturnOK('Invalid Student Project Key specified: %s' %( - project_start_key)) + return error_handler.logErrorAndReturnOK( + 'Invalid Student Project Key specified: %s' %(project_start_key)) fields['__key__ >'] = project_start.key() @@ -169,7 +172,7 @@ if not (project_key and survey_key and survey_type): # invalid task data, log and return OK - return logErrorAndReturnOK( + return error_handler.logErrorAndReturnOK( 'Invalid sendSurveyReminderForProject data: %s' % post_dict) # set logic depending on survey type specified in POST @@ -183,13 +186,15 @@ if not student_project: # no existing project found, log and return OK - return logErrorAndReturnOK('Invalid project specified %s:' % project_key) + return error_handler.logErrorAndReturnOK( + 'Invalid project specified %s:' % project_key) survey = survey_logic.getFromKeyName(survey_key) if not survey: # no existing survey found, log and return OK - return logErrorAndReturnOK('Invalid survey specified %s:' % survey_key) + return error_handler.logErrorAndReturnOK( + 'Invalid survey specified %s:' % survey_key) # try to retrieve an existing record record_logic = survey_logic.getRecordLogic() @@ -258,13 +263,3 @@ # return OK return http.HttpResponse() - - -def logErrorAndReturnOK(error_msg='Error found in Survey Task'): - """Logs the given error message and returns a HTTP OK response. - - Args: - error_msg: Error message to log - """ - logging.error(error_msg) - return http.HttpResponse()