0.5.13 pdf articles export

This commit is contained in:
SDE
2024-07-16 17:35:33 +03:00
parent b132b9e087
commit f11a3f0463
15 changed files with 416 additions and 54 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2010 wkhtmltopdf authors
*
* This file is part of wkhtmltopdf.
*
* wkhtmltopdf is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wkhtmltopdf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
*/
#ifndef __WKHTMLTOPDF_DLLBEGIN__
#define __WKHTMLTOPDF_DLLBEGIN__
#if defined _WIN32 || defined __CYGWIN__
#ifdef BUILDING_DLL
#define DLL_PUBLIC __declspec(dllexport)
#else
#define DLL_PUBLIC __declspec(dllimport)
#endif
#define DLL_LOCAL
#else
#if __GNUC__ >= 4
#define DLL_PUBLIC __attribute__ ((visibility("default")))
#define DLL_LOCAL __attribute__ ((visibility("hidden")))
#else
#define DLL_PUBLIC
#define DLL_LOCAL
#endif
#endif
#if defined _WIN32
#define CALLTYPE __stdcall
#else
#define CALLTYPE
#endif
#ifdef __cplusplus
#define CAPI(type) extern "C" DLL_PUBLIC type CALLTYPE
#else
#define CAPI(type) DLL_PUBLIC type CALLTYPE
#endif
#endif /*__WKHTMLTOPDF_DLLBEGIN__*/

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2010 wkhtmltopdf authors
*
* This file is part of wkhtmltopdf.
*
* wkhtmltopdf is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wkhtmltopdf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
*/
#ifdef __WKHTMLTOPDF_DLLBEGIN__
#undef __WKHTMLTOPDF_DLLBEGIN__
#undef DLL_PUBLIC
#undef DLL_LOCAL
#undef CAPI
#undef CALLTYPE
#endif /*__WKHTMLTOPDF_DLLBEGIN__*/

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2010 wkhtmltopdf authors
*
* This file is part of wkhtmltopdf.
*
* wkhtmltopdf is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wkhtmltopdf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
*/
#ifndef __IMAGE_H__
#define __IMAGE_H__
#include <wkhtmltox/dllbegin.inc>
struct wkhtmltoimage_global_settings;
typedef struct wkhtmltoimage_global_settings wkhtmltoimage_global_settings;
struct wkhtmltoimage_converter;
typedef struct wkhtmltoimage_converter wkhtmltoimage_converter;
typedef void (*wkhtmltoimage_str_callback)(wkhtmltoimage_converter * converter, const char * str);
typedef void (*wkhtmltoimage_int_callback)(wkhtmltoimage_converter * converter, const int val);
typedef void (*wkhtmltoimage_void_callback)(wkhtmltoimage_converter * converter);
CAPI(int) wkhtmltoimage_init(int use_graphics);
CAPI(int) wkhtmltoimage_deinit();
CAPI(int) wkhtmltoimage_extended_qt();
CAPI(const char *)wkhtmltoimage_version();
CAPI(wkhtmltoimage_global_settings *) wkhtmltoimage_create_global_settings();
CAPI(int) wkhtmltoimage_set_global_setting(wkhtmltoimage_global_settings * settings, const char * name, const char * value);
CAPI(int) wkhtmltoimage_get_global_setting(wkhtmltoimage_global_settings * settings, const char * name, char * value, int vs);
CAPI(wkhtmltoimage_converter *) wkhtmltoimage_create_converter(wkhtmltoimage_global_settings * settings, const char * data);
CAPI(void) wkhtmltoimage_destroy_converter(wkhtmltoimage_converter * converter);
CAPI(void) wkhtmltoimage_set_warning_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback cb);
CAPI(void) wkhtmltoimage_set_error_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_str_callback cb);
CAPI(void) wkhtmltoimage_set_phase_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_void_callback cb);
CAPI(void) wkhtmltoimage_set_progress_changed_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback cb);
CAPI(void) wkhtmltoimage_set_finished_callback(wkhtmltoimage_converter * converter, wkhtmltoimage_int_callback cb);
CAPI(int) wkhtmltoimage_convert(wkhtmltoimage_converter * converter);
/* CAPI(void) wkhtmltoimage_begin_conversion(wkhtmltoimage_converter * converter); */
/* CAPI(void) wkhtmltoimage_cancel(wkhtmltoimage_converter * converter); */
CAPI(int) wkhtmltoimage_current_phase(wkhtmltoimage_converter * converter);
CAPI(int) wkhtmltoimage_phase_count(wkhtmltoimage_converter * converter);
CAPI(const char *) wkhtmltoimage_phase_description(wkhtmltoimage_converter * converter, int phase);
CAPI(const char *) wkhtmltoimage_progress_string(wkhtmltoimage_converter * converter);
CAPI(int) wkhtmltoimage_http_error_code(wkhtmltoimage_converter * converter);
CAPI(long) wkhtmltoimage_get_output(wkhtmltoimage_converter * converter, const unsigned char **);
#include <wkhtmltox/dllend.inc>
#endif /*__IMAGE_H__*/

