PEP8 and general cleanups
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os, sys
|
||||
import os
|
||||
import sys
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError, LabelCommand
|
||||
from django.utils.simplejson import loads, dumps
|
||||
from django.utils.simplejson import loads
|
||||
|
||||
from metadata.api import convert_dict_to_dict_list
|
||||
from documents.models import DocumentType
|
||||
@@ -25,7 +26,7 @@ class Command(LabelCommand):
|
||||
make_option('--document_type', action='store', dest='document_type_name',
|
||||
help='The document type to apply to the uploaded documents.'),
|
||||
)
|
||||
|
||||
|
||||
def handle_label(self, label, **options):
|
||||
if not os.access(label, os.R_OK):
|
||||
raise CommandError("File '%s' is not readable." % label)
|
||||
@@ -53,10 +54,10 @@ class Command(LabelCommand):
|
||||
print 'Using the metadata values:'
|
||||
for key, value in metadata_dict.items():
|
||||
print '%s: %s' % (key, value)
|
||||
|
||||
|
||||
if document_type:
|
||||
print 'Uploaded document will be of type: %s' % options['document_type_name']
|
||||
|
||||
|
||||
source = OutOfProcess()
|
||||
fd = open(label)
|
||||
try:
|
||||
@@ -71,7 +72,7 @@ class Command(LabelCommand):
|
||||
else:
|
||||
print 'Cancelled.'
|
||||
|
||||
|
||||
|
||||
def _confirm(interactive):
|
||||
if not interactive:
|
||||
return 'yes'
|
||||
|
||||
@@ -9,7 +9,6 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
from django.db.utils import DatabaseError
|
||||
|
||||
from converter.api import get_available_transformations_choices
|
||||
from converter.literals import DIMENSION_SEPARATOR
|
||||
@@ -91,7 +90,7 @@ class BaseModel(models.Model):
|
||||
@transaction.commit_on_success
|
||||
def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None):
|
||||
new_document = not document
|
||||
|
||||
|
||||
if not document:
|
||||
document = Document()
|
||||
if document_type:
|
||||
@@ -99,7 +98,7 @@ class BaseModel(models.Model):
|
||||
document.save()
|
||||
|
||||
apply_default_acls(document, user)
|
||||
|
||||
|
||||
if user:
|
||||
document.add_as_recent_document_for_user(user)
|
||||
create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
|
||||
@@ -113,7 +112,7 @@ class BaseModel(models.Model):
|
||||
|
||||
if not new_version_data:
|
||||
new_version_data = {}
|
||||
|
||||
|
||||
try:
|
||||
new_version = document.new_version(file=file_object, **new_version_data)
|
||||
except Exception:
|
||||
@@ -121,7 +120,7 @@ class BaseModel(models.Model):
|
||||
# document.delete()
|
||||
transaction.rollback()
|
||||
raise
|
||||
|
||||
|
||||
if filename:
|
||||
document.rename(filename)
|
||||
|
||||
@@ -129,11 +128,11 @@ class BaseModel(models.Model):
|
||||
|
||||
new_version.apply_default_transformations(transformations)
|
||||
#TODO: new HISTORY for version updates
|
||||
|
||||
|
||||
if metadata_dict_list and new_document:
|
||||
# Only do for new documents
|
||||
save_metadata_list(metadata_dict_list, document, create=True)
|
||||
warnings = update_indexes(document)
|
||||
warnings = update_indexes(document)
|
||||
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
@@ -288,6 +287,7 @@ class SourceTransformation(models.Model):
|
||||
|
||||
class OutOfProcess(BaseModel):
|
||||
is_interactive = False
|
||||
|
||||
class Meta(BaseModel.Meta):
|
||||
verbose_name = _(u'out of process')
|
||||
verbose_name_plural = _(u'out of process')
|
||||
|
||||
@@ -165,13 +165,13 @@ def upload_interactive(request, source_type=None, source_id=None, document_pk=No
|
||||
else:
|
||||
if result['is_compressed'] == None:
|
||||
messages.success(request, _(u'File uploaded successfully.'))
|
||||
|
||||
|
||||
if result['is_compressed'] == True:
|
||||
messages.success(request, _(u'File uncompressed successfully and uploaded as individual files.'))
|
||||
|
||||
|
||||
if result['is_compressed'] == False:
|
||||
messages.warning(request, _(u'File was not a compressed file, uploaded as it was.'))
|
||||
|
||||
|
||||
return HttpResponseRedirect(request.get_full_path())
|
||||
except Exception, e:
|
||||
if settings.DEBUG:
|
||||
@@ -240,7 +240,7 @@ def upload_interactive(request, source_type=None, source_id=None, document_pk=No
|
||||
|
||||
if result['is_compressed'] == True:
|
||||
messages.success(request, _(u'Staging file: %s, uncompressed successfully and uploaded as individual files.') % staging_file.filename)
|
||||
|
||||
|
||||
if result['is_compressed'] == False:
|
||||
messages.warning(request, _(u'Staging file: %s, was not compressed, uploaded as a single file.') % staging_file.filename)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user