Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Add JSON endpoint for cert viewing #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ def get(self):
cert_id = int(self.request.get('id'))
except (ValueError, TypeError):
return self.error(404)
cert_format = self.request.get('format', 'html')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't actually use 'html' anywhere, why not just make this .get('format').


self.show_cert(cert_id, cert_format)

self.show_cert(cert_id)

def show_cert(self, cert_id):
def show_cert(self, cert_id, cert_format):
cert = models.Certification.get_by_id(cert_id)
if not cert:
return self.error(404)
Expand Down Expand Up @@ -505,9 +505,12 @@ def show_cert(self, cert_id):
char_id = int(char_id)
return self.show_cert_progress(data, char_id)

template = jinja_environment.get_template("view_cert.html")
page = template.render(data)
self.response.out.write(page)
if cert_format == 'json':
self.response.out.write(json.dumps(dict(name=cert.name, skills=skills)))
else:
template = jinja_environment.get_template("view_cert.html")
page = template.render(data)
self.response.out.write(page)

def show_cert_progress(self, data, char_id):
character = None
Expand Down