View File

@@ -0,0 +1,76 @@
/*
* Copyright 2010 wkhtmltopdf authors
*
* This file is part of wkhtmltopdf.
*
* wkhtmltopdf is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wkhtmltopdf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wkhtmltopdf. If not, see <http: *www.gnu.org/licenses/>.
*/
#ifndef __PDF_H__
#define __PDF_H__
#include <wkhtmltox/dllbegin.inc>
struct wkhtmltopdf_global_settings;
typedef struct wkhtmltopdf_global_settings wkhtmltopdf_global_settings;
struct wkhtmltopdf_object_settings;
typedef struct wkhtmltopdf_object_settings wkhtmltopdf_object_settings;
struct wkhtmltopdf_converter;
typedef struct wkhtmltopdf_converter wkhtmltopdf_converter;
typedef void (*wkhtmltopdf_str_callback)(wkhtmltopdf_converter * converter, const char * str);
typedef void (*wkhtmltopdf_int_callback)(wkhtmltopdf_converter * converter, const int val);
typedef void (*wkhtmltopdf_void_callback)(wkhtmltopdf_converter * converter);
CAPI(int) wkhtmltopdf_init(int use_graphics);
CAPI(int) wkhtmltopdf_deinit();
CAPI(int) wkhtmltopdf_extended_qt();
CAPI(const char *) wkhtmltopdf_version();
CAPI(wkhtmltopdf_global_settings *) wkhtmltopdf_create_global_settings();
CAPI(void) wkhtmltopdf_destroy_global_settings(wkhtmltopdf_global_settings *);
CAPI(wkhtmltopdf_object_settings *) wkhtmltopdf_create_object_settings();
CAPI(void) wkhtmltopdf_destroy_object_settings(wkhtmltopdf_object_settings *);
CAPI(int) wkhtmltopdf_set_global_setting(wkhtmltopdf_global_settings * settings, const char * name, const char * value);
CAPI(int) wkhtmltopdf_get_global_setting(wkhtmltopdf_global_settings * settings, const char * name, char * value, int vs);
CAPI(int) wkhtmltopdf_set_object_setting(wkhtmltopdf_object_settings * settings, const char * name, const char * value);
CAPI(int) wkhtmltopdf_get_object_setting(wkhtmltopdf_object_settings * settings, const char * name, char * value, int vs);
CAPI(wkhtmltopdf_converter *) wkhtmltopdf_create_converter(wkhtmltopdf_global_settings * settings);
CAPI(void) wkhtmltopdf_destroy_converter(wkhtmltopdf_converter * converter);
CAPI(void) wkhtmltopdf_set_warning_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback cb);
CAPI(void) wkhtmltopdf_set_error_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_str_callback cb);
CAPI(void) wkhtmltopdf_set_phase_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_void_callback cb);
CAPI(void) wkhtmltopdf_set_progress_changed_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback cb);
CAPI(void) wkhtmltopdf_set_finished_callback(wkhtmltopdf_converter * converter, wkhtmltopdf_int_callback cb);
/* CAPI(void) wkhtmltopdf_begin_conversion(wkhtmltopdf_converter * converter); */
/* CAPI(void) wkhtmltopdf_cancel(wkhtmltopdf_converter * converter); */
CAPI(int) wkhtmltopdf_convert(wkhtmltopdf_converter * converter);
CAPI(void) wkhtmltopdf_add_object(
wkhtmltopdf_converter * converter, wkhtmltopdf_object_settings * setting, const char * data);
CAPI(int) wkhtmltopdf_current_phase(wkhtmltopdf_converter * converter);
CAPI(int) wkhtmltopdf_phase_count(wkhtmltopdf_converter * converter);
CAPI(const char *) wkhtmltopdf_phase_description(wkhtmltopdf_converter * converter, int phase);
CAPI(const char *) wkhtmltopdf_progress_string(wkhtmltopdf_converter * converter);
CAPI(int) wkhtmltopdf_http_error_code(wkhtmltopdf_converter * converter);
CAPI(long) wkhtmltopdf_get_output(wkhtmltopdf_converter * converter, const unsigned char **);
#include <wkhtmltox/dllend.inc>
#endif /*__PDF_H__*/

