mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-25 18:43:47 +03:00
added csv
This commit is contained in:
parent
e56f64afc6
commit
d6a738ee60
|
@ -19,7 +19,7 @@
|
|||
"avif": image.basic.view,
|
||||
"bmp": image.basic.view,
|
||||
},
|
||||
"text": {"css": text.common.view, "plain": text.plain.view},
|
||||
"text": {"css": text.common.view, "plain": text.plain.view, "csv": text.csv.view},
|
||||
}
|
||||
|
||||
source_code = {}
|
||||
|
|
|
@ -1 +1 @@
|
|||
from . import common, plain # noqa
|
||||
from . import common, csv, plain # noqa
|
||||
|
|
34
akarpov/files/previews/text/csv.py
Normal file
34
akarpov/files/previews/text/csv.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import csv
|
||||
|
||||
import chardet
|
||||
import structlog
|
||||
|
||||
from akarpov.files.models import File
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
def view(file: File):
|
||||
try:
|
||||
try:
|
||||
with open(file.file.path, newline="") as csvfile:
|
||||
dialect = csv.Sniffer().sniff(csvfile.read(1024))
|
||||
csvfile.seek(0)
|
||||
reader = csv.reader(csvfile, dialect)
|
||||
for row in reader:
|
||||
print(row)
|
||||
except UnicodeDecodeError:
|
||||
rawdata = open("file.csv", "rb").read()
|
||||
enc = chardet.detect(rawdata)
|
||||
print(enc)
|
||||
with open(file.file.path, newline="", encoding=enc["encoding"]) as csvfile:
|
||||
dialect = csv.Sniffer().sniff(csvfile.read(1024))
|
||||
csvfile.seek(0)
|
||||
reader = csv.reader(csvfile, dialect)
|
||||
for row in reader:
|
||||
print(row)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
static = ""
|
||||
content = ""
|
||||
return static, content
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
class TopFolderView(LoginRequiredMixin, ListView):
|
||||
template_name = "files/list.html"
|
||||
paginate_by = 20
|
||||
paginate_by = 19
|
||||
model = File
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
15
poetry.lock
generated
15
poetry.lock
generated
|
@ -689,6 +689,18 @@ Django = ">=3.2"
|
|||
daphne = ["daphne (>=4.0.0)"]
|
||||
tests = ["async-timeout", "coverage (>=4.5,<5.0)", "pytest", "pytest-asyncio", "pytest-django"]
|
||||
|
||||
[[package]]
|
||||
name = "chardet"
|
||||
version = "5.1.0"
|
||||
description = "Universal encoding detector for Python 3"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "chardet-5.1.0-py3-none-any.whl", hash = "sha256:362777fb014af596ad31334fde1e8c327dfdb076e1960d1694662d46a6917ab9"},
|
||||
{file = "chardet-5.1.0.tar.gz", hash = "sha256:0d62712b956bc154f85fb0a266e2a3c5913c2967e00348701b32411d6def31e5"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "charset-normalizer"
|
||||
version = "3.1.0"
|
||||
|
@ -3163,7 +3175,6 @@ files = [
|
|||
{file = "Pillow-9.5.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:c1170d6b195555644f0616fd6ed929dfcf6333b8675fcca044ae5ab110ded296"},
|
||||
{file = "Pillow-9.5.0-cp311-cp311-win32.whl", hash = "sha256:54f7102ad31a3de5666827526e248c3530b3a33539dbda27c6843d19d72644ec"},
|
||||
{file = "Pillow-9.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:cfa4561277f677ecf651e2b22dc43e8f5368b74a25a8f7d1d4a3a243e573f2d4"},
|
||||
{file = "Pillow-9.5.0-cp311-cp311-win_arm64.whl", hash = "sha256:965e4a05ef364e7b973dd17fc765f42233415974d773e82144c9bbaaaea5d089"},
|
||||
{file = "Pillow-9.5.0-cp312-cp312-win32.whl", hash = "sha256:22baf0c3cf0c7f26e82d6e1adf118027afb325e703922c8dfc1d5d0156bb2eeb"},
|
||||
{file = "Pillow-9.5.0-cp312-cp312-win_amd64.whl", hash = "sha256:432b975c009cf649420615388561c0ce7cc31ce9b2e374db659ee4f7d57a1f8b"},
|
||||
{file = "Pillow-9.5.0-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:5d4ebf8e1db4441a55c509c4baa7a0587a0210f7cd25fcfe74dbbce7a4bd1906"},
|
||||
|
@ -5202,4 +5213,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"]
|
|||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.11"
|
||||
content-hash = "717219069cdeaa5037bc3693ddb6580db23e67d0e6ae42b47deed69a048622ea"
|
||||
content-hash = "580bc9d748f65b25b9de3554c49e5c05a9cb3fccc60ce411b8f953ab70f2c14f"
|
||||
|
|
|
@ -86,6 +86,7 @@ xvfbwrapper = "^0.2.9"
|
|||
vtk = "^9.2.6"
|
||||
ffmpeg-python = "^0.2.0"
|
||||
cairosvg = "^2.7.0"
|
||||
chardet = "^5.1.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
|
Loading…
Reference in New Issue
Block a user