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,12 +1,12 @@
# 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
class EmailAuthBackend(ModelBackend):
"""
Email Authentication Backend
Allows a user to sign in using an email/password pair rather than
a username/password pair.
"""

View File

@@ -51,7 +51,7 @@ class DetailForm(forms.ModelForm):
self.fields[field_name].widget = TextAreaDiv(
attrs=field.widget.attrs,
)
for field_name, field in self.fields.items():
self.fields[field_name].widget.attrs.update({'readonly': 'readonly'})
@@ -128,10 +128,10 @@ class EmailAuthenticationForm(AuthenticationForm):
Override the default authentication form to use email address
authentication
"""
email = forms.CharField(label=_(u'Email'), max_length=75,
email = forms.CharField(label=_(u'Email'), max_length=75,
widget=EmailInput()
)
def clean(self):
email = self.cleaned_data.get('email')
password = self.cleaned_data.get('password')
@@ -145,7 +145,7 @@ class EmailAuthenticationForm(AuthenticationForm):
self.check_for_test_cookie()
return self.cleaned_data
# Remove the inherited username field
# Remove the inherited username field
EmailAuthenticationForm.base_fields.keyOrder = ['email', 'password']
@@ -164,5 +164,4 @@ class ChangelogForm(forms.Form):
changelog_path = os.path.join(settings.PROJECT_ROOT, CHANGELOG_DIRECTORY, CHANGELOG_FILENAME)
fd = open(changelog_path)
self.fields['text'].initial = fd.read()
fd.close()
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
@@ -181,18 +177,15 @@ def login_view(request):
if LOGIN_METHOD == 'email':
kwargs['authentication_form'] = EmailAuthenticationForm
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)
def changelog(request):
form = ChangelogForm()
return render_to_response(
'generic_detail.html', {
'form': form,
'title': _(u'Changelog'),
},
context_instance=RequestContext(request))
context_instance=RequestContext(request))

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,11 +77,12 @@ 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))))
return mark_safe(result.replace('\n', '<br>'))

View File

@@ -5,16 +5,15 @@ 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
from converter.literals import DIMENSION_SEPARATOR
TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM
from converter.literals import DIMENSION_SEPARATOR
from converter.utils import cleanup
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
@@ -51,7 +50,7 @@ def create_image_cache_filename(input_filepath, *args, **kwargs):
return os.path.join(TEMPORARY_DIRECTORY, hash_value)
else:
return None
def convert_office_document(input_filepath):
if os.path.exists(UNOCONV_PATH):
@@ -136,5 +135,5 @@ def get_available_transformations_choices():
for transformation in backend.get_available_transformations():
transformation_template = u'%s %s' % (TRANSFORMATION_CHOICES[transformation]['label'], u','.join(['<%s>' % argument['name'] if argument['required'] else '[%s]' % argument['name'] for argument in TRANSFORMATION_CHOICES[transformation]['arguments']]))
result.append([transformation, transformation_template])
return result

View File

@@ -13,6 +13,6 @@ class ConverterBase(object):
def get_available_transformations(self):
raise NotImplementedError("Your %s class has not defined a get_available_transformations() method, which is required." % self.__class__.__name__)
def get_page_count(self):
raise NotImplementedError("Your %s class has not defined a get_page_count() method, which is required." % self.__class__.__name__)

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
@@ -26,7 +24,7 @@ from converter.utils import cleanup
class ConverterClass(ConverterBase):
def get_page_count(self, input_filepath):
page_count = 1
mimetype, encoding = get_mimetype(input_filepath)
if mimetype == 'application/pdf':
# If file is a PDF open it with slate to determine the page
@@ -37,7 +35,7 @@ class ConverterClass(ConverterBase):
try:
im = Image.open(input_filepath)
except IOError: #cannot identify image file
except IOError: # cannot identify image file
raise UnknownFileFormat
try:
@@ -46,10 +44,10 @@ class ConverterClass(ConverterBase):
page_count += 1
# do something to im
except EOFError:
pass # end of sequence
pass # end of sequence
return page_count
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT):
tmpfile = None
mimetype, encoding = get_mimetype(input_filepath)
@@ -79,12 +77,13 @@ class ConverterClass(ConverterBase):
]
ghostscript.Ghostscript(*args)
page = 1 # Don't execute the following while loop
page = 1 # Don't execute the following while loop
input_filepath = tmpfile
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

@@ -35,12 +35,12 @@ TRANSFORMATION_CHOICES = {
{'name': 'width', 'label': _(u'width'), 'required': True},
{'name': 'height', 'label': _(u'height'), 'required': False},
]
},
},
TRANSFORMATION_ZOOM: {
'label': _(u'Zoom'),
'description': _(u'Zoom by n percent.'),
'arguments': [
{'name': 'percent', 'label': _(u'percent'), 'required': True}
]
},
},
}

View File

@@ -2,8 +2,8 @@ import os
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
#http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python
def copyfile(source, dest, buffer_size=1024 * 1024):
"""
@@ -36,7 +36,7 @@ def _lazy_load(fn):
return _cached[0]
return _decorated
@_lazy_load
def load_backend():
from converter.conf.settings import GRAPHICS_BACKEND as backend_name
@@ -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

