From c0bc3ad8e2b5464b412910209ff9b1f3f4c0c341 Mon Sep 17 00:00:00 2001 From: Kasper Brandt Date: Tue, 8 Sep 2015 11:47:39 +0300 Subject: [PATCH] [#1770] Remove custom RSR exceptions --- akvo/iati/imports/fields/image.py | 12 ++++------- akvo/iati/imports/iati_import.py | 26 +++++++++++------------ akvo/iati/imports/iati_import_activity.py | 24 ++++++++++----------- akvo/rsr/exceptions.py | 21 ------------------ 4 files changed, 28 insertions(+), 55 deletions(-) delete mode 100644 akvo/rsr/exceptions.py diff --git a/akvo/iati/imports/fields/image.py b/akvo/iati/imports/fields/image.py index a4226ae6ee..981a82fc65 100644 --- a/akvo/iati/imports/fields/image.py +++ b/akvo/iati/imports/fields/image.py @@ -4,19 +4,19 @@ # See more details in the license.txt file located at the root folder of the Akvo RSR module. # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. -from ....rsr.exceptions import ProjectFieldException - from django.conf import settings +from django.core.exceptions import ValidationError from django.core.files import File from django.core.files.temp import NamedTemporaryFile import urllib2 VALID_IMAGE_EXTENSIONS = [ + 'gif', 'jpg', 'jpeg', 'png', - 'gif' + 'tiff' ] @@ -43,11 +43,7 @@ def current_image(activity, project, activities_globals): image_extension = image_url.rsplit('.', 1)[1].lower() if not image_extension in VALID_IMAGE_EXTENSIONS: - raise ProjectFieldException({ - 'message': u'%s is not a valid image extension.' % image_extension, - 'project': project, - 'field': u'Image' - }) + raise ValidationError(u'%s is not a valid image extension' % image_extension) if not project.current_image or \ (project.current_image diff --git a/akvo/iati/imports/iati_import.py b/akvo/iati/imports/iati_import.py index 3b14856c2a..acd836338a 100644 --- a/akvo/iati/imports/iati_import.py +++ b/akvo/iati/imports/iati_import.py @@ -5,7 +5,6 @@ # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. from ...rsr.models.iati_import_log import IatiImportLog -from ...rsr.exceptions import ProjectException from .iati_import_activity import IatiImportActivity from django.core.files import File @@ -149,19 +148,20 @@ def __init__(self, iati_import): try: IatiImportActivity(self.iati_import, activity, self.organisation, self.user, self.activities.attrib) - except ProjectException as pe: - IatiImportLog.objects.create( - iati_import=self.iati_import, - text=pe.args[0]['message'], - project=pe.args[0]['project'], - error=True - ) except Exception as e: - IatiImportLog.objects.create( - iati_import=self.iati_import, - text=e, - error=True - ) + if 'project' in e.args[0].keys(): + IatiImportLog.objects.create( + iati_import=self.iati_import, + text=e.args[0]['message'], + project=e.args[0]['project'], + error=True + ) + else: + IatiImportLog.objects.create( + iati_import=self.iati_import, + text=e, + error=True + ) # Import process complete self.set_status(4) diff --git a/akvo/iati/imports/iati_import_activity.py b/akvo/iati/imports/iati_import_activity.py index 72976ef267..00230ad6a7 100644 --- a/akvo/iati/imports/iati_import_activity.py +++ b/akvo/iati/imports/iati_import_activity.py @@ -4,8 +4,6 @@ # See more details in the license.txt file located at the root folder of the Akvo RSR module. # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. -from ...rsr.exceptions import ProjectException, ProjectFieldException - from django.contrib.admin.models import LogEntry, CHANGE from django.contrib.contenttypes.models import ContentType from django.db.models import get_model @@ -100,8 +98,9 @@ def set_sync_owner(self): self.set_end_date() self.set_status(4) self.set_errors_true() - raise ProjectException({ - 'message': u'Project has a different sync_owner: %s.' % sync_owner.name, + raise Exception({ + 'message': u'sync_owner: Project has a different sync_owner (%s).' % + sync_owner.name, 'project': self.project }) self.project.sync_owner = self.organisation @@ -150,19 +149,18 @@ def __init__(self, iati_import, activity, reporting_organisation, user, activiti for field in FIELDS: try: changes = getattr(fields, field)(self.activity, self.project, self.globals) - except ProjectFieldException as pfe: - changes = [] - get_model('rsr', 'iatiimportlog').objects.create( - iati_import=self.iati_import, - text=u'%s: %s' % (pfe.args[0]['field'], pfe.args[0]['message']), - project=pfe.args[0]['project'], - error=True - ) except Exception as e: changes = [] + if isinstance(e, basestring): + text = e + else: + try: + text = u", ".join(str(e_part) for e_part in e) + except TypeError: + text = e get_model('rsr', 'iatiimportlog').objects.create( iati_import=self.iati_import, - text=u'%s: %s' % (field, e), + text=u'%s: %s.' % (field, text), project=self.project, error=True ) diff --git a/akvo/rsr/exceptions.py b/akvo/rsr/exceptions.py deleted file mode 100644 index 86c6ef29d5..0000000000 --- a/akvo/rsr/exceptions.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- - -# Akvo RSR is covered by the GNU Affero General Public License. -# See more details in the license.txt file located at the root folder of the Akvo RSR module. -# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >. - - -class ProjectException(Exception): - """ - A specific Exception used in IATI imports for errors belonging to a project. - Assumes that a project is passed together with the message in a dictionary. - """ - pass - - -class ProjectFieldException(Exception): - """ - A specific Exception used in IATI imports for errors belonging to a project's field. - Assumes that a project and a field is passed together with the message in a dictionary. - """ - pass