mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 19:17:13 -05:00 
			
		
		
		
	Merge branch 'dev'
This commit is contained in:
		
						commit
						8371c2399f
					
				@ -43,14 +43,12 @@ def select_action(modeladmin, request, queryset, title, action, modelclass, succ
 | 
			
		||||
        media=modeladmin.media,
 | 
			
		||||
        action=action,
 | 
			
		||||
        objects=modelclass.objects.all(),
 | 
			
		||||
        itemname=model_ngettext(modelclass,1)
 | 
			
		||||
        itemname=model_ngettext(modelclass, 1)
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    request.current_app = modeladmin.admin_site.name
 | 
			
		||||
 | 
			
		||||
    return TemplateResponse(request,
 | 
			
		||||
        "admin/%s/%s/select_object.html" % (app_label, opts.model_name)
 | 
			
		||||
    , context)
 | 
			
		||||
    return TemplateResponse(request, "admin/%s/%s/select_object.html" % (app_label, opts.model_name), context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def simple_action(modeladmin, request, queryset, success_message="", document_action=None, queryset_action=None):
 | 
			
		||||
@ -70,6 +68,7 @@ def simple_action(modeladmin, request, queryset, success_message="", document_ac
 | 
			
		||||
            "count": n, "items": model_ngettext(modeladmin.opts, n)
 | 
			
		||||
        }, messages.SUCCESS)
 | 
			
		||||
 | 
			
		||||
    # Return None to display the change list page again.
 | 
			
		||||
    return None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -99,7 +98,7 @@ def set_correspondent_on_selected(modeladmin, request, queryset):
 | 
			
		||||
                         action="set_correspondent_on_selected",
 | 
			
		||||
                         modelclass=Correspondent,
 | 
			
		||||
                         success_message="Successfully set correspondent %(selected_object)s on %(count)d %(items)s.",
 | 
			
		||||
                         queryset_action=lambda queryset, correspondent: queryset.update(correspondent=correspondent))
 | 
			
		||||
                         queryset_action=lambda qs, correspondent: qs.update(correspondent=correspondent))
 | 
			
		||||
set_correspondent_on_selected.short_description = "Set correspondent on selected documents"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -116,7 +115,7 @@ def set_document_type_on_selected(modeladmin, request, queryset):
 | 
			
		||||
                         action="set_document_type_on_selected",
 | 
			
		||||
                         modelclass=DocumentType,
 | 
			
		||||
                         success_message="Successfully set document type %(selected_object)s on %(count)d %(items)s.",
 | 
			
		||||
                         queryset_action=lambda queryset, document_type: queryset.update(document_type=document_type))
 | 
			
		||||
                         queryset_action=lambda qs, document_type: qs.update(document_type=document_type))
 | 
			
		||||
set_document_type_on_selected.short_description = "Set document type on selected documents"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -94,9 +94,10 @@ class RecentCorrespondentFilter(admin.RelatedFieldListFilter):
 | 
			
		||||
 | 
			
		||||
    def field_choices(self, field, request, model_admin):
 | 
			
		||||
        lookups = []
 | 
			
		||||
        if settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS and settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS > 0:
 | 
			
		||||
            date_limit = datetime.now() - timedelta(days=365*settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS)
 | 
			
		||||
        for c in Correspondent.objects.filter(documents__created__gte = date_limit).distinct():
 | 
			
		||||
            lookups.append( (c.id, c.name) )
 | 
			
		||||
            for c in Correspondent.objects.filter(documents__created__gte=date_limit).distinct():
 | 
			
		||||
                lookups.append((c.id, c.name))
 | 
			
		||||
        return lookups
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -153,6 +154,7 @@ class DocumentTypeAdmin(CommonAdmin):
 | 
			
		||||
        return obj.document_count
 | 
			
		||||
    document_count.admin_order_field = "document_count"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DocumentAdmin(CommonAdmin):
 | 
			
		||||
 | 
			
		||||
    class Media:
 | 
			
		||||
