Skip to content

Commit 74fab70

Browse files
committed
Moving from io to tempfile to respect pandoc fileoutput constraint
1 parent d0f99b4 commit 74fab70

File tree

4 files changed

+32
-52
lines changed

4 files changed

+32
-52
lines changed

README.md

+16-42
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,43 @@
11
# Django Panpub
22

3-
**Warning: early-stage dev, no migration files provided**
3+
**Warning: early-stage dev**
44

5-
Panpub, from *pan* ("all, of everything") and *publishing*. A Django publishing app providing united streamlined outputs from centralised normalised inputs.
5+
Panpub, from *pan* ("all, of everything") and *publishing*. A Django publishing app providing united streamlined outputs from centralised normalised inputs, with an embedded system of claims regarding each content and role (*creator*, *curator*, *mediator*).
66

77

88
## Directions
99

1010
* **Medium openness**: widely-used media - writing, picture, audio and video - with outside link as a fall-back option
11+
* **Access first**: various commonly-used formats for import and export
1112
* **Living culture**: claims of participation (whether as creator, curator or mediator) available for each unique content
12-
* **Batteries included**: delicious base of models, decorators and templatetags, with its standard topping of views, forms, urls and templates
13+
* **Batteries included**: delicious base of models, decorators and templatetags, with its standard topping of views, forms, urls and templates for reuse
1314

1415

1516
## Achieved features
16-
* Panpub ecosystem : data and media export
17-
* Text model : upload to markdown through pandoc
17+
* Panpub ecosystem: claim system, corpus creation, system-wide exporting
18+
* Text model: use of pandoc as the middleman, upload and download
1819

1920

2021
## Ecosystem
2122

22-
Models:
23-
* Corpus
24-
* Content
25-
* Crafter
26-
* Claim
27-
28-
Decorator:
29-
* has_any_claim
30-
* has_creator_claim
31-
* has_curator_claim
32-
* has_mediator_claim
33-
34-
Templatetags:
35-
* crafterworks
23+
* models: Corpus, Content, Crafter, Claim
24+
* decorators: has_any_claim, has_creator_claim, has_curator_claim, has_mediator_claim
25+
* templatetags: crafterworks
26+
* utils: panpub_export
3627

3728

3829
## Writing
3930

40-
Main class:
41-
* Text
42-
43-
Available inputs:
44-
* .md (*pandoc-standard* or *github-flavored*)
45-
* .latex
46-
* .docx
47-
* .odt
48-
* .html
49-
* .rst
50-
* native Haskell
51-
52-
In-house format:
53-
* markdown (*pandoc-standard*)
54-
55-
Available outputs: (*none implemented yet*)
56-
* md
57-
* html
58-
* pdf
59-
* .ebook
60-
61-
Templatetags:
62-
* craftertexts
31+
* main class: Text
32+
* inputs: .md (*pandoc-standard* or *github-flavored*), .latex, .docx, .odt, .html, .rst, native Haskell
33+
* in-house: markdown (*pandoc-standard*)
34+
* ouputs: .md (*pandoc-standard* or *github-flavored*), .html, .docx, .epub, .odt
35+
* templatetags: craftertexts
6336

6437

6538
## Spoilers
6639

40+
* Text medium: fixing integration of xetex and adding .pdf to the outputs, extending .md and .latex plugins
6741
* Picture medium: Pillow-fed input, with opt-in EXIF-cleaner and LSB-smoother (a.k.a. *anti-steganography**)
6842
* Dataset medium: Tablib-fed input
6943
* pandoc auto-installation

panpub/models.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
import pathlib
5+
import tempfile
46
from io import StringIO
57
from sys import getsizeof
68

@@ -147,30 +149,34 @@ def filefriendly_name(self):
147149
return slugify(self.name)
148150

149151
def available_pubformats(self):
150-
# docx, epub, odt require outputfile instead of var
151152
# pdf requires xetex
152153
return ('gfm',
153154
'html',
154155
'markdown',
156+
'docx',
157+
'epub',
158+
'odt',
155159
)
156160

157161
def export(self, pubformat='markdown'):
158162
if pubformat not in self.available_pubformats():
159163
raise Exception
160164
try:
161-
data = pypandoc.convert_file(self.document.path,
162-
pubformat,
163-
format='md')
164-
datafile = StringIO(data)
165+
with tempfile.NamedTemporaryFile() as f:
166+
pypandoc.convert_file(self.document.path,
167+
pubformat,
168+
format='md',
169+
outputfile=pathlib.Path(tempfile.tempdir, f.name).as_posix())
170+
f.seek(0)
171+
datafile = f.read()
165172
except Exception:
166173
raise Exception
167174
else:
168-
filelen = len(datafile.getvalue())
175+
filelen = len(datafile)
169176
filename = '{}.{}'.format(self.filefriendly_name(),
170177
pubformat)
171-
datafile.seek(0)
172-
filedata = datafile.getvalue()
173-
return filedata, filename, filelen
178+
filedata = datafile
179+
return datafile, filename, filelen
174180

175181

176182
class Picture(Content):

panpub/urls.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
from django.conf.urls import url
4-
from django.views.generic import TemplateView
54

65
from panpub import views
76

panpub/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def text_export(request, text_id, export_format):
7373

7474
if not text.ready:
7575
raise PermissionDenied # unless user has claim ?
76+
7677
if export_format not in text.available_pubformats():
7778
raise Http404("Export format requested unavailable.")
7879

0 commit comments

Comments
 (0)