diff --git a/BaseModels/functions.py b/BaseModels/functions.py index 2dd38bf..b726889 100644 --- a/BaseModels/functions.py +++ b/BaseModels/functions.py @@ -96,27 +96,27 @@ def sortByLength(inputStr): return len(inputStr) -def add_domain(request, url, add_lang=False): - domain = get_domain_by_request(request) - if add_lang: - cur_lang = get_cur_lang_by_request(request) - return '{0}/{1}/{2}'.format(domain, cur_lang, url) - else: - return '{0}{1}'.format(domain, url) - - -def get_domain_by_request(request): - from project_sets import domain - if request.query_params and 'domain' in request.query_params: - return request.query_params['domain'] - return domain - - -def get_cur_lang_by_request(request): - from project_sets import lang - if request.query_params and 'cur_lang' in request.query_params: - return request.query_params['cur_lang'] - return lang +# def add_domain(request, url, add_lang=False): +# domain = get_domain_by_request(request) +# if add_lang: +# cur_lang = get_cur_lang_by_request(request) +# return '{0}/{1}/{2}'.format(domain, cur_lang, url) +# else: +# return '{0}{1}'.format(domain, url) +# +# +# def get_domain_by_request(request): +# from pAerBim.project_sets import domain +# if request.query_params and 'domain' in request.query_params: +# return request.query_params['domain'] +# return domain +# +# +# def get_cur_lang_by_request(request): +# from project_sets import lang +# if request.query_params and 'cur_lang' in request.query_params: +# return request.query_params['cur_lang'] +# return lang def get_img_type_by_request(request): diff --git a/BaseModels/wkhtmltox/bin/libwkhtmltox.a b/BaseModels/wkhtmltox/bin/libwkhtmltox.a new file mode 100644 index 0000000..69fa1d0 Binary files /dev/null and b/BaseModels/wkhtmltox/bin/libwkhtmltox.a differ diff --git a/BaseModels/wkhtmltox/bin/wkhtmltoimage.exe b/BaseModels/wkhtmltox/bin/wkhtmltoimage.exe new file mode 100644 index 0000000..ddf2d20 Binary files /dev/null and b/BaseModels/wkhtmltox/bin/wkhtmltoimage.exe differ diff --git a/BaseModels/wkhtmltox/bin/wkhtmltopdf.exe b/BaseModels/wkhtmltox/bin/wkhtmltopdf.exe new file mode 100644 index 0000000..f2906cd Binary files /dev/null and b/BaseModels/wkhtmltox/bin/wkhtmltopdf.exe differ diff --git a/BaseModels/wkhtmltox/bin/wkhtmltox.dll b/BaseModels/wkhtmltox/bin/wkhtmltox.dll new file mode 100644 index 0000000..f453ff8 Binary files /dev/null and b/BaseModels/wkhtmltox/bin/wkhtmltox.dll differ diff --git a/BaseModels/wkhtmltox/include/wkhtmltox/dllbegin.inc b/BaseModels/wkhtmltox/include/wkhtmltox/dllbegin.inc new file mode 100644 index 0000000..4535efc --- /dev/null +++ b/BaseModels/wkhtmltox/include/wkhtmltox/dllbegin.inc @@ -0,0 +1,54 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*- + * vi:set ts=4 sts=4 sw=4 noet : + * + * Copyright 2010-2020 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 . + */ + +#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__*/ diff --git a/BaseModels/wkhtmltox/include/wkhtmltox/dllend.inc b/BaseModels/wkhtmltox/include/wkhtmltox/dllend.inc new file mode 100644 index 0000000..ae23f3b --- /dev/null +++ b/BaseModels/wkhtmltox/include/wkhtmltox/dllend.inc @@ -0,0 +1,30 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*- + * vi:set ts=4 sts=4 sw=4 noet : + * + * Copyright 2010-2020 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 . + */ + +#ifdef __WKHTMLTOPDF_DLLBEGIN__ + +#undef __WKHTMLTOPDF_DLLBEGIN__ +#undef DLL_PUBLIC +#undef DLL_LOCAL +#undef CAPI +#undef CALLTYPE + +#endif /*__WKHTMLTOPDF_DLLBEGIN__*/ diff --git a/BaseModels/wkhtmltox/include/wkhtmltox/image.h b/BaseModels/wkhtmltox/include/wkhtmltox/image.h new file mode 100644 index 0000000..6b1f910 --- /dev/null +++ b/BaseModels/wkhtmltox/include/wkhtmltox/image.h @@ -0,0 +1,76 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*- + * vi:set ts=4 sts=4 sw=4 noet : + * + * Copyright 2010-2020 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 . + */ + +#ifndef __IMAGE_H__ +#define __IMAGE_H__ + +#ifdef BUILDING_WKHTMLTOX +#include "dllbegin.inc" +#else +#include +#endif + +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 **); + +#ifdef BUILDING_WKHTMLTOX +#include "dllend.inc" +#else +#include +#endif + +#endif /*__IMAGE_H__*/ diff --git a/BaseModels/wkhtmltox/include/wkhtmltox/pdf.h b/BaseModels/wkhtmltox/include/wkhtmltox/pdf.h new file mode 100644 index 0000000..0ed2ad4 --- /dev/null +++ b/BaseModels/wkhtmltox/include/wkhtmltox/pdf.h @@ -0,0 +1,88 @@ +/* -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*- + * vi:set ts=4 sts=4 sw=4 noet : + * + * Copyright 2010-2020 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 . + */ + +#ifndef __PDF_H__ +#define __PDF_H__ + +#ifdef BUILDING_WKHTMLTOX +#include "dllbegin.inc" +#else +#include +#endif + +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 **); + +#ifdef BUILDING_WKHTMLTOX +#include "dllend.inc" +#else +#include +#endif + +#endif /*__PDF_H__*/ diff --git a/DocsApp/views.py b/DocsApp/views.py index 8d057ef..52ea1e5 100644 --- a/DocsApp/views.py +++ b/DocsApp/views.py @@ -1,4 +1,5 @@ import json +import os from django.http import HttpResponse, Http404, FileResponse, HttpResponseRedirect from django.template import loader, RequestContext @@ -10,7 +11,7 @@ from django.utils.translation import gettext_lazy as _ from django.urls import reverse from collections import OrderedDict from django.template.loader import render_to_string - +from urllib.parse import unquote def get_tree_arts(art, arts, sel_arts_ids): @@ -28,15 +29,7 @@ def get_tree_arts(art, arts, sel_arts_ids): return docs_tree -import os -def link_callback(uri, rel): - if settings.STATIC_URL and uri.startswith(settings.STATIC_URL): - path = os.path.join(settings.STATIC_ROOT, uri.replace(settings.STATIC_URL, "")) - elif settings.MEDIA_URL and uri.startswith(settings.MEDIA_URL): - path = os.path.join(settings.MEDIA_ROOT, uri.replace(settings.MEDIA_URL, "")) - else: - path = os.path.join(settings.STATIC_ROOT, uri) - return path + def _response_pdf(path): @@ -54,17 +47,40 @@ def _response_pdf(path): def pdf_render(request, template, context, file_name): from BaseModels.functions import url_translit + from GeneralApp.funcs_options import get_options_by_opt_types filename = url_translit(file_name) html = render_to_string(template, context, request) + + sets = get_options_by_opt_types(['domain'], only_vals=True, w_prefix=True) + if settings.DEBUG: + sets['domain'] = 'http://127.0.0.1:8019' + while 'src="/' in html: + html = html.replace('src="/', f'src="{sets["domain"]}/') + # html = unquote(html) + + 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)) + '{wkhtmltopdf} ' + # '--margin-top 20mm ' + # '--encoding windows-1250 ' + '--enable-local-file-access ' + '--load-error-handling ignore ' + '--enable-internal-links ' + '--keep-relative-links ' + '--print-media-type ' + '--encoding UTF-8 ' + # '--default-header ' + # '--minimum-font-size 20mm ' + '{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) diff --git a/GeneralApp/funcs_options.py b/GeneralApp/funcs_options.py index bf34d9d..4d05417 100644 --- a/GeneralApp/funcs_options.py +++ b/GeneralApp/funcs_options.py @@ -1,6 +1,6 @@ from .models import * -def get_options_by_opt_types(opt_types, only_vals=False): +def get_options_by_opt_types(opt_types, only_vals=False, w_prefix=False): if type(opt_types) == str: kwargs = {'opt_type': opt_types} elif type(opt_types) == dict: @@ -10,8 +10,11 @@ def get_options_by_opt_types(opt_types, only_vals=False): opts = Option.objects.filter(**kwargs) if opts and only_vals: - opts = opts.values('opt_type', 'value') - opts = {item['opt_type']: item['value'] for item in opts} + opts = opts.values('opt_type', 'value', 'prefix') + if w_prefix: + opts = {item['opt_type']: f"{item['prefix']}{item['value']}" for item in opts} + else: + opts = {item['opt_type']: item['value'] for item in opts} return opts def get_first_option_value_by_opt_type(opt_type): diff --git a/pAerBim/settings.py b/pAerBim/settings.py index 1c303ef..2052118 100644 --- a/pAerBim/settings.py +++ b/pAerBim/settings.py @@ -164,7 +164,9 @@ USE_TZ = False # https://docs.djangoproject.com/en/4.2/howto/static-files/ MEDIA_URL = '/media/' -MEDIA_ROOT = 'media/' +# MEDIA_ROOT = 'media/' +import os +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') STATIC_URL = '/static/' STATIC_ROOT = '/' diff --git a/templates/blocks/b_documentation_article.html b/templates/blocks/b_documentation_article.html index 6849a91..3f34622 100644 --- a/templates/blocks/b_documentation_article.html +++ b/templates/blocks/b_documentation_article.html @@ -5,6 +5,7 @@ +{# #} {% endif %} @@ -24,13 +25,13 @@ - + {% trans "Предыдущий" %} {% endif %} - + {% if next_article %} @@ -43,7 +44,7 @@ {% endif %} - + {% trans "Скачать в PDF" %} {% endif %} \ No newline at end of file