@ -199,10 +201,10 @@ class DocumentAdmin(CommonAdmin):
 | 
			
		||||
        extra_context['download_url'] = doc.download_url
 | 
			
		||||
        extra_context['file_type'] = doc.file_type
 | 
			
		||||
        if self.document_queue and object_id and int(object_id) in self.document_queue:
 | 
			
		||||
            #There is a queue of documents
 | 
			
		||||
            # There is a queue of documents
 | 
			
		||||
            current_index = self.document_queue.index(int(object_id))
 | 
			
		||||
            if current_index < len(self.document_queue) - 1:
 | 
			
		||||
                #... and there are still documents in the queue
 | 
			
		||||
                # ... and there are still documents in the queue
 | 
			
		||||
                extra_context['next_object'] = self.document_queue[current_index + 1]
 | 
			
		||||
        return super(DocumentAdmin, self).change_view(
 | 
			
		||||
            request, object_id, form_url, extra_context=extra_context,
 | 
			
		||||
 | 
			
		||||
@ -127,7 +127,7 @@ class DocumentClassifier(object):
 | 
			
		||||
    def classify_document(self, document, classify_correspondent=False, classify_document_type=False, classify_tags=False, replace_tags=False):
 | 
			
		||||
        X = self.data_vectorizer.transform([preprocess_content(document.content)])
 | 
			
		||||
 | 
			
		||||
        update_fields=()
 | 
			
		||||
        update_fields = ()
 | 
			
		||||
 | 
			
		||||
        if classify_correspondent and self.correspondent_classifier is not None:
 | 
			
		||||
            y_correspondent = self.correspondent_classifier.predict(X)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								src/documents/templates/admin/documents/document/change_form.html
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										7
									
								
								src/documents/templates/admin/documents/document/change_form.html
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -4,7 +4,7 @@
 | 
			
		||||
 | 
			
		||||
{{ block.super }}
 | 
			
		||||
 | 
			
		||||
{% if file_type in "pdf jpg png" %}
 | 
			
		||||
{% if file_type in "asd" %}
 | 
			
		||||
 | 
			
		||||
	<div id="change_form_twocolumn_parent">
 | 
			
		||||
		<div id="change_form_form_parent"></div>
 | 
			
		||||
@ -23,7 +23,9 @@
 | 
			
		||||
		django.jQuery("#content-main").append(django.jQuery("#change_form_twocolumn_parent"));
 | 
			
		||||
	</script>
 | 
			
		||||
 | 
			
		||||
	{% if next_object %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% if next_object %}
 | 
			
		||||
	<script type="text/javascript">//<![CDATA[
 | 
			
		||||
		(function($){
 | 
			
		||||
			$('<input type="submit" value="Save and edit next" name="_saveandeditnext" />')
 | 
			
		||||
@ -32,7 +34,6 @@
 | 
			
		||||
			.prependTo('div.submit-row');
 | 
			
		||||
		})(django.jQuery);
 | 
			
		||||
	//]]></script>
 | 
			
		||||
	{% endif %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
{% endblock content %}
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,7 @@
 | 
			
		||||
        <input type="hidden" name="action" value="{{action}}"/>
 | 
			
		||||
        <input type="hidden" name="post" value="yes"/>
 | 
			
		||||
        <p>
 | 
			
		||||
            <input type="submit" value="{% trans " Confirm" %}" />
 | 
			
		||||
            <input type="submit" value="{% trans "Confirm" %}" />
 | 
			
		||||
            <a href="#" class="button cancel-link">{% trans "Go back" %}</a>
 | 
			
		||||
        </p>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1
									
								
								src/documents/templates/admin/documents/document/viewers/viewer_image.html
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										1
									
								
								src/documents/templates/admin/documents/document/viewers/viewer_image.html
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -1,2 +1 @@
 | 
			
		||||
<img src="{{download_url}}" style="max-width: 100%">
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										69
									
								
								src/documents/templates/admin/documents/document/viewers/viewer_pdf.html
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							
							
						
						
									
										69
									
								
								src/documents/templates/admin/documents/document/viewers/viewer_pdf.html
									
									
									
									
									
										
										
										Executable file → Normal file
									
								
							@ -11,12 +11,13 @@
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<div style="width: 100%; overflow: auto;">
 | 
			
		||||
<canvas id="the-canvas"></canvas>
 | 
			
		||||
    </div>
 | 
			
		||||
    <canvas id="the-canvas"></canvas>
 | 
			
		||||
</div>
 | 
			
		||||
<script type="text/javascript" src="{% static 'documents/js/pdf.js' %}"></script>
 | 
			
		||||
<script type="text/javascript" src="{% static 'documents/js/pdf.worker.js' %}"></script>
 | 
			
		||||
	{# Load and display PDF document#}
 | 
			
		||||
	<script>
 | 
			
		||||
 | 
			
		||||
{# Load and display PDF document#}
 | 
			
		||||
<script>
 | 
			
		||||
var pdfjsLib = window['pdfjs-dist/build/pdf'];
 | 
			
		||||
 | 
			
		||||
var pdfDoc = null,
 | 
			
		||||
@ -31,7 +32,7 @@ var pdfDoc = null,
 | 
			
		||||
 * Get page info from document, resize canvas accordingly, and render page.
 | 
			
		||||
 * @param num Page number.
 | 
			
		||||
 */
 | 
			
		||||
  function renderPage(num) {
 | 
			
		||||
function renderPage(num) {
 | 
			
		||||
    pageRendering = true;
 | 
			
		||||
    // Using promise to fetch the page
 | 
			
		||||
    pdfDoc.getPage(num).then(function(page) {
 | 
			
		||||
@ -56,64 +57,74 @@ var pdfDoc = null,
 | 
			
		||||
    });
 | 
			
		||||
    // Update page counters
 | 
			
		||||
    document.getElementById('page_num').textContent = num;
 | 
			
		||||
  }
 | 
			
		||||
  /**
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * If another page rendering in progress, waits until the rendering is
 | 
			
		||||
 * finised. Otherwise, executes rendering immediately.
 | 
			
		||||
 */
 | 
			
		||||
  function queueRenderPage(num) {
 | 
			
		||||
function queueRenderPage(num) {
 | 
			
		||||
    if (pageRendering) {
 | 
			
		||||
        pageNumPending = num;
 | 
			
		||||
    } else {
 | 
			
		||||
        renderPage(num);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  /**
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Displays previous page.
 | 
			
		||||
 */
 | 
			
		||||
  function onPrevPage() {
 | 
			
		||||
function onPrevPage() {
 | 
			
		||||
    if (pageNum <= 1) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    pageNum--;
 | 
			
		||||
    queueRenderPage(pageNum);
 | 
			
		||||
  }
 | 
			
		||||
  document.getElementById('prev').addEventListener('click', onPrevPage);
 | 
			
		||||
  /**
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
document.getElementById('prev').addEventListener('click', onPrevPage);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Displays next page.
 | 
			
		||||
 */
 | 
			
		||||
  function onNextPage() {
 | 
			
		||||
function onNextPage() {
 | 
			
		||||
    if (pageNum >= pdfDoc.numPages) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    pageNum++;
 | 
			
		||||
    queueRenderPage(pageNum);
 | 
			
		||||
  }
 | 
			
		||||
  document.getElementById('next').addEventListener('click', onNextPage);
 | 
			
		||||
  /**
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
document.getElementById('next').addEventListener('click', onNextPage);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Displays next page.
 | 
			
		||||
 */
 | 
			
		||||
  function onZoomIn() {
 | 
			
		||||
function onZoomIn() {
 | 
			
		||||
    scale *= 1.2;
 | 
			
		||||
    queueRenderPage(pageNum);
 | 
			
		||||
  }
 | 
			
		||||
  document.getElementById('zoomin').addEventListener('click', onZoomIn);
 | 
			
		||||
  /**
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
document.getElementById('zoomin').addEventListener('click', onZoomIn);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Displays next page.
 | 
			
		||||
 */
 | 
			
		||||
  function onZoomOut() {
 | 
			
		||||
function onZoomOut() {
 | 
			
		||||
    scale /= 1.2;
 | 
			
		||||
    queueRenderPage(pageNum);
 | 
			
		||||
  }
 | 
			
		||||
  document.getElementById('zoomout').addEventListener('click', onZoomOut);
 | 
			
		||||
  /**
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
document.getElementById('zoomout').addEventListener('click', onZoomOut);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Asynchronously downloads PDF.
 | 
			
		||||
 */
 | 
			
		||||
  pdfjsLib.getDocument("{{download_url}}").then(function (pdfDoc_) {
 | 
			
		||||
pdfjsLib.getDocument("{{download_url}}").then(function (pdfDoc_) {
 | 
			
		||||
    pdfDoc = pdfDoc_;
 | 
			
		||||
    document.getElementById('page_count').textContent = pdfDoc.numPages;
 | 
			
		||||
    // Initial/first page rendering
 | 
			
		||||
    renderPage(pageNum);
 | 
			
		||||
  });
 | 
			
		||||
	</script>
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -298,4 +298,8 @@ FY_END = os.getenv("PAPERLESS_FINANCIAL_YEAR_END")
 | 
			
		||||
# Specify the default date order (for autodetected dates)
 | 
			
		||||
DATE_ORDER = os.getenv("PAPERLESS_DATE_ORDER", "DMY")
 | 
			
		||||
 | 
			
		||||
PAPERLESS_RECENT_CORRESPONDENT_YEARS = int(os.getenv("PAPERLESS_RECENT_CORRESPONDENT_YEARS", 1))
 | 
			
		||||
# Specify for how many years a correspondent is considered recent. Recent
 | 
			
		||||
# correspondents will be shown in a separate "Recent correspondents" filter as
 | 
			
		||||
# well. Set to 0 to disable this filter.
 | 
			
		||||
PAPERLESS_RECENT_CORRESPONDENT_YEARS = int(os.getenv(
 | 
			
		||||
    "PAPERLESS_RECENT_CORRESPONDENT_YEARS", 0))
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user