Binary file not shown.

View File

@@ -9,6 +9,7 @@ from GeneralApp.funcs import get_inter_http_respose
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.urls import reverse from django.urls import reverse
from collections import OrderedDict from collections import OrderedDict
from django.template.loader import render_to_string
def get_tree_arts(art, arts, sel_arts_ids): def get_tree_arts(art, arts, sel_arts_ids):
@@ -27,22 +28,59 @@ def get_tree_arts(art, arts, sel_arts_ids):
return docs_tree return docs_tree
# def get_tree_arts(art, arts): import os
# def link_callback(uri, rel):
# docs_tree = OrderedDict() if settings.STATIC_URL and uri.startswith(settings.STATIC_URL):
# docs_tree.update({ path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, ""))
# art['name']: { elif settings.MEDIA_URL and uri.startswith(settings.MEDIA_URL):
# 'url': art['url'], path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, ""))
# 'id': art['id'], else:
# 'children': get_tree_arts(art, DocArt.objects.filter(parent=art)), path = os.path.join(settings.STATIC_ROOT, uri)
# } for art in arts.filter(parent=None) return path
# })
# return docs_tree
def _response_pdf(path):
filePDF = open(path, 'rb')
content = filePDF.read()
# content = str(content)
filePDF.close()
response = HttpResponse(content, content_type='application/pdf')
response['Content-Disposition'] = 'filename="{fn}"'.format(fn=os.path.basename(path))
return response
def pdf_render(request, template, context, file_name):
from BaseModels.functions import url_translit
filename = url_translit(file_name)
html = render_to_string(template, context, request)
f = open(f'{settings.PDF_FOLDER}/{filename}.html', 'w')
f.write(html)
f.close()
os.system(
u'{wkhtmltopdf} --load-error-handling ignore --default-header {pdf_folder}/{file_name}.html {pdf_folder}/{file_name}.pdf'.format(
wkhtmltopdf=settings.WKHTML_TO_PDF, pdf_folder=settings.PDF_FOLDER, file_name=filename))
path = settings.PDF_FOLDER + '/' + filename + '.pdf'
# os.system(u'{wkhtmltopdf} {print_folder}/order{filename}.html {print_folder}/order{filename}.pdf'.format(wkhtmltopdf=settings.WKHTML_TO_PDF, print_folder=settings.PRINT_FOLDER))
return _response_pdf(path)
def DocsView(request, version=None, art_url=None): def DocsView(request, version=None, art_url=None):
if art_url and version: if art_url and version:
generate_pdf = False
if request.GET and 'pdf' in request.GET and request.GET['pdf'] == 'true':
generate_pdf = True
kwargs = { kwargs = {
'enable': True, 'enable': True,
'url': art_url, 'url': art_url,
@@ -85,10 +123,19 @@ def DocsView(request, version=None, art_url=None):
'allow_versions': versions, 'allow_versions': versions,
'breadcrumbs': breadcrumbs, 'breadcrumbs': breadcrumbs,
'prev_article': art.get_prev_article(version=vers_obj), 'prev_article': art.get_prev_article(version=vers_obj),
'next_article': art.get_next_article(version=vers_obj) 'next_article': art.get_next_article(version=vers_obj),
'pdf_render': generate_pdf
} }
t = loader.get_template('pages/p_documentation.html')
return get_inter_http_respose(t, Dict, request) if not generate_pdf:
tpl = 'pages/p_documentation.html'
t = loader.get_template(tpl)
return get_inter_http_respose(t, Dict, request)
else:
tpl = 'blocks/b_documentation_article.html'
# tpl = 'pages/p_documentation.html'
return pdf_render(request, tpl, Dict, art.name)
except DocArt.DoesNotExist: except DocArt.DoesNotExist:
raise Http404 raise Http404

