-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
225 lines (193 loc) · 4.9 KB
/
constants.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
"Constants."
import functools
from pathlib import Path
SOFTWARE = "mdbook"
VERSION = (5, 16, 0)
__version__ = ".".join([str(n) for n in VERSION])
LANGUAGE_CODES = ("sv-SE", "en-GB", "en-US")
ENCODING = "utf-8"
MARKDOWN_EXT = ".md"
SOURCE_DIRPATH = Path(__file__).parent
FONT_DIRPATH = SOURCE_DIRPATH / "freefont"
TRANSLATIONS_FILEPATH = SOURCE_DIRPATH / "translations.csv"
USERS_DATABASE_FILENAME = "users.yaml"
# Hard-coded groups.
ADMIN_GROUP = "admin"
USER_GROUP = "user"
PUBLIC_RESOURCES = set(
[
"/login",
"/ping",
"/favicon.ico",
"/mods.css",
"/mdbook.png",
"/clipboard.min.js",
"/clipboard.svg",
]
)
DATETIME_ISO_FORMAT = "%Y-%m-%d %H:%M:%S"
MONTHS = {
"jan": 1,
"january": 1,
"feb": 2,
"february": 2,
"mar": 3,
"march": 3,
"apr": 4,
"april": 4,
"may": 5,
"jun": 6,
"june": 6,
"jul": 7,
"july": 7,
"aug": 8,
"august": 8,
"sep": 9,
"september": 9,
"oct": 10,
"october": 10,
"nov": 11,
"november": 11,
"dec": 12,
"december": 12,
}
EM_DASH = "\u2014"
@functools.total_ordering
class Status:
@classmethod
def lookup(cls, name, default=None):
if name:
return STATUS_LOOKUP.get(name) or default
else:
return min(STATUSES)
def __init__(self, name, ordinal, color):
self.name = name
self.ordinal = ordinal
self.color = color
def __str__(self):
return self.name.capitalize()
def __repr__(self):
return self.name
def __eq__(self, other):
if not isinstance(other, Status):
return False
return self.name == other.name
def __ne__(self, other):
return other is None or self.name != other.name
def __lt__(self, other):
return self.ordinal < other.ordinal
STARTED = Status("started", 0, "gray")
OUTLINE = Status("outline", 1, "salmon")
INCOMPLETE = Status("incomplete", 2, "tomato")
DRAFT = Status("draft", 3, "crimson")
WRITTEN = Status("written", 4, "dodgerblue")
REVISED = Status("revised", 5, "blue")
DONE = Status("done", 6, "forestgreen")
PROOFS = Status("proofs", 7, "yellowgreen")
FINAL = Status("final", 8, "black")
STATUSES = (STARTED, OUTLINE, INCOMPLETE, DRAFT, WRITTEN, REVISED, DONE, PROOFS, FINAL)
STATUS_LOOKUP = dict([(s.name, s) for s in STATUSES])
STATUS_LOOKUP.update(dict([(str(s), s) for s in STATUSES]))
ARTICLE = "article"
BOOK = "book"
LINK = "link"
MAX_RECENT = 20
MAX_COPY_NUMBER = 20
MAX_DISPLAY_AUTHORS = 4
REFERENCES = "references"
REFERENCE_TYPES = (ARTICLE, BOOK, LINK)
REFERENCE_COLOR = "royalblue"
REFERENCE_LINKS = dict(
doi=("DOI", "https://doi.org/{value}"),
pmid=("PubMed", "https://pubmed.ncbi.nlm.nih.gov/{value}"),
isbn=("ISBN", "https://isbnsearch.org/isbn/{value}"),
)
BOLD = "bold"
ITALIC = "italic"
NORMAL = "normal"
UNDERLINE = "underline"
CODE_STYLE = "mdbook Code"
CODE_FONT = "FreeMono"
CODE_LEFT_INDENT = 30
QUOTE_STYLE = "mdbook Quote"
QUOTE_FONT = "FreeSerif"
QUOTE_FONT_SIZE = 14
QUOTE_LEFT_INDENT = 30
QUOTE_RIGHT_INDENT = 70
FONT = "FreeSans"
FONT_NORMAL_SIZE = 12
FONT_LARGE_SIZE = FONT_NORMAL_SIZE + 2
FONT_TITLE_SIZE = 28
FONT_NORMAL = (FONT, FONT_NORMAL_SIZE)
FONT_ITALIC = (FONT, FONT_NORMAL_SIZE, ITALIC)
FONT_BOLD = (FONT, FONT_NORMAL_SIZE, BOLD)
FONT_LARGE_BOLD = (FONT, FONT_LARGE_SIZE, BOLD)
FONT_SMALL_SIZE = FONT_NORMAL_SIZE - 2
FONT_SMALL = (FONT, FONT_SMALL_SIZE)
NORMAL = "normal"
ITALIC = "italic"
BOLD = "bold"
UNDERLINE = "underline"
FONT_STYLES = (NORMAL, ITALIC, BOLD, UNDERLINE)
H1 = dict(
tag="h1",
font=(FONT, FONT_LARGE_SIZE + 10, BOLD),
left_margin=40,
spacing=30,
)
H2 = dict(
tag="h2",
font=(FONT, FONT_LARGE_SIZE + 5, BOLD),
left_margin=30,
spacing=20,
)
H3 = dict(
tag="h3",
font=(FONT, FONT_LARGE_SIZE + 3, BOLD),
left_margin=20,
spacing=15,
)
H4 = dict(
tag="h4",
font=(FONT, FONT_NORMAL_SIZE, BOLD),
left_margin=15,
spacing=10,
)
H5 = dict(
tag="h5",
font=(FONT, FONT_NORMAL_SIZE, BOLD),
left_margin=10,
spacing=5,
)
H6 = dict(
tag="h6",
font=(FONT, FONT_NORMAL_SIZE),
left_margin=10,
spacing=5,
)
H_LOOKUP = dict([(1, H1), (2, H2), (3, H3), (4, H4), (5, H5), (6, H6)])
MAX_H_LEVEL = max(H_LOOKUP)
FOOTNOTES_EACH_TEXT = "after each text"
FOOTNOTES_EACH_CHAPTER = "after each chapter"
FOOTNOTES_END_OF_BOOK = "at end of book"
FOOTNOTES_LOCATIONS = (
FOOTNOTES_EACH_TEXT,
FOOTNOTES_EACH_CHAPTER,
FOOTNOTES_END_OF_BOOK,
)
DOCX_MIMETYPE = (
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
)
PDF_MIMETYPE = "application/pdf"
GZIP_MIMETYPE = "application/gzip"
PDF_HREF_COLOR = (20, 20, 255)
PDF_LIST_INDENT = 30
PDF_THEMATIC_BREAK_INDENT = 100
PDF_PAGE_NUMBER = "page number"
PDF_TEXT_FULLTITLE = "text fulltitle"
PDF_TEXT_HEADING = "text heading"
PDF_INDEXED_XREF_DISPLAY = (
PDF_PAGE_NUMBER,
PDF_TEXT_FULLTITLE,
PDF_TEXT_HEADING,
)