Simplify database creation error catching for the history app
This commit is contained in:
@@ -3,15 +3,7 @@ from __future__ import absolute_import
|
||||
import pickle
|
||||
import json
|
||||
|
||||
try:
|
||||
from psycopg2 import OperationalError
|
||||
except ImportError:
|
||||
class OperationalError(Exception):
|
||||
pass
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import transaction
|
||||
from django.db.utils import DatabaseError
|
||||
from django.core import serializers
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db import models
|
||||
@@ -20,33 +12,23 @@ from .models import HistoryType, History
|
||||
from .runtime_data import history_types_dict
|
||||
|
||||
|
||||
@transaction.commit_manually
|
||||
@transaction.commit_on_success
|
||||
def register_history_type(history_type_dict):
|
||||
namespace = history_type_dict['namespace']
|
||||
name = history_type_dict['name']
|
||||
try:
|
||||
# Permanent
|
||||
history_type_obj, created = HistoryType.objects.get_or_create(
|
||||
namespace=namespace, name=name)
|
||||
history_type_obj.save()
|
||||
|
||||
# Runtime
|
||||
history_types_dict.setdefault(namespace, {})
|
||||
history_types_dict[namespace][name] = {
|
||||
'label': history_type_dict['label'],
|
||||
'summary': history_type_dict.get('summary', u''),
|
||||
'details': history_type_dict.get('details', u''),
|
||||
'expressions': history_type_dict.get('expressions', []),
|
||||
}
|
||||
except DatabaseError:
|
||||
transaction.rollback()
|
||||
# Special case for ./manage.py syncdb
|
||||
except (OperationalError, ImproperlyConfigured):
|
||||
transaction.rollback()
|
||||
# Special for DjangoZoom, which executes collectstatic media
|
||||
# doing syncdb and creating the database tables
|
||||
else:
|
||||
transaction.commit()
|
||||
history_type_obj, created = HistoryType.objects.get_or_create(
|
||||
namespace=namespace, name=name)
|
||||
history_type_obj.save()
|
||||
|
||||
# Runtime
|
||||
history_types_dict.setdefault(namespace, {})
|
||||
history_types_dict[namespace][name] = {
|
||||
'label': history_type_dict['label'],
|
||||
'summary': history_type_dict.get('summary', u''),
|
||||
'details': history_type_dict.get('details', u''),
|
||||
'expressions': history_type_dict.get('expressions', []),
|
||||
}
|
||||
|
||||
|
||||
def create_history(history_type_dict, source_object=None, data=None):
|
||||
|
||||
Reference in New Issue
Block a user