sync document updated: store raw data in document token; format on compile
This commit is contained in:
1 parent
18645a7c94
commit
e2f41c8dc4
3 files changed
+18
-35
No files matched your search
@@ -1,4 +1,5 @@
|
||||
from kazimir.Token import parse_file, is_document, Token
|
||||
import math
|
||||
|
||||
|
||||
class DocumentToken(Token):
|
||||
@@ -10,7 +11,7 @@ class DocumentToken(Token):
|
||||
super().__init__(name='file', data=data)
|
||||
self.joinable = False
|
||||
self.build = None
|
||||
|
||||
|
||||
async def get_data(self):
|
||||
data = parse_file(self.data)
|
||||
document = await self.build(data)
|
||||
@@ -23,6 +24,9 @@ class DocumentToken(Token):
|
||||
|
||||
|
||||
def create_document(document):
|
||||
file_size = get_size(document['file_size'], 1)
|
||||
file_format = 'ПДФ'
|
||||
|
||||
return f'''
|
||||
<div>
|
||||
<div class="document-row">
|
||||
@@ -38,9 +42,18 @@ def create_document(document):
|
||||
|
||||
<div class="document-row__file-info">
|
||||
<a href="{document['file_url']}" target="_blank">
|
||||
{document['file_format']} ({document['file_size']})
|
||||
{file_format} ({file_size})
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
'''.strip()
|
||||
|
||||
|
||||
def get_size(number_of_bytes, precision=1):
|
||||
units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ']
|
||||
number = math.floor(math.log(number_of_bytes) / math.log(1024))
|
||||
size = (number_of_bytes / math.pow(1024, math.floor(number)))
|
||||
size = round(size, precision)
|
||||
|
||||
return f'{size} {units[number]}'
|
||||
Reference in new issue
Block a user