Add maintenace view to clear the document image cache
This commit is contained in:
@@ -85,6 +85,7 @@ document_clear_transformations = {'text': _(u'clear transformations'), 'view': '
|
||||
document_multiple_clear_transformations = {'text': _(u'clear transformations'), 'view': 'document_multiple_clear_transformations', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_print = {'text': _(u'print'), 'view': 'document_print', 'args': 'object.id', 'famfam': 'printer', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_history_view = {'text': _(u'history'), 'view': 'history_for_object', 'args': ['"documents"', '"document"', 'object.id'], 'famfam': 'book_go', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_clear_image_cache = {'text': _(u'Clear the document image cache'), 'view': 'document_clear_image_cache', 'famfam': 'camera_delete', 'permissions': [PERMISSION_DOCUMENT_TOOLS], 'description': _(u'Clear the graphics representations used to speed up the documents\' display and interactive transformations results.')}
|
||||
|
||||
document_page_transformation_list = {'text': _(u'page transformations'), 'class': 'no-parent-history', 'view': 'document_page_transformation_list', 'args': 'page.pk', 'famfam': 'pencil_go', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_create = {'text': _(u'create new transformation'), 'class': 'no-parent-history', 'view': 'document_page_transformation_create', 'args': 'page.pk', 'famfam': 'pencil_add', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
@@ -158,7 +159,7 @@ register_links(['document_page_transformation_edit', 'document_page_transformati
|
||||
|
||||
register_diagnostic('documents', _(u'Documents'), document_missing_list)
|
||||
|
||||
register_maintenance_links([document_find_all_duplicates, document_update_page_count], namespace='documents', title=_(u'documents'))
|
||||
register_maintenance_links([document_find_all_duplicates, document_update_page_count, document_clear_image_cache], namespace='documents', title=_(u'documents'))
|
||||
|
||||
#def document_exists(document):
|
||||
# try:
|
||||
|
||||
@@ -92,6 +92,13 @@ class Document(models.Model):
|
||||
object_id_field='object_pk'
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def clear_image_cache():
|
||||
for the_file in os.listdir(CACHE_PATH):
|
||||
file_path = os.path.join(CACHE_PATH, the_file)
|
||||
if os.path.isfile(file_path):
|
||||
os.unlink(file_path)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'document')
|
||||
verbose_name_plural = _(u'documents')
|
||||
|
||||
BIN
apps/documents/static/images/icons/camera_delete.png
Normal file
BIN
apps/documents/static/images/icons/camera_delete.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
@@ -37,6 +37,7 @@ urlpatterns = patterns('documents.views',
|
||||
url(r'^multiple/clear_transformations/$', 'document_multiple_clear_transformations', (), 'document_multiple_clear_transformations'),
|
||||
url(r'^duplicates/list/$', 'document_find_all_duplicates', (), 'document_find_all_duplicates'),
|
||||
url(r'^maintenance/update_page_count/$', 'document_update_page_count', (), 'document_update_page_count'),
|
||||
url(r'^maintenance/clear_image_cache/$', 'document_clear_image_cache', (), 'document_clear_image_cache'),
|
||||
|
||||
url(r'^page/(?P<document_page_id>\d+)/$', 'document_page_view', (), 'document_page_view'),
|
||||
url(r'^page/(?P<document_page_id>\d+)/text/$', 'document_page_text', (), 'document_page_text'),
|
||||
|
||||
@@ -1121,3 +1121,24 @@ def document_type_filename_create(request, document_type_id):
|
||||
'document_type': document_type,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def document_clear_image_cache(request):
|
||||
check_permissions(request.user, [PERMISSION_DOCUMENT_TOOLS])
|
||||
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))
|
||||
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
Document.clear_image_cache()
|
||||
messages.success(request, _(u'Document image cache cleared successfully'))
|
||||
except Exception, msg:
|
||||
messages.error(request, _(u'Error clearing document image cache; %s') % msg)
|
||||
|
||||
return HttpResponseRedirect(previous)
|
||||
|
||||
return render_to_response('generic_confirm.html', {
|
||||
'previous': previous,
|
||||
'title': _(u'Are you sure you wish to clear the document image cache?'),
|
||||
'form_icon': u'camera_delete.png',
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
Reference in New Issue
Block a user