View File

@@ -1,8 +1,10 @@
from django import forms import copy
from django import forms
from django.contrib import admin
from sets.admin import * from sets.admin import *
from .models import * from .models import *
from django.contrib import admin
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
# from nested_inline.admin import NestedStackedInline, NestedTabularInline, NestedModelAdmin, NestedInline # from nested_inline.admin import NestedStackedInline, NestedTabularInline, NestedModelAdmin, NestedInline
from super_inlines.admin import SuperInlineModelAdmin, SuperModelAdmin from super_inlines.admin import SuperInlineModelAdmin, SuperModelAdmin
@@ -131,6 +133,77 @@ class Admin_StackedInline_Block(Admin_Trans_GenericBaseIconStackedInline, SuperI
class Admin_PageAddingBlocksTemplate(Admin_BaseIconModel):
from ServicesApp.admin import Admin_StackedInline_BlockPluginPresentation
from SlidesApp.admin import Admin_StackedInline_Slide
fieldsets = [
(None, {
'classes': ['wide'],
'fields': ('name',
# 'url',
# 'title',
# 'description', 'text',
# 'picture',
# 'order',
)
}),
# ('SEO', {
# 'classes': ['wide', 'collapse'],
# 'fields': (
# 'seo_title', 'seo_description', 'seo_keywords', 'seo_text',
# )
# }),
]
def get_list_display(self, request):
if request.user.is_superuser:
# self.list_display.append()
d_list = copy.copy(self.list_display)
d_list.append('name_plural')
return d_list
return self.list_display
def get_changelist_instance(self, request):
if request.user.is_superuser:
self.list_editable.append('name_plural')
return super(Admin_PageAddingBlocksTemplate, self).get_changelist_instance(request)
list_display = [
# 'image_thumb',
'id',
'name',
'enable',
# 'url',
# 'title',
# 'order',
'modifiedDT', 'createDT'
]
list_display_links = ['id', 'name']
list_editable = ['enable']
list_filter = ['modifiedDT', 'createDT']
search_fields = ['name']
# filter_horizontal = ['options']
inlines = [
Admin_StackedInline_Slide,
Admin_StackedInline_BlockPluginPresentation,
Admin_StackedInline_Block,
# AdminStacked_FAQitem,
]
def has_delete_permission(self, request, obj=None):
if request.user.is_superuser:
return True
if not obj or obj.name_plural in ['documentation', 'contacts']:
return False
admin.site.register(PageAddingBlocksTemplate, Admin_PageAddingBlocksTemplate)
class Admin_StaticPage(SuperModelAdmin, Admin_Trans_BaseModelViewPage): class Admin_StaticPage(SuperModelAdmin, Admin_Trans_BaseModelViewPage):

View File

@@ -12,6 +12,13 @@ from colorfield.fields import ColorField
from filebrowser.fields import FileBrowseField from filebrowser.fields import FileBrowseField
from filebrowser.base import FileObject from filebrowser.base import FileObject
class PageAddingBlocksTemplate(BaseModel):
class Meta:
verbose_name = _('Шаблон настройки дополнительных блоков на странице')
verbose_name_plural = _('Шаблоны настройки дополнительных блоков на странице')
class FileUnit(BaseModel): class FileUnit(BaseModel):
file = FileBrowseField(verbose_name=_('Файл'), max_length=250, directory="files/") file = FileBrowseField(verbose_name=_('Файл'), max_length=250, directory="files/")

View File

@@ -271,6 +271,9 @@ CKEDITOR_CONFIGS = {
} }
} }
PDF_FOLDER = 'media/pdf'
WKHTML_TO_PDF = 'BaseModels\wkhtmltopdf\{0}\wkhtmltopdf'.format(u'bin')
try: try:
import db_local_sets import db_local_sets

