Render submission date

This commit is contained in:
Jake Howard 2017-05-25 21:33:18 +01:00
parent a8a228cb23
commit 1c937e9188
7 changed files with 43 additions and 6 deletions

View file

@ -16,5 +16,9 @@
{% if turnitin_number %}
<h4>TurnItIn Number: {{ turnitin_number }}</h4>
{% endif %}
{% if submission_date %}
<h4>Submission Date: {{ submission_date }}</h4>
{% endif %}
</body>
</html>

View file

@ -8,7 +8,11 @@
<tr>
<td></td>
<td></td>
<td></td>
<td>
{% if submission_date %}
Date: {{ submission_date }}
{% endif %}
</td>
</tr>
</table>
<script type="text/javascript" src="../static/context.js"></script>

View file

@ -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 md_pdf.utils import get_plain_text
from datetime import datetime
from dateutil import parser
import datetime
EXTRA_CONTEXT = {
'templates_dir': TEMPLATES_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'):
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

View file

@ -3,7 +3,8 @@ from md_pdf.consts import CSL_DIR
import glob
import os
import logging
from dateutil import parser
import datetime
logger = logging.getLogger(__file__)
@ -83,6 +84,18 @@ def validate_wordcount(config):
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):
logger.debug("Validating Config...")
for validator in [
@ -92,7 +105,8 @@ def validate_config(config):
validate_bibliography,
validate_context,
validate_toc,
validate_wordcount
validate_wordcount,
validate_submission_date
]:
validator(config)
logger.debug("Config Ok!")

View file

@ -11,3 +11,7 @@ STATIC_DIR = os.path.join(ASSET_DIR, 'static')
CONFIG_FILE = os.path.join(WORKING_DIR, 'mdp.yml')
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)

View file

@ -12,6 +12,7 @@ setup(
"progressbar2==3.16.0",
"pypandoc==1.3.3",
"pyscss==1.3.5",
"python-dateutil==2.6.0",
"PyYAML==3.12",
"word-count==0.1.0"
],

View file

@ -14,3 +14,4 @@ context:
title: test title
toc: true
show_word_count: true
submission_date: 2017-01-01