Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>PDF</title>
- </head>
- <body>
- <div id="convertedPage" class="converted__page">
- <div class="logo">
- <img src="data:image/png;base64,{{img}}">
- </div>
- <div class="info">
- <div class="info__items">
- <div class="info__item-text">
- <p class="info__text">
- <p class="text info__date">Дата:{{inpObj["date"]}}</p>
- <p class="text info__id">ID:{{inpObj["id"]}}</p>
- <p class="text info__customer">Заказчик:{{inpObj["customer"]}}</p>
- <p class="text info__partner">Партнёр:{{inpObj["partner"]}}</p>
- <p class="text info__distributor">Дистрибьютор:{{inpObj["distributor"]}}</p>
- </p>
- </div>
- <div class="info__item-result">
- <p class="text info__date-result" id="date"></p>
- <p class="text info__id-result" id="ID"></p>
- <p class="text info__customer-result" id="customer"></p>
- <p class="text info__partner-result" id="partner"></p>
- <p class="text info__distributor-result" id="distributor"></p>
- </div>
- </div>
- </div>
- <div class="assessment">
- <h3 class="assessment_title">Бюджетная оценка</h3>
- <div class="assessment__text">
- <p class="assessment__text-item" id="action_time">{{inpObj["offer"]}}</p>
- <p class="assessment__text-item" id="shipping_time">{{inpObj["delivery"]}}</p>
- <p class="assessment__text-item" id="payment_conditions">{{inpObj["payment"]}}</p>
- <p class="assessment__text-item" id="warranty_conditions">{{inpObj["warranty"]}}</p>
- <p class="assessment__text-item" id="shipping_conditions">{{inpObj["shipping"]}}</p>
- <p class="assessment__text-item" id="correct">{{inpObj["correct"]}}</p>
- </div>
- </div>
- <div class="resume">
- <table class="main__table">
- <thead class="main__table-header">
- <tr class="main__table-tr">
- <th class="main__table-header-text">№</th>
- <th class="main__table-header-text">Наименование</th>
- <th class="main__table-header-text">Количество</th>
- <th class="main__table-header-text">Цена (РРЦ) <br> USD с НДС</th>
- <th class="main__table-header-text">Сумма (РРЦ) <br> USD с НДС</th>
- </tr>
- </thead>
- <tbody class="main__table-body">
- <tr>
- <td id="num">1</td>
- <td id="config_name">{{inpObj["server_name"]}}</td>
- <td id="config_quantity">1</td>
- <td id="price_pdf">{{inpObj["price"]}}</td>
- <td id="summ_pdf">{{inpObj["summary"]}}</td>
- </tr>
- <tr>
- <td></td>
- <td class="component-cell">
- <ul class="component-list">
- {% for obj in object %}
- {% if obj != None %}
- <li class="component-item">{{obj}}</li>
- {%endif%}
- {%endfor%}
- </ul>
- </td>
- <td class="quantity-cell">
- <ul class="quantity-list">
- {% for num in number%}
- {%if num != 0 %}
- <li class="quantity-item">{{num}}</li>
- {% endif %}
- {%endfor%}
- </ul>
- </td>
- <td></td>
- <td></td>
- </tr>
- <tr>
- </tbody>
- </table>
- </div>
- <style>
- .component-list {
- list-style-type: none;
- /* Убираем маркеры списка */
- padding: 0;
- /* Убираем внешние отступы */
- margin: 0;
- /* Убираем внутренние отступы */
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .quantity-item, .component-item {
- margin: 0;
- padding: 0;
- }
- /* Устанавливаем стиль для списка количества */
- .quantity-list {
- list-style-type: none;
- /* Убираем маркеры списка */
- padding: 0;
- /* Убираем внешние отступы */
- margin: 0;
- /* Убираем внутренние отступы */
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- }
- .component-cell,
- .quantity-cell {
- height: 100%;
- /* Занимаем всю доступную высоту ячейки */
- padding: 0;
- /* Убираем внутренние отступы */
- margin: 0;
- /* Убираем внешние отступы */
- }
- input:active,
- input:hover,
- input:focus {
- outline: none;
- }
- body {
- background-color: #fff;
- }
- .info,
- .logo,
- .assessment,
- .resume {
- padding: 0 50px;
- }
- .info__items {
- display: flex;
- }
- .info__item-input {}
- .info__item-text {
- margin-right: 3rem;
- }
- .assessment {
- text-align: left;
- }
- .table__inside-body-td-name {
- text-align: left !important;
- }
- table {
- width: 100%;
- border-collapse: collapse;
- /* border-spacing: 0 10px; Первое значение - горизонтальный отступ, второе - вертикальный */
- margin-bottom: 20px;
- font-size: 14px;
- }
- th,
- td {
- border: 2px solid #000;
- padding: 8px 2px;
- }
- th {
- background-color: #fff;
- text-align: center !important;
- }
- /* Указываем процентное значение ширины для каждой колонны */
- th:nth-child(1),
- td:nth-child(1) {
- width: 10%;
- text-align: center;
- /* Центрирование текста в первой колонне */
- }
- th:nth-child(2),
- td:nth-child(2) {
- width: 50%;
- margin-bottom: 10px;
- /* Отступ только после ячейки 2-1 */
- }
- th:nth-child(3),
- td:nth-child(3) {
- width: 10%;
- text-align: center;
- }
- th:nth-child(4),
- td:nth-child(4) {
- width: 15%;
- text-align: right;
- }
- th:nth-child(5),
- td:nth-child(5) {
- width: 15%;
- text-align: right;
- }
- </style>
- </div>
- </body>
- input:active,
- input:hover,
- input:focus {
- outline: none;
- }
- .info,
- .logo,
- .assessment,
- .resume {
- padding: 0 50px;
- }
- .info__items {
- display: flex;
- }
- .info__item-input {}
- .info__item-text {
- margin-right: 3rem;
- }
- .assessment {
- text-align: center;
- }
- .table__inside-body-td-name {
- text-align: left !important;
- }
- table {
- width: 100%;
- border-collapse: collapse;
- /* border-spacing: 0 10px; Первое значение - горизонтальный отступ, второе - вертикальный */
- margin-bottom: 20px;
- }
- th,
- td {
- border: 2px solid #000;
- padding: 8px 2px;
- }
- th {
- background-color: #fff;
- text-align: center !important;
- }
- /* Указываем процентное значение ширины для каждой колонны */
- th:nth-child(1),
- td:nth-child(1) {
- width: 10%;
- text-align: center;
- /* Центрирование текста в первой колонне */
- }
- th:nth-child(2),
- td:nth-child(2) {
- width: 50%;
- margin-bottom: 10px;
- /* Отступ только после ячейки 2-1 */
- }
- th:nth-child(3),
- td:nth-child(3) {
- width: 10%;
- text-align: center;
- }
- th:nth-child(4),
- td:nth-child(4) {
- width: 15%;
- text-align: right;
- }
- th:nth-child(5),
- td:nth-child(5) {
- width: 15%;
- text-align: right;
- }
- @app.route('/make_pdf', methods = ['POST'])
- @login_required
- def make_pdf():
- data = request.get_json()
- object,number = [], []
- env = Environment(loader=FileSystemLoader('.'))
- '''
- TODO: Пройти по объекту data и отфильтровать наполнение:
- в object пихать название, а в number его количество.
- (Тебе надо будет установить wkhtmltopdf(в консоли ссылка будет)
- и папку расположить на диске D как тут D:\\wkhtmltopdf\\bin\\wkhtmltopdf.exe)
- '''
- commodity_needed = ['cpu', 'ram', 'drives', 'gpus', 'fc_adapters', 'psu', 'transceiver', 'raid', 'bios',
- 'bmc', 'dss_software', 'cipf', 'wifiBluetoothAdapter', 'lte', 'stylus', 'operating_system',
- 'mouse', 'keyboard', 'network_ocp_controllers', 'network_adapters', 'cables', 'cabel',
- 'mobile_rack', ]
- cables = ['hdminisas', 'aoc', 'dac', 'patchcord', 'psu_cable']
- drives = ['sata', 'sas', 'm2', 'nvme']
- for i in data: # Писать тут
- if data[i] != None and i in commodity_needed and len(data[i]) > 0:
- name, quantity = [], []
- if i == 'drives':
- for j in data[i]:
- if j == 'on_backplane' or j == 'on_jbod':
- for z in data[i][j]:
- for u in z:
- if u in drives and len(z[u]) > 0:
- for y in z[u]:
- name.append(y['name'])
- quantity.append(y['quantity'])
- else:
- for j in data[i]['m2']:
- name.append(j['name'])
- quantity.append(j['quantity'])
- elif i == 'cables':
- for j in data[i]:
- for z in data[i][j]:
- name.append(z['name'])
- quantity.append(z['quantity'])
- else:
- if type(data[i]) is list:
- for j in data[i]:
- name.append(j['name'])
- quantity.append(j['quantity'])
- else:
- name.append(data[i]['name'])
- quantity.append(data[i]['quantity'])
- if len(name) > 0 and len(quantity) > 0:
- object = object + name
- number = number + quantity
- template = env.get_template("templates/html_to_pdf.html")
- pdf_template = template.render(inpObj=data["inpObj"], number=number, object=object, img=image_file_path_to_base64_string(r"/home/malixds/work/aquarius_flask/static/images/logo.jpg"))
- path = "/usr/bin/wkhtmltopdf"
- postfix = ''.join(random.choices(string.ascii_letters, k=3))
- filename = data["server_name"] + postfix
- for w in postfix:
- filename += w
- config = pdfkit.configuration(wkhtmltopdf=path)
- pdfkit.from_string(pdf_template, f"/tmp/{filename}.pdf", configuration=config)
- return {
- "path": f"/tmp/{filename}.pdf"
- }
Add Comment
Please, Sign In to add comment