Skip to content

Commit

Permalink
Add options for name and school
Browse files Browse the repository at this point in the history
  • Loading branch information
suchow committed May 1, 2014
1 parent b3eabea commit be64be9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
48 changes: 7 additions & 41 deletions assets/schools/Generic/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,13 @@ def __init__(self):
self.document = Document('../assets/word-base/dissertate.docx')

def fill(self):

# Cover page
self.document.add_heading('Title of the dissertation', level=1)

list = ['a dissertation presented',
'by',
'Firstname M. Lastname',
'to',
'the department of motor vehicles',
'',
'in partial fulfillment of the requirements',
'for the degree of',
'Doctor of Philosophy',
'in the subject of',
'Psychology',
'',
'Harvard University',
'Cambridge, Massachusetts',
'May 2014']

for i in list:
self.document.add_paragraph(i, style="CoverBody")

self.document.add_page_break()

p = self.document.add_paragraph('A plain paragraph having some ')
p.add_run('bold').bold = True
p.add_run(' and some ')
p.add_run('italic.').italic = True

self.document.add_heading('Heading, level 1', level=1)
self.document.add_paragraph('Intense quote', style='IntenseQuote')

self.document.add_paragraph(
'first item in unordered list', style='ListBullet'
)
self.document.add_paragraph(
'first item in ordered list', style='ListNumber'
)

#document.add_picture('monty-truth.png', width=Inches(1.25))
print ""

def save(self):
self.document.save('dissertation.docx')

def clear_paragraph(self, paragraph):
p_element = paragraph._p
p_child_elements = [elm for elm in p_element.iterchildren()]
for child_element in p_child_elements:
p_element.remove(child_element)
Binary file modified assets/word-base/dissertate.docx
Binary file not shown.
25 changes: 21 additions & 4 deletions scripts/dissertate-word.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
#!/usr/bin/env python
import optparse
import importlib
import os


def main():
"""A command line interface for creating Dissertate Word templates."""
p = optparse.OptionParser()
p.add_option("--school", "-s",
action="callback", callback=createTemplate, type="str")
action="store", type="string", dest="school")
p.add_option("--name", "--n",
action="store", type="string", dest="name")

options, arguments = p.parse_args()

if not options.name:
options.name = "Firstname M. Lastname"

def createTemplate(option, opt_str, schoolName, parser):
SchoolPackage = importlib.import_module("schools." + schoolName + ".word")
if not options.school:
options.school = "Generic"

createTemplate(options.school, options.name)


def createTemplate(school, name):
SchoolPackage = importlib.import_module("schools." + school + ".word")
template = SchoolPackage.Template()
template.fill()

for paragraph in template.document.paragraphs:
if "Firstname M. Lastname" in paragraph.text:
style = paragraph.style
template.clear_paragraph(paragraph)
paragraph.add_run(name)
paragraph.style = style

template.save()


Expand Down

0 comments on commit be64be9

Please sign in to comment.