@@ -44,7 +44,7 @@ def index_instance_list(request, index_id=None):
request,
title=title,
object_list=index_instance_list,
extra_context = {
extra_context={
'object': index_instance
}
)
@@ -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
@@ -168,7 +165,7 @@ class Document(models.Model):
def update_page_count(self, save=True):
handle, filepath = tempfile.mkstemp()
# Just need the filepath, close the file description
os.close(handle)
os.close(handle)
self.save_to_file(filepath)
try:
@@ -236,7 +233,7 @@ class Document(models.Model):
)
page_transformation.save()
def get_cached_image_name(self, page):
document_page = self.documentpage_set.get(page_number=page)
transformations, warnings = document_page.get_transformation_list()

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
@@ -388,13 +387,13 @@ def document_page_transformation_edit(request, document_page_transformation_id):
'navigation_object_list': [
{'object': 'page'},
{'object': 'transformation', 'name': _(u'transformation')}
],
],
'title': _(u'Edit transformation "%(transformation)s" for: %(document_page)s') % {
'transformation': document_page_transformation.get_transformation_display(),
'document_page': document_page_transformation.document_page},
'web_theme_hide_menus': True,
}, context_instance=RequestContext(request))
def document_page_transformation_delete(request, document_page_transformation_id):
check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
@@ -417,7 +416,7 @@ def document_page_transformation_delete(request, document_page_transformation_id
'navigation_object_list': [
{'object': 'page'},
{'object': 'transformation', 'name': _(u'transformation')}
],
],
'title': _(u'Are you sure you wish to delete transformation "%(transformation)s" for: %(document_page)s') % {
'transformation': document_page_transformation.get_transformation_display(),
'document_page': document_page_transformation.document_page},
@@ -865,7 +864,7 @@ def document_type_document_list(request, document_type_id):
extra_context={
'object_name': _(u'document type'),
'navigation_object_name': 'document_type',
'document_type': document_type,
'document_type': document_type,
}
)
@@ -926,11 +925,11 @@ def document_type_delete(request, document_type_id):
'delete_view': True,
'previous': previous,
'next': next,
'object_name': _(u'document type'),
'navigation_object_name': 'document_type',
'document_type': document_type,
'title': _(u'Are you sure you wish to delete the document type: %s?') % document_type,
'message': _(u'The document type of all documents using this document type will be set to none.'),
'form_icon': u'layout_delete.png',
@@ -1018,7 +1017,7 @@ def document_type_filename_edit(request, document_type_filename_id):
'navigation_object_list': [
{'object': 'document_type', 'name': _(u'document type')},
{'object': 'filename', 'name': _(u'document type filename')}
],
],
},
context_instance=RequestContext(request))
@@ -1052,7 +1051,7 @@ def document_type_filename_delete(request, document_type_filename_id):
'navigation_object_list': [
{'object': 'document_type', 'name': _(u'document type')},
{'object': 'filename', 'name': _(u'document type filename')}
],
],
'title': _(u'Are you sure you wish to delete the filename: %(filename)s, from document type "%(document_type)s"?') % {
'document_type': document_type_filename.document_type, 'filename': document_type_filename
},

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)
@@ -202,7 +202,7 @@ def folder_add_document(request, document_id):
return HttpResponseRedirect(next)
else:
form = AddDocumentForm(user=request.user)
return render_to_response('generic_form.html', {
'title': _(u'add document "%s" to a folder') % document,
'form': form,
@@ -210,12 +210,12 @@ def folder_add_document(request, document_id):
'next': next,
},
context_instance=RequestContext(request))
def document_folder_list(request, document_id):
check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
document = get_object_or_404(Document, pk=document_id)
return folder_list(
request,
queryset=Folder.objects.filter(user=request.user).filter(folderdocument__document=document),
@@ -224,7 +224,7 @@ def document_folder_list(request, document_id):
'object': document,
}
)
def folder_document_remove(request, folder_id, document_id=None, document_id_list=None):
post_action_redirect = None

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

