multiple author support

This commit is contained in:
Neale Pickett 2017-01-30 19:13:02 +00:00
parent 6906903ef4
commit c12ee422c4
3 changed files with 11 additions and 8 deletions

View File

@ -176,7 +176,7 @@ you are a fool.
for a in puzzle.answers: for a in puzzle.answers:
body.write("<li><code>{}</code></li>".format(html.escape(a))) body.write("<li><code>{}</code></li>".format(html.escape(a)))
body.write("</ul>") body.write("</ul>")
body.write("<h2>Author</h2><p>{}</p>".format(puzzle.author)) body.write("<h2>Authors</h2><p>{}</p>".format(', '.join(puzzle.get_authors())))
body.write("<h2>Summary</h2><p>{}</p>".format(puzzle.summary)) body.write("<h2>Summary</h2><p>{}</p>".format(puzzle.summary))
if puzzle.logs: if puzzle.logs:
body.write("<h2>Debug Log</h2>") body.write("<h2>Debug Log</h2>")

View File

@ -63,8 +63,8 @@ class Puzzle:
super().__init__() super().__init__()
self.points = points self.points = points
self.author = None
self.summary = None self.summary = None
self.authors = []
self.answers = [] self.answers = []
self.files = {} self.files = {}
self.body = io.StringIO() self.body = io.StringIO()
@ -88,7 +88,7 @@ class Puzzle:
key = key.lower() key = key.lower()
val = val.strip() val = val.strip()
if key == 'author': if key == 'author':
self.author = val self.authors.append(val)
elif key == 'summary': elif key == 'summary':
self.summary = val self.summary = val
elif key == 'answer': elif key == 'answer':
@ -234,6 +234,9 @@ class Puzzle:
self.body.write('{:08x}\n'.format(offset)) self.body.write('{:08x}\n'.format(offset))
self.body.write('</pre>') self.body.write('</pre>')
def get_authors(self):
return self.authors or [self.author]
def get_body(self): def get_body(self):
return self.body.getvalue() return self.body.getvalue()

View File

@ -35,7 +35,7 @@ def write_kv_pairs(ziphandle, filename, kv):
def escape(s): def escape(s):
return s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;') return s.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')
def generate_html(ziphandle, puzzle, puzzledir, category, points, author, files): def generate_html(ziphandle, puzzle, puzzledir, category, points, authors, files):
html_content = io.StringIO() html_content = io.StringIO()
file_content = io.StringIO() file_content = io.StringIO()
if files: if files:
@ -73,14 +73,14 @@ def generate_html(ziphandle, puzzle, puzzledir, category, points, author, files)
<input type="submit" value="submit"> <input type="submit" value="submit">
</form> </form>
</section> </section>
<address>Puzzle by <span class="author" data-handle="{author}">{author}</span></address> <address>Puzzle by <span class="authors" data-handle="{authors}">{authors}</span></address>
<section id="sponsors"> <section id="sponsors">
<img src="../../images/lanl.png" alt="Los Alamos National Laboratory"> <img src="../../images/lanl.png" alt="Los Alamos National Laboratory">
<img src="../../images/doe.png" alt="US Department Of Energy"> <img src="../../images/doe.png" alt="US Department Of Energy">
<img src="../../images/sandia.png" alt="Sandia National Laboratories"> <img src="../../images/sandia.png" alt="Sandia National Laboratories">
</section> </section>
</body> </body>
</html>'''.format(category=category, points=points, body=puzzle.html_body(), file_content=file_content.getvalue(), author=author)) </html>'''.format(category=category, points=points, body=puzzle.html_body(), file_content=file_content.getvalue(), authors=', '.join(authors)))
ziphandle.writestr(os.path.join(puzzledir, 'index.html'), html_content.getvalue()) ziphandle.writestr(os.path.join(puzzledir, 'index.html'), html_content.getvalue())
def build_category(categorydir, outdir): def build_category(categorydir, outdir):
@ -132,14 +132,14 @@ def build_category(categorydir, outdir):
zf.writestr(os.path.join(puzzledir, fn), payload) zf.writestr(os.path.join(puzzledir, fn), payload)
puzzledict = { puzzledict = {
'author': puzzle.author, 'authors': puzzle.authors,
'hashes': puzzle.hashes(), 'hashes': puzzle.hashes(),
'files': files, 'files': files,
'body': puzzle.html_body(), 'body': puzzle.html_body(),
} }
puzzlejson = json.dumps(puzzledict) puzzlejson = json.dumps(puzzledict)
zf.writestr(os.path.join(puzzledir, 'puzzle.json'), puzzlejson) zf.writestr(os.path.join(puzzledir, 'puzzle.json'), puzzlejson)
generate_html(zf, puzzle, puzzledir, categoryname, puzzle.points, puzzle.author, files) generate_html(zf, puzzle, puzzledir, categoryname, puzzle.points, puzzle.get_authors(), files)
write_kv_pairs(zf, 'map.txt', mapping) write_kv_pairs(zf, 'map.txt', mapping)
write_kv_pairs(zf, 'answers.txt', answers) write_kv_pairs(zf, 'answers.txt', answers)