Skip to content

Commit

Permalink
[#1770] Remove custom RSR exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Sep 8, 2015
1 parent f714d2e commit c0bc3ad
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 55 deletions.
12 changes: 4 additions & 8 deletions akvo/iati/imports/fields/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]


Expand All @@ -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
Expand Down
26 changes: 13 additions & 13 deletions akvo/iati/imports/iati_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 11 additions & 13 deletions akvo/iati/imports/iati_import_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
21 changes: 0 additions & 21 deletions akvo/rsr/exceptions.py

This file was deleted.

0 comments on commit c0bc3ad

Please sign in to comment.