Removed unused import, PEP8 cleanups

This commit is contained in:
Roberto Rosario
2011-08-12 02:13:23 -04:00
parent 09f1c2bd2f
commit 0a2591d58f
38 changed files with 295 additions and 142 deletions

View File

@@ -1,5 +1,5 @@
# From: http://www.micahcarrick.com/django-email-authentication.html
from django.contrib.auth.models import User, check_password
from django.contrib.auth.models import User
from django.contrib.auth.backends import ModelBackend

View File

@@ -165,4 +165,3 @@ class ChangelogForm(forms.Form):
fd = open(changelog_path)
self.fields['text'].initial = fd.read()
fd.close()

View File

@@ -358,12 +358,6 @@ def validate_path(path):
return True
#def encapsulate(function):
# def wrapper():
# return function
# return wrapper
def encapsulate(function):
# Workaround Django ticket 15791
# Changeset 16045

View File

@@ -1,5 +1,3 @@
import os
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseRedirect
@@ -10,10 +8,8 @@ from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.utils.http import urlencode
from django.contrib.auth.views import login
from django.conf import settings
from django.utils.safestring import mark_safe
from common.forms import ChoiceForm, UserForm, UserForm_view
from common.forms import ChoiceForm, UserForm, UserForm_view, ChangelogForm
from common.forms import EmailAuthenticationForm
from common.conf.settings import LOGIN_METHOD
@@ -184,11 +180,8 @@ def login_view(request):
return login(request, **kwargs)
from common.forms import ChangelogForm
def changelog(request):
#changelog_widget = mark_safe(u'<form class="form"><div class="group"><textarea rows="10" cols="40" class="text_area">%s</textarea></div></form>' % changelog)
form = ChangelogForm()
return render_to_response(
'generic_detail.html', {

View File

@@ -4,8 +4,8 @@ from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe
from django import forms
from django.forms.util import flatatt
from django.utils.html import escape, conditional_escape
from django.utils.encoding import StrAndUnicode, force_unicode
from django.utils.html import conditional_escape
from django.utils.encoding import force_unicode
class PlainWidget(forms.widgets.Widget):
@@ -77,7 +77,8 @@ class TextAreaDiv(forms.widgets.Widget):
super(TextAreaDiv, self).__init__(default_attrs)
def render(self, name, value, attrs=None):
if value is None: value = ''
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
result = mark_safe(u'<div%s>%s</div>' % (flatatt(final_attrs),
conditional_escape(force_unicode(value))))

View File

@@ -5,15 +5,14 @@ import hashlib
from common.conf.settings import TEMPORARY_DIRECTORY
from converter.conf.settings import UNOCONV_PATH
from converter.exceptions import OfficeConversionError, UnknownFileFormat
from converter.exceptions import OfficeConversionError
from converter.literals import DEFAULT_PAGE_NUMBER, \
DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, DEFAULT_FILE_FORMAT
from converter import backend
from converter.literals import TRANSFORMATION_CHOICES
from converter.literals import TRANSFORMATION_RESIZE, \
TRANSFORMATION_ROTATE, TRANSFORMATION_DENSITY, \
TRANSFORMATION_ZOOM
TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM
from converter.literals import DIMENSION_SEPARATOR
from converter.utils import cleanup

View File

@@ -7,8 +7,7 @@ from converter.exceptions import ConvertError, UnknownFileFormat, \
IdentifyError
from converter.backends import ConverterBase
from converter.literals import TRANSFORMATION_RESIZE, \
TRANSFORMATION_ROTATE, TRANSFORMATION_DENSITY, \
TRANSFORMATION_ZOOM
TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM
from converter.literals import DIMENSION_SEPARATOR, DEFAULT_PAGE_NUMBER, \
DEFAULT_FILE_FORMAT

View File

@@ -10,11 +10,9 @@ try:
except RuntimeError:
USE_GHOSTSCRIPT = False
from django.utils.translation import ugettext_lazy as _
from mimetype.api import get_mimetype
from converter.exceptions import ConvertError, UnknownFileFormat, IdentifyError
from converter.exceptions import UnknownFileFormat
from converter.backends import ConverterBase
from converter.literals import TRANSFORMATION_RESIZE, \
TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM
@@ -84,7 +82,8 @@ class ConverterClass(ConverterBase):
try:
im = Image.open(input_filepath)
except Exception: # Python Imaging Library doesn't recognize it as an image
except Exception:
# Python Imaging Library doesn't recognize it as an image
raise UnknownFileFormat
finally:
if tmpfile:
@@ -97,7 +96,8 @@ class ConverterClass(ConverterBase):
current_page += 1
# do something to im
except EOFError:
pass # end of sequence
# end of sequence
pass
try:
if transformations:

View File

@@ -71,7 +71,8 @@ def load_backend():
(backend_name, ", ".join(map(repr, available_backends)), e_user)
raise ImproperlyConfigured(error_msg)
else:
raise # If there's some other error, this must be an error in Mayan itself.
# If there's some other error, this must be an error in Mayan itself.
raise
def cleanup(filename):

View File

@@ -7,6 +7,7 @@ from common.utils import encapsulate
from converter import backend
from converter.conf.settings import GRAPHICS_BACKEND
def formats_list(request):
#check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])

View File

@@ -105,7 +105,6 @@ def document_index_list(request, document_id):
for index_instance in document.indexinstance_set.all():
object_list.append(get_breadcrumbs(index_instance, single_link=True, include_count=True))
return render_to_response('generic_list.html', {
'title': _(u'indexes containing: %s') % document,
'object_list': object_list,

View File

@@ -25,7 +25,6 @@ from documents.literals import HISTORY_DOCUMENT_CREATED, \
HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED
from documents.conf.settings import ZOOM_MAX_LEVEL
from documents.conf.settings import ZOOM_MIN_LEVEL
from documents.conf.settings import CACHE_PATH
from documents.conf import settings as document_settings
from documents.widgets import document_thumbnail

View File

@@ -9,7 +9,6 @@ from django.utils.translation import ugettext
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.comments.models import Comment
from django.conf import settings
from django.core.exceptions import ValidationError
from taggit.managers import TaggableManager
@@ -31,8 +30,6 @@ from documents.conf.settings import CACHE_PATH
from documents.managers import RecentDocumentManager, \
DocumentPageTransformationManager
from documents.utils import document_save_to_temp_dir
from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
from converter.literals import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \
DEFAULT_PAGE_NUMBER

View File

@@ -8,7 +8,6 @@ from django.template import RequestContext
from django.contrib import messages
from django.views.generic.list_detail import object_list
from django.core.urlresolvers import reverse
from django.views.generic.create_update import delete_object, update_object
from django.utils.http import urlencode
import sendfile
@@ -19,7 +18,7 @@ from common.literals import PAGE_SIZE_DIMENSIONS, \
PAGE_ORIENTATION_PORTRAIT, PAGE_ORIENTATION_LANDSCAPE
from common.conf.settings import DEFAULT_PAPER_SIZE
from converter.literals import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \
DEFAULT_FILE_FORMAT, DEFAULT_PAGE_NUMBER
DEFAULT_PAGE_NUMBER
from filetransfers.api import serve_file
from grouping.utils import get_document_group_subtemplate
from metadata.forms import MetadataFormSet, MetadataSelectionForm

View File

3
apps/exporter/models.py Normal file
View File

@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

16
apps/exporter/tests.py Normal file
View File

@@ -0,0 +1,16 @@
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from django.test import TestCase
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)

5
apps/exporter/urls.py Normal file
View File

@@ -0,0 +1,5 @@
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('exporter.views',
url(r'^export_test/$', 'export_test', (), 'export_test'),
)

150
apps/exporter/views.py Normal file
View File

@@ -0,0 +1,150 @@
import os
import hashlib
from django.utils import simplejson
from django.http import HttpResponse
from django.template.defaultfilters import slugify
from documents.models import Document, DocumentType
from metadata.models import MetadataType, MetadataSet
FORMAT_VERSION = 1.0
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
def get_hash(obj):
if obj:
return u'%s_%s' % (HASH_FUNCTION(unicode(obj)), slugify(unicode(obj)))
else:
return None
'''
comments
tags
folders
pages
pages transformation
metadata
doc_type metadata
sources
sources transform
users
class DocumentTypeDefaults(models.Model):
"""
Default preselected metadata types and metadata set per document
type
"""
document_type = models.ForeignKey(DocumentType, verbose_name=_(u'document type'))
default_metadata_sets = models.ManyToManyField(MetadataSet, blank=True, verbose_name=_(u'default metadata sets'))
default_metadata = models.ManyToManyField(MetadataType, blank=True, verbose_name=_(u'default metadata'))
'''
def export_test(request):
big_list = []
big_list.append({'version': FORMAT_VERSION})
for metadata_type in MetadataType.objects.all():
big_list.append(
{
'metadata_types': [
{
'id': get_hash(metadata_type.name),
'name': metadata_type.name,
'title': metadata_type.title,
'default': metadata_type.default,
'lookup': metadata_type.lookup,
}
]
}
)
for metadata_set in MetadataSet.objects.all():
big_list.append(
{
'metadata_sets': [
{
'id': get_hash(metadata_set.title),
'name': metadata_set.title,
'metadata_types': [
{
'id': get_hash(metadata_type),
}
for metadata_type in metadata_set.metadatasetitem_set.all()
]
}
]
}
)
for document_type in DocumentType.objects.all():
big_list.append(
{
'document_types': [
{
'id': get_hash(document_type.name),
'name': document_type.name,
'filenames': [
{
'filename': doc_type_filename.filename,
'enabled': doc_type_filename.enabled,
}
for doc_type_filename in document_type.documenttypefilename_set.all()
],
'metadata_defaults': [
{
'default_metadata': [get_hash(metadata_type.name) for metadata_type in doc_type_defaults.default_metadata.all()],
'default_metadata_sets': [get_hash(metadata_set.title) for metadata_set in doc_type_defaults.default_metadata_sets.all()],
}
for doc_type_defaults in document_type.documenttypedefaults_set.all()
]
}
]
}
)
for document in Document.objects.all()[:10]:
big_list.append(
{
'documents': [
{
'document_type': get_hash(document.document_type),
'filename': os.extsep.join([document.file_filename, document.file_extension]),
#'date_added'
'uuid': document.uuid,
'description': unicode(document.description) if document.description else None,
'tags': [get_hash(tag) for tag in document.tags.all()],
'folders': [get_hash(folder_document.folder) for folder_document in document.folderdocument_set.all()],
'comments': [
{
'comment': comment.comment,
'user': unicode(comment.user),
'submit_date': unicode(comment.submit_date),
}
for comment in document.comments.all()
],
'versions': [
{
1.0: {
'mimetype': document.file_mimetype,
'encoding': document.file_mime_encoding,
#'date_updated'
'checksum': document.checksum,
}
}
]
}
]
}
)
return HttpResponse(simplejson.dumps(big_list, indent=4, ensure_ascii=True), mimetype='application/json')

View File

@@ -2,7 +2,6 @@ from django.utils.translation import ugettext_lazy as _
from navigation.api import register_links, register_top_menu, \
register_multi_item_links, register_sidebar_template
from navigation.api import register_sidebar_template
from documents.models import Document
from documents.literals import PERMISSION_DOCUMENT_VIEW

View File

@@ -9,7 +9,6 @@ from django.core.exceptions import PermissionDenied
from documents.literals import PERMISSION_DOCUMENT_VIEW
from documents.models import Document
from documents.widgets import document_thumbnail, document_link
from permissions.api import check_permissions
from common.utils import encapsulate
@@ -36,6 +35,7 @@ def folder_list(request, queryset=None, extra_context=None):
extra_context=context,
)
def folder_create(request):
if request.method == 'POST':
form = FolderForm(request.POST)

View File

@@ -10,7 +10,6 @@ except ImportError:
from django.core.exceptions import ImproperlyConfigured
from django.db import transaction
from django.db.utils import DatabaseError
#from django.utils import simplejson
from django.core import serializers
from django.shortcuts import get_object_or_404
from django.db import models
@@ -18,6 +17,7 @@ from django.db import models
from history.models import HistoryType, History
from history.runtime_data import history_types_dict
@transaction.commit_manually
def register_history_type(history_type_dict):
namespace = history_type_dict['namespace']

View File

@@ -73,6 +73,7 @@ register_tool(all_document_ocr_cleanup, namespace='ocr', title=_(u'OCR'))
#Menus
register_top_menu('ocr', link={'text': _('OCR'), 'famfam': 'hourglass', 'view': 'queue_document_list'}, children_path_regex=[r'^ocr/'])
@transaction.commit_manually
def create_default_queue():
try:

View File

@@ -1,5 +1,4 @@
from django.db import models
from django.contrib.contenttypes.models import ContentType
from ocr.exceptions import AlreadyQueued

View File

@@ -4,7 +4,6 @@ from time import sleep
from random import random
from django.db.models import Q
from django.utils.translation import ugettext as _
from django.core.cache import get_cache
from job_processor.api import process_job

View File

@@ -1,8 +1,7 @@
from django.utils.translation import ugettext_lazy as _
from navigation.api import register_links, \
register_model_list_columns, register_multi_item_links, \
register_sidebar_template
register_model_list_columns
from permissions.api import register_permission, set_namespace_title
from sources.staging import StagingFile

View File

@@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError
from converter.api import get_available_transformations_choices
from converter.literals import DIMENSION_SEPARATOR
from documents.models import DocumentType, Document#, RecentDocument
from documents.models import DocumentType, Document
from documents.literals import HISTORY_DOCUMENT_CREATED
from document_indexing.api import update_indexes
from history.api import create_history
@@ -145,6 +145,7 @@ class SourceMetadata(models.Model):
verbose_name_plural = _(u'sources metadata')
'''
class WebForm(InteractiveBaseModel):
is_interactive = True
source_type = SOURCE_CHOICE_WEB_FORM

View File

@@ -5,7 +5,6 @@ import hashlib
from django.core.files.base import File
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from mimetype.api import get_icon_file_path, get_error_icon_file_path, \
get_mimetype

View File

@@ -6,8 +6,10 @@ from django.utils.translation import ugettext
# From http://www.peterbe.com/plog/whitelist-blacklist-logic
def accept_item(value, whitelist, blacklist, default_accept=True):
""" return true if this item is either whitelisted or
not blacklisted """
"""
return true if this item is either whitelisted or
not blacklisted
"""
if not whitelist:
whitelist = []

View File

@@ -59,7 +59,6 @@ class SettingsNode(Node):
context[self.var_name] = getattr(web_theme_settings, self.format_string, '')
return ''
from django.utils.safestring import mark_safe
@register.tag
def get_web_theme_setting(parser, token):