@@ -61,7 +61,7 @@ setup_document_type_metadata = {'text': _(u'default metadata'), 'view': 'setup_d
#register_links(Document, [metadata_add, metadata_edit, metadata_remove])
register_links(['metadata_add', 'metadata_edit', 'metadata_remove', 'metadata_view'], [metadata_add, metadata_edit, metadata_remove], menu_name='sidebar')
register_links(Document, [metadata_view], menu_name='form_header')#, metadata_edit, metadata_remove])
register_links(Document, [metadata_view], menu_name='form_header') #, metadata_edit, metadata_remove])
register_multi_item_links(['document_find_duplicates', 'folder_view', 'index_instance_list', 'document_type_document_list', 'search', 'results', 'document_group_view', 'document_list', 'document_list_recent'], [metadata_multiple_add, metadata_multiple_edit, metadata_multiple_remove])
register_links(MetadataType, [setup_metadata_type_edit, setup_metadata_type_delete])

View File

@@ -17,29 +17,29 @@ UNKNWON_TYPE_FILE_NAME = 'unknown.png'
ERROR_FILE_NAME = 'error.png'
mimetype_icons = {
'application/pdf' : 'file_extension_pdf.png',
'application/zip' : 'file_extension_zip.png',
'application/ogg' : 'file_extension_ogg.png',
'application/postscript' : 'file_extension_ps.png',
'application/x-gzip' : 'file_extension_gz.png',
'application/x-rar-compressed' : 'file_extension_rar.png',
'application/x-troff-msvideo' : 'file_extension_avi.png',
'application/acad' : 'file_extension_dwg.png',
'application/octet-stream' : 'file_extension_exe.png',
'application/pdf': 'file_extension_pdf.png',
'application/zip': 'file_extension_zip.png',
'application/ogg': 'file_extension_ogg.png',
'application/postscript': 'file_extension_ps.png',
'application/x-gzip': 'file_extension_gz.png',
'application/x-rar-compressed': 'file_extension_rar.png',
'application/x-troff-msvideo': 'file_extension_avi.png',
'application/acad': 'file_extension_dwg.png',
'application/octet-stream': 'file_extension_exe.png',
'application/vnd.oasis.opendocument.text': 'ODF_textdocument_32x32.png',
'application/vnd.oasis.opendocument.spreadsheet': 'ODF_spreadsheet_32x32.png',
'application/vnd.oasis.opendocument.presentation': 'ODF_presentation_32x32.png',
'application/vnd.oasis.opendocument.graphics': 'ODF_drawing_32x32.png',
'application/vnd.ms-excel': 'file_extension_xls.png',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'file_extension_xls.png',
'application/vnd.ms-excel': 'file_extension_xls.png',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'file_extension_xls.png',
'application/msword': 'file_extension_doc.png',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'file_extension_doc.png',
'application/mspowerpoint': 'file_extension_pps.png',
'application/vnd.ms-powerpoint': 'file_extension_pps.png',
'application/wav' : 'file_extension_wav.png',
'application/x-wav' : 'file_extension_wav.png',
'application/vnd.oasis.opendocument.text' : 'ODF_textdocument_32x32.png',
'application/wav': 'file_extension_wav.png',
'application/x-wav': 'file_extension_wav.png',
'application/vnd.oasis.opendocument.text': 'ODF_textdocument_32x32.png',
'image/jpeg' : 'file_extension_jpeg.png',
'image/png' : 'file_extension_png.png',
'image/x-png' : 'file_extension_png.png',
@@ -49,7 +49,7 @@ mimetype_icons = {
'image/gif' : 'file_extension_gif.png',
'image/vnd.dwg' : 'file_extension_dwg.png',
'image/x-dwg' : 'file_extension_dwg.png',
'audio/mpeg' : 'file_extension_mp3.png',
'audio/mid' : 'file_extension_mid.png',
'audio/x-wav' : 'file_extension_wav.png',
@@ -63,7 +63,7 @@ mimetype_icons = {
'video/quicktime' : 'file_extension_mov.png',
'video/x-ms-asf' : 'file_extension_asf.png',
'video/x-ms-wmv' : 'file_extension_wmv.png',
'text/html' : 'file_extension_html.png',
'text/plain' : 'file_extension_txt.png',
}

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

@@ -11,7 +11,7 @@ class CompressedFile(object):
def __init__(self, file_object):
self.file_object = file_object
def children(self):
def children(self):
try:
# Try for a ZIP file
zfobj = zipfile.ZipFile(self.file_object)
@@ -19,6 +19,6 @@ class CompressedFile(object):
return (SimpleUploadedFile(name=filename, content=zfobj.read(filename)) for filename in filenames)
except zipfile.BadZipfile:
raise NotACompressedFile
#def close(self):
# self.file_object.close()

View File

@@ -56,34 +56,34 @@ class WebFormForm(DocumentForm):
label=_(u'Expand compressed files'), required=False,
help_text=ugettext(u'Upload a compressed file\'s contained files as individual documents')
)
def clean_file(self):
data = self.cleaned_data['file']
validate_whitelist_blacklist(data.name, self.source.whitelist.split(','), self.source.blacklist.split(','))
return data
return data
class WebFormSetupForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(WebFormSetupForm, self).__init__(*args, **kwargs)
super(WebFormSetupForm, self).__init__(*args, **kwargs)
self.fields['icon'].widget = FamFamRadioSelect(
attrs=self.fields['icon'].widget.attrs,
choices=self.fields['icon'].widget.choices,
)
class Meta:
model = WebForm
class StagingFolderSetupForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(StagingFolderSetupForm, self).__init__(*args, **kwargs)
super(StagingFolderSetupForm, self).__init__(*args, **kwargs)
self.fields['icon'].widget = FamFamRadioSelect(
attrs=self.fields['icon'].widget.attrs,
choices=self.fields['icon'].widget.choices,
)
class Meta:
model = StagingFolder
@@ -91,7 +91,7 @@ class StagingFolderSetupForm(forms.ModelForm):
class WatchFolderSetupForm(forms.ModelForm):
class Meta:
model = WatchFolder
class SourceTransformationForm(forms.ModelForm):
class Meta:

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

@@ -5,9 +5,11 @@ 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 """
def accept_item(value, whitelist, blacklist, default_accept=True):
"""
return true if this item is either whitelisted or
not blacklisted
"""
if not whitelist:
whitelist = []
@@ -18,9 +20,9 @@ def accept_item(value, whitelist, blacklist, default_accept=True):
for reject, item_list in ([False, whitelist], [True, blacklist]):
#print 'item_list: %s' % item_list
#print 'reject: %s' % reject
for okpattern in item_list:
for okpattern in item_list:
#print 'okpattern: %s' % okpattern
if re.findall(okpattern.replace('*','\S+'), value, re.I):
if re.findall(okpattern.replace('*', '\S+'), value, re.I):
# match!
#print 'MATCH'
if reject:

View File

@@ -29,7 +29,7 @@ from sources.forms import SourceTransformationForm, SourceTransformationForm_cre
from sources import PERMISSION_SOURCES_SETUP_VIEW, \
PERMISSION_SOURCES_SETUP_EDIT, PERMISSION_SOURCES_SETUP_DELETE, \
PERMISSION_SOURCES_SETUP_CREATE
def return_function(obj):
return lambda context: context['source'].source_type == obj.source_type and context['source'].pk == obj.pk
@@ -59,13 +59,13 @@ def get_active_tab_links():
'keep_query': True,
'conditional_highlight': return_function(staging_folder),
})
return {
'tab_links': tab_links,
SOURCE_CHOICE_WEB_FORM: web_forms,
SOURCE_CHOICE_STAGING: staging_folders
}
def upload_interactive(request, source_type=None, source_id=None):
check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
@@ -140,7 +140,7 @@ def upload_interactive(request, source_type=None, source_id=None):
return HttpResponseRedirect(request.get_full_path())
else:
form = WebFormForm(
show_expand=(web_form.uncompress==SOURCE_UNCOMPRESS_CHOICE_ASK),
show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
document_type=document_type,
source=web_form
)
@@ -159,7 +159,7 @@ def upload_interactive(request, source_type=None, source_id=None):
if request.method == 'POST':
form = StagingDocumentForm(request.POST, request.FILES,
cls=StagingFile, document_type=document_type,
show_expand=(staging_folder.uncompress==SOURCE_UNCOMPRESS_CHOICE_ASK),
show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
source=staging_folder
)
if form.is_valid():
@@ -171,14 +171,14 @@ def upload_interactive(request, source_type=None, source_id=None):
if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
expand = True
else:
expand = False
expand = False
new_filename = get_form_filename(form)
staging_folder.upload_file(staging_file.upload(),
new_filename, document_type=document_type,
expand=expand,
metadata_dict_list=decode_metadata_from_url(request.GET),
user=request.user
)
)
messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename)
if staging_folder.delete_after_upload:
@@ -191,8 +191,8 @@ def upload_interactive(request, source_type=None, source_id=None):
return HttpResponseRedirect(request.get_full_path())
else:
form = StagingDocumentForm(cls=StagingFile,
document_type=document_type,
show_expand=(staging_folder.uncompress==SOURCE_UNCOMPRESS_CHOICE_ASK),
document_type=document_type,
show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK),
source=staging_folder
)
try:
@@ -217,7 +217,7 @@ def upload_interactive(request, source_type=None, source_id=None):
'hide_link': True,
}
},
]
]
context.update({
'document_type_id': document_type_id,
@@ -234,7 +234,7 @@ def upload_interactive(request, source_type=None, source_id=None):
'temporary_navigation_links': {'form_header': {'upload_interactive': {'links': results['tab_links']}}},
})
return render_to_response('generic_form.html', context,
context_instance=RequestContext(request))
context_instance=RequestContext(request))
def get_form_filename(form):
@@ -246,16 +246,16 @@ def get_form_filename(form):
if form and 'document_type_available_filenames' in form.cleaned_data:
if form.cleaned_data['document_type_available_filenames']:
return form.cleaned_data['document_type_available_filenames'].filename
return filename
def staging_file_preview(request, source_type, source_id, staging_file_id):
check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
staging_folder = get_object_or_404(StagingFolder, pk=source_id)
StagingFile = create_staging_file_class(request, staging_folder.folder_path)
transformations, errors = SourceTransformation.transformations.get_for_object_as_list(staging_folder)
output_file = StagingFile.get(staging_file_id).get_image(
size=staging_folder.get_preview_size(),
transformations=transformations
@@ -274,7 +274,7 @@ def staging_file_thumbnail(request, source_id, staging_file_id):
staging_folder = get_object_or_404(StagingFolder, pk=source_id)
StagingFile = create_staging_file_class(request, staging_folder.folder_path, source=staging_folder)
transformations, errors = SourceTransformation.transformations.get_for_object_as_list(staging_folder)
output_file = StagingFile.get(staging_file_id).get_image(
size=THUMBNAIL_SIZE,
transformations=transformations
@@ -291,7 +291,7 @@ def staging_file_thumbnail(request, source_id, staging_file_id):
def staging_file_delete(request, source_type, source_id, staging_file_id):
check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
staging_folder = get_object_or_404(StagingFolder, pk=source_id)
StagingFile = create_staging_file_class(request, staging_folder.folder_path)
StagingFile = create_staging_file_class(request, staging_folder.folder_path)
staging_file = StagingFile.get(staging_file_id)
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
@@ -299,7 +299,7 @@ def staging_file_delete(request, source_type, source_id, staging_file_id):
if request.method == 'POST':
try:
transformations, errors=SourceTransformation.transformations.get_for_object_as_list(staging_folder)
transformations, errors = SourceTransformation.transformations.get_for_object_as_list(staging_folder)
staging_file.delete(
preview_size=staging_folder.get_preview_size(),
transformations=transformations
@@ -310,7 +310,7 @@ def staging_file_delete(request, source_type, source_id, staging_file_id):
return HttpResponseRedirect(next)
results = get_active_tab_links()
return render_to_response('generic_confirm.html', {
'source': staging_folder,
'delete_view': True,
@@ -324,14 +324,14 @@ def staging_file_delete(request, source_type, source_id, staging_file_id):
def setup_source_list(request, source_type):
check_permissions(request.user, [PERMISSION_SOURCES_SETUP_VIEW])
if source_type == SOURCE_CHOICE_WEB_FORM:
cls = WebForm
elif source_type == SOURCE_CHOICE_STAGING:
cls = StagingFolder
elif source_type == SOURCE_CHOICE_WATCH:
cls = WatchFolder
context = {
'object_list': cls.objects.all(),
'title': cls.class_fullname_plural(),

View File

@@ -16,7 +16,7 @@ class FamFamRadioFieldRenderer(forms.widgets.RadioFieldRenderer):
else:
famfam_template = u'<span class="famfam active famfam-cross" style="vertical-align: bottom;"></span>'
results.append(u'<li class="undecorated_list">%s%s</li>' % (famfam_template, force_unicode(w)))
results.append(u'\n</ul>')
return mark_safe(u'\n'.join(results))

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):