2022-02-18 19:30:54 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -- coding:utf-8 --
|
|
|
|
|
# @Author: markushammered@gmail.com
|
|
|
|
|
# @Development Tool: PyCharm
|
2022-03-26 08:02:25 +08:00
|
|
|
# @Create Time: 2022/3/25
|
2022-02-18 19:35:46 +08:00
|
|
|
# @File Name: view.py
|
2022-02-18 19:30:54 +08:00
|
|
|
|
|
|
|
|
|
2022-03-26 08:02:25 +08:00
|
|
|
from ..db.db import SQLite as db
|
2022-03-26 08:03:39 +08:00
|
|
|
from flask import request
|
2022-02-18 19:30:54 +08:00
|
|
|
from flask import render_template
|
2022-03-26 08:02:25 +08:00
|
|
|
from typing import Tuple
|
2022-02-18 19:30:54 +08:00
|
|
|
|
|
|
|
|
|
2022-04-09 10:54:05 +08:00
|
|
|
def view(theme: str, length: int, name: str, count: str ) -> str or Tuple[bool, str]:
|
2022-02-18 19:30:54 +08:00
|
|
|
"""
|
|
|
|
|
渲染模板
|
2022-03-26 08:02:25 +08:00
|
|
|
:param theme:
|
2022-02-28 21:18:05 +08:00
|
|
|
:param length:
|
|
|
|
|
:param name:
|
|
|
|
|
:param count:
|
2022-02-18 19:30:54 +08:00
|
|
|
:return:
|
|
|
|
|
"""
|
2022-03-26 08:02:25 +08:00
|
|
|
datas = db().fetching_table(theme)
|
2022-02-18 19:30:54 +08:00
|
|
|
context = []
|
2022-02-28 21:18:05 +08:00
|
|
|
for i in count:
|
|
|
|
|
if i == '0':
|
|
|
|
|
context.append({'base64': datas[0]['base64'],
|
|
|
|
|
'width': datas[0]['width'],
|
|
|
|
|
'height': datas[0]['height']})
|
|
|
|
|
elif i == '1':
|
|
|
|
|
context.append({'base64': datas[1]['base64'],
|
|
|
|
|
'width': datas[1]['width'],
|
|
|
|
|
'height': datas[1]['height']})
|
|
|
|
|
elif i == '2':
|
|
|
|
|
context.append({'base64': datas[2]['base64'],
|
|
|
|
|
'width': datas[2]['width'],
|
|
|
|
|
'height': datas[2]['height']})
|
|
|
|
|
elif i == '3':
|
|
|
|
|
context.append({'base64': datas[3]['base64'],
|
|
|
|
|
'width': datas[3]['width'],
|
|
|
|
|
'height': datas[3]['height']})
|
|
|
|
|
elif i == '4':
|
|
|
|
|
context.append({'base64': datas[4]['base64'],
|
|
|
|
|
'width': datas[4]['width'],
|
|
|
|
|
'height': datas[4]['height']})
|
|
|
|
|
elif i == '5':
|
|
|
|
|
context.append({'base64': datas[5]['base64'],
|
|
|
|
|
'width': datas[5]['width'],
|
|
|
|
|
'height': datas[5]['height']})
|
|
|
|
|
elif i == '6':
|
|
|
|
|
context.append({'base64': datas[6]['base64'],
|
|
|
|
|
'width': datas[6]['width'],
|
|
|
|
|
'height': datas[6]['height']})
|
|
|
|
|
elif i == '7':
|
|
|
|
|
context.append({'base64': datas[7]['base64'],
|
|
|
|
|
'width': datas[7]['width'],
|
|
|
|
|
'height': datas[7]['height']})
|
|
|
|
|
elif i == '8':
|
|
|
|
|
context.append({'base64': datas[8]['base64'],
|
|
|
|
|
'width': datas[8]['width'],
|
|
|
|
|
'height': datas[8]['height']})
|
|
|
|
|
elif i == '9':
|
|
|
|
|
context.append({'base64': datas[9]['base64'],
|
|
|
|
|
'width': datas[9]['width'],
|
|
|
|
|
'height': datas[9]['height']})
|
2022-02-18 19:30:54 +08:00
|
|
|
|
|
|
|
|
for p, i in zip(context, range(0, length)):
|
2022-02-25 18:29:02 +08:00
|
|
|
p['position'] = i * p['width'] # 设置每张图片对应的位置
|
2022-02-18 19:30:54 +08:00
|
|
|
|
2022-02-28 21:18:05 +08:00
|
|
|
general_width = datas[0]['width'] * length # 计算出图片总长度
|
|
|
|
|
general_height = datas[0]['height'] # 总宽度
|
2022-02-18 19:30:54 +08:00
|
|
|
|
2022-02-28 21:18:05 +08:00
|
|
|
return render_template('view.html',
|
2022-03-26 08:02:25 +08:00
|
|
|
context=context,
|
|
|
|
|
title=name,
|
2022-03-26 08:03:39 +08:00
|
|
|
address=request.remote_addr,
|
2022-03-26 08:02:25 +08:00
|
|
|
general_height=general_height,
|
|
|
|
|
general_width=general_width)
|