View File

@@ -1,37 +0,0 @@
{% load static %}
{% load i18n %}
<div class="content_part_tree_els">
{# <div class="name_article_tree">#}
{# #}
{# </div>#}
{# <div class="description_article_tree">#}
{# {{ cur_article.text }}#}
{# </div>#}
{{ cur_article.text|safe }}
<div class="controls_content_part_tree_els">
<div class="control_content_part_tree_el left">
{% if prev_article %}
<picture class="arrow_control_content_part_tree_el_picture">
<source srcset="{% static "images/arrow_control_part_tree_el.svg" %}">
<img class="arrow_control_content_part_tree_el_img" src="{% static "images/arrow_control_part_tree_el.svg" %}" alt="">
</picture>
<div class="txt_control_content_part_tree_el" data-url="{% url 'docs_art_page' cur_version.url prev_article.url %}" onclick="changeCurArticle(this)">
{% trans "Предыдущий" %}
</div>
{% endif %}
</div>
<div class="control_content_part_tree_el right">
{% if next_article %}
<div class="txt_control_content_part_tree_el" data-url="{% url 'docs_art_page' cur_version.url next_article.url %}" onclick="changeCurArticle(this)">
{% trans "Следующий" %}
</div>
<picture class="arrow_control_content_part_tree_el_picture">
<source srcset="{% static "images/arrow_control_part_tree_el.svg" %}">
<img class="arrow_control_content_part_tree_el_img" src="{% static "images/arrow_control_part_tree_el.svg" %}" alt="">
</picture>
{% endif %}
</div>
</div>
<a class="btn_download_in_pdf" href="">{% trans "Скачать в PDF" %}</a>
</div>

View File

@@ -0,0 +1,49 @@
{% load static %}
{% load i18n %}
{% if pdf_render %}
<HEAD>
<meta charset="windows-1251">
</HEAD>
{% endif %}
<div class="content_part_tree_els">
{# <div class="name_article_tree">#}
{# #}
{# </div>#}
{# <div class="description_article_tree">#}
{# {{ cur_article.text }}#}
{# </div>#}
{{ cur_article.text|safe }}
{% if not pdf_render %}
<div class="controls_content_part_tree_els">
<div class="control_content_part_tree_el left">
{% if prev_article %}
<picture class="arrow_control_content_part_tree_el_picture">
<source srcset="{% static "images/arrow_control_part_tree_el.svg" %}">
<img class="arrow_control_content_part_tree_el_img" src="{% static "images/arrow_control_part_tree_el.svg" %}" alt="">
</picture>
<div class="txt_control_content_part_tree_el" data-url="{% url 'docs_art_page' cur_version.url prev_article.url %}" onclick="changeCurArticle(this)">
{% trans "Предыдущий" %}
</div>
{% endif %}
</div>
<div class="control_content_part_tree_el right">
{% if next_article %}
<div class="txt_control_content_part_tree_el" data-url="{% url 'docs_art_page' cur_version.url next_article.url %}" onclick="changeCurArticle(this)">
{% trans "Следующий" %}
</div>
<picture class="arrow_control_content_part_tree_el_picture">
<source srcset="{% static "images/arrow_control_part_tree_el.svg" %}">
<img class="arrow_control_content_part_tree_el_img" src="{% static "images/arrow_control_part_tree_el.svg" %}" alt="">
</picture>
{% endif %}
</div>
</div>
<a class="btn_download_in_pdf" target="_blank" href="?pdf=true">{% trans "Скачать в PDF" %}</a>
{% endif %}
</div>

View File

@@ -117,7 +117,7 @@
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% include "blocks/b_Pdocumentation_article.html" %} {% include "blocks/b_documentation_article.html" %}
</div> </div>
</div> </div>
{% endblock %} {% endblock %}