# HG changeset patch # User neko259 # Date 2016-05-22 11:17:48 # Node ID beb328602bc826a895430167e657546646f34102 # Parent 24ed0df7f0163bf23bfa1350d6e2f7444cf3e27d Moved exceptions to a separate module diff --git a/boards/abstracts/exceptions.py b/boards/abstracts/exceptions.py new file mode 100644 --- /dev/null +++ b/boards/abstracts/exceptions.py @@ -0,0 +1,10 @@ +class BannedException(Exception): + pass + + +class ArchiveException(Exception): + pass + + +class SyncException(Exception): + pass diff --git a/boards/models/post/manager.py b/boards/models/post/manager.py --- a/boards/models/post/manager.py +++ b/boards/models/post/manager.py @@ -3,6 +3,7 @@ import logging from datetime import datetime, timedelta, date from datetime import time as dtime +from boards.abstracts.exceptions import BannedException, ArchiveException from django.db import models, transaction from django.utils import timezone from django.dispatch import Signal @@ -33,16 +34,15 @@ class PostManager(models.Manager): """ if thread is not None and thread.is_archived(): - raise Exception('Cannot post into an archived thread') + raise ArchiveException('Cannot post into an archived thread') if not utils.is_anonymous_mode(): is_banned = Ban.objects.filter(ip=ip).exists() else: is_banned = False - # TODO Raise specific exception and catch it in the views if is_banned: - raise Exception("This user is banned") + raise BannedException("This user is banned") if not tags: tags = [] diff --git a/boards/models/post/sync.py b/boards/models/post/sync.py --- a/boards/models/post/sync.py +++ b/boards/models/post/sync.py @@ -1,9 +1,10 @@ import xml.etree.ElementTree as et +from boards.abstracts.exceptions import SyncException +from boards.models import KeyPair, GlobalId, Signature, Post, Tag from boards.models.attachment.downloaders import download from boards.utils import get_file_mimetype, get_file_hash from django.db import transaction -from boards.models import KeyPair, GlobalId, Signature, Post, Tag EXCEPTION_NODE = 'Sync node returned an error: {}.' EXCEPTION_OP = 'Load the OP first.' @@ -52,10 +53,6 @@ ID_TYPE_MD5 = 'md5' STATUS_SUCCESS = 'success' -class SyncException(Exception): - pass - - class SyncManager: @staticmethod def generate_response_get(model_list: list):