Render submission date
This commit is contained in:
parent
a8a228cb23
commit
1c937e9188
7 changed files with 43 additions and 6 deletions
|
@ -16,5 +16,9 @@
|
||||||
{% if turnitin_number %}
|
{% if turnitin_number %}
|
||||||
<h4>TurnItIn Number: {{ turnitin_number }}</h4>
|
<h4>TurnItIn Number: {{ turnitin_number }}</h4>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if submission_date %}
|
||||||
|
<h4>Submission Date: {{ submission_date }}</h4>
|
||||||
|
{% endif %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td></td>
|
<td>
|
||||||
|
{% if submission_date %}
|
||||||
|
Date: {{ submission_date }}
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<script type="text/javascript" src="../static/context.js"></script>
|
<script type="text/javascript" src="../static/context.js"></script>
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
from md_pdf.consts import TEMPLATES_DIR, STATIC_DIR
|
from md_pdf.consts import TEMPLATES_DIR, STATIC_DIR, DATE_FORMAT, TIME_FORMAT, DATETIME_FORMAT
|
||||||
from word_count import word_count
|
from word_count import word_count
|
||||||
from md_pdf.utils import get_plain_text
|
from md_pdf.utils import get_plain_text
|
||||||
from datetime import datetime
|
from dateutil import parser
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
EXTRA_CONTEXT = {
|
EXTRA_CONTEXT = {
|
||||||
'templates_dir': TEMPLATES_DIR,
|
'templates_dir': TEMPLATES_DIR,
|
||||||
'static_dir': STATIC_DIR,
|
'static_dir': STATIC_DIR,
|
||||||
'date': datetime.now()
|
'date': datetime.datetime.now().strftime(DATE_FORMAT),
|
||||||
|
'time': datetime.datetime.now().strftime(TIME_FORMAT),
|
||||||
|
'datetime': datetime.datetime.now().strftime(DATETIME_FORMAT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,4 +28,10 @@ def get_context(config, content):
|
||||||
)
|
)
|
||||||
if config.get('show_word_count'):
|
if config.get('show_word_count'):
|
||||||
context['word_count'] = word_count(get_plain_text(content))
|
context['word_count'] = word_count(get_plain_text(content))
|
||||||
|
if config.get('submission_date'):
|
||||||
|
if type(config['submission_date']) in [datetime.date, datetime.datetime, datetime.time]:
|
||||||
|
submission_date = config['submission_date']
|
||||||
|
else:
|
||||||
|
submission_date = parser.parse(config['submission_date'])
|
||||||
|
context['submission_date'] = submission_date.strftime(DATE_FORMAT)
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -3,7 +3,8 @@ from md_pdf.consts import CSL_DIR
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
from dateutil import parser
|
||||||
|
import datetime
|
||||||
|
|
||||||
logger = logging.getLogger(__file__)
|
logger = logging.getLogger(__file__)
|
||||||
|
|
||||||
|
@ -83,6 +84,18 @@ def validate_wordcount(config):
|
||||||
raise ConfigValidationException("Show word count key should be either true or false")
|
raise ConfigValidationException("Show word count key should be either true or false")
|
||||||
|
|
||||||
|
|
||||||
|
def validate_submission_date(config):
|
||||||
|
if 'submission_date' not in config:
|
||||||
|
return
|
||||||
|
if type(config['submission_date']) in [datetime.date, datetime.datetime, datetime.time]:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
parser.parse(config['submission_date'])
|
||||||
|
except ValueError:
|
||||||
|
raise ConfigValidationException("Invalid Submission Date format")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def validate_config(config):
|
def validate_config(config):
|
||||||
logger.debug("Validating Config...")
|
logger.debug("Validating Config...")
|
||||||
for validator in [
|
for validator in [
|
||||||
|
@ -92,7 +105,8 @@ def validate_config(config):
|
||||||
validate_bibliography,
|
validate_bibliography,
|
||||||
validate_context,
|
validate_context,
|
||||||
validate_toc,
|
validate_toc,
|
||||||
validate_wordcount
|
validate_wordcount,
|
||||||
|
validate_submission_date
|
||||||
]:
|
]:
|
||||||
validator(config)
|
validator(config)
|
||||||
logger.debug("Config Ok!")
|
logger.debug("Config Ok!")
|
||||||
|
|
|
@ -11,3 +11,7 @@ STATIC_DIR = os.path.join(ASSET_DIR, 'static')
|
||||||
CONFIG_FILE = os.path.join(WORKING_DIR, 'mdp.yml')
|
CONFIG_FILE = os.path.join(WORKING_DIR, 'mdp.yml')
|
||||||
|
|
||||||
CSL_DOWNLOAD_LINK = "https://github.com/citation-style-language/styles/archive/master.zip"
|
CSL_DOWNLOAD_LINK = "https://github.com/citation-style-language/styles/archive/master.zip"
|
||||||
|
|
||||||
|
DATE_FORMAT = "%d %B %Y"
|
||||||
|
TIME_FORMAT = "%H:%M"
|
||||||
|
DATETIME_FORMAT = "{} {}".format(DATE_FORMAT, TIME_FORMAT)
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -12,6 +12,7 @@ setup(
|
||||||
"progressbar2==3.16.0",
|
"progressbar2==3.16.0",
|
||||||
"pypandoc==1.3.3",
|
"pypandoc==1.3.3",
|
||||||
"pyscss==1.3.5",
|
"pyscss==1.3.5",
|
||||||
|
"python-dateutil==2.6.0",
|
||||||
"PyYAML==3.12",
|
"PyYAML==3.12",
|
||||||
"word-count==0.1.0"
|
"word-count==0.1.0"
|
||||||
],
|
],
|
||||||
|
|
|
@ -14,3 +14,4 @@ context:
|
||||||
title: test title
|
title: test title
|
||||||
toc: true
|
toc: true
|
||||||
show_word_count: true
|
show_word_count: true
|
||||||
|
submission_date: 2017-01-01
|
||||||
|
|
Reference in a new issue