{% extends "base.html" %}
{% block header %}
<h1>{{p['name']}}</h1>
{% endblock header %}
{% block content %}
<h1>{{p['position'].capitalize()}}</h1>
<img src="{{p.get('avatar')}}" style="width:200px"/>
<p>{{p.get('bio', '').replace('\n\n', '</p><p>')}}</p>


{%if 'honors' in p and len(p['honors']) > 0%}
<hr/><a name="honors" />
<h1><a href="#honors">Honors</a></h1>
{%for h in sorted(p['honors'], key=doc_date_key, reverse=True)%}
  <h3>{{h['name']}}</h3>
  {{h.get('month', '')}} {{h['year']}}{%if 'duration' in h%},
  Duration: {{h['duration']}}{%endif%}
  {%if 'description' in h%}<br/>{{h['description']}}{%endif%}
  <br/><br/>
{%endfor%}
{%endif%}


{%if len(education_and_employment) > 0%}
<hr/><a name="education-and-employment" />
<h1><a href="#education-and-employment">Education & Employment</a></h1><br/>
{%for e in education_and_employment%}
  {%if 'institution' in e%}{# In eduction #}
    <h2>{{e['institution']}}</h2>
      {%if 'degree' in e%}
        <h3>{{e['degree']}}</h3>
      {%else%}
        <h3>{{e['position']}}</h3>
      {%endif%}
  {%elif 'organization' in e%}{# In emplyment #}
    <h2>{{e['organization']}}</h2><h3>{{e['position']}}</h3>
  {%endif%}
  {{e['location']}}, <i>{{e['begin_year']}} - {{e.get('end_year', 'present')}}</i><br/>
  {%if 'other' in e and len(e['other']) > 0%}
    <ul>{%for o in e['other']%}
      <li>{{o}}</li>
    {%endfor%}</ul>
  {%endif%}
{%endfor%}
{%endif%}


{%if 'funding' in p and len(p['funding']) > 0%}
<hr/><a name="funding" />
<h1><a href="#funding">Awards, Grants, & Contracts</a></h1>
{%for f in sorted(p['funding'], key=doc_date_key, reverse=True)%}
  <h3>{{f['name']}}</h3>
  {{f.get('currency', '$')}}{{'{:,.2f}'.format(f['value'])}} in
  {{f.get('month', '')}} {{f['year']}}{%if 'duration' in f%},
  Duration: {{f['duration']}}{%endif%}
  <br/><br/>
{%endfor%}
{%endif%}


{%if 'service' in p and len(p['service']) > 0%}
<hr/><a name="service" />
<h1><a href="#service">Service</a></h1>
{%for s in sorted(p['service'], key=doc_date_key, reverse=True)%}
  <h3>{{s['name']}}</h3>
  {{s.get('month', '')}} {{s['year']}}{%if 'duration' in s%},
  Duration: {{s['duration']}}{%endif%}
  {%if 'description' in s%}<br/>{{s['description']}}{%endif%}
  <br/><br/>
{%endfor%}
{%endif%}


{%if len(projects) > 0%}
<hr/><a name="projects" />
<h1><a href="#projects">Projects</a></h1><br/>
{%for proj in projects%}
  <h2><a href="{{proj['website']}}">{{proj['_id']}}</a></h2>
  {%if 'logo' in proj%}<a href="{{proj['website']}}" class="image-link">
    <img src="{{proj['logo']}}" style="width:150px;height:150px;"/>
  </a><br/>{%endif%}
  {%if 'description' in proj%}{{proj['description']}}{%endif%}
  <ul>{%for pos in sorted(proj['team'], key=date_key, reverse=True)%}
    <li><b>{{pos['position']}}:</b><i>
      {{pos.get('begin_month', '')}} {{pos['begin_year']}} -
      {{pos.get('end_month', '')}} {{pos.get('end_year', 'present')}}
    </i></li>
  {%endfor%}</ul>
{%endfor%}
{%endif%}


<hr/><a name="pubs" />
<h1><a href="#pubs">Publications</a></h1>
{%if bibfile%}<h3><a href="{{p['_id']}}.bib">[Download bibtex]</a></h3>{%endif%}
<details>
<ol>
{% for pub in pubs %}
  <li>
  {%  set ae = pub.get('author', pub.get('editor', [])) %}
  {% for a in ae[:-1] %}
    {% if a in names %}<b>{% endif %}{{a}}{% if a in names %}</b>{% endif %},
  {% endfor %}
  {% if len(ae) > 1 %}
    and
  {% endif %}
  {% set a = ae[-1] %}
  {% if a in names %}<b>{% endif %}{{a}}{% if a in names %}</b>{% endif %}.
  <i>"{{pub.get('title', '')}}".</i>
  {{pub.get('version', '')}}
  {{pub.get('journal', '')}}
  {{pub.get('booktitle', '')}}.
  {{pub.get('volume', '')}}
    {%- if pub['pages'] %}
  {{'p. ' + pub['pages']}}
    {%- else %}
  {{''}}
    {%- endif %}
  {{pub.get('address', '')}}
  {% if 'month' in pub and 'year' in pub %}
    {{pub['month'].capitalize()}} {{pub['year']}}
  {% elif 'year' in pub %}
    ({{pub['year']}})
  {% endif %}
  {% if 'link' in pub %}<a href="{{pub['link']}}">link</a>{% endif %}
  {% if 'url' in pub %}<a href="{{pub['url']}}">download</a>{% endif %}
  {% if 'doi' in pub %}<a href="{{pub['doi']}}">doi</a>{% endif %}
  </li>
{% endfor %}
</ol>
</details>

{%if 'teaching' in p and len(p['teaching']) > 0%}
<hr/><a name="teaching" />
<h1><a href="#teaching">Teaching Experience</a></h1><br/>
{%for t in sorted(p['teaching'], key=date_key, reverse=True)%}
  <h2>{{t['course']}}</h2>
  <h3>{{t['organization']}}</h3>
  {{t['position']}},
  <i>
    {{t.get('month', '')}} {{t['year']}}
    {%if 'end_year' in t%}- {{t.get('end_month', '')}} {{t['end_year']}}{%endif%}
  </i>
  {%if 'description' in t%}<br/>{{t['description']}}{%endif%}
  {%if 'website' in t%}<a href="{{t['website']}}">[Website]</a>{%endif%}
  {%if 'syllabus' in t%}<a href="{{t['syllabus']}}">[Syllabus]</a>{%endif%}
  {%if 'video' in t%}<a href="{{t['video']}}">[Video]</a>{%endif%}
  {%if 'materials' in t%}<a href="{{t['materials']}}">[Course Materials]</a>{%endif%}
  <br/><br/>
{%endfor%}
{%endif%}


{%if 'membership' in p and len(p['membership']) > 0%}
<hr/><a name="membership" />
<h1><a href="#membership">Memberships</a></h1><br/>
{%for m in sorted(p['membership'], key=date_key, reverse=True)%}
  <h2>{{m['organization']}}</h2>
  {{m['position']}},
  <i>
    {{m.get('begin_month', '')}} {{m['begin_year']}} -
    {{m.get('end_month', '')}} {{m.get('end_year', 'present')}}
  </i>
  {%if 'description' in m%}<br/>{{m['description']}}{%endif%}
  {%if 'website' in m%}<a href="{{m['website']}}">[Website]</a>{%endif%}
  <br/><br/>
{%endfor%}
{%endif%}


{%if 'skills' in p and len(p['skills']) > 0%}
<hr/><a name="skills" />
<h1><a href="#skills">Skills</a></h1><br/>
{%for cat, cgrp in groupby(p['skills'], key=category_val)%}
  <h3>{{cat}}</h3>
  <ul>{%for lvl, lgrp in groupby(cgrp, key=level_val)%}
    <li><b>{{lvl.capitalize()}}:</b> {{gets(lgrp, 'name', '<nemo>') | join(', ')}}</li>
  {%endfor%}</ul>
{%endfor%}
{%endif%}


{% endblock content %}
{% block footer %}
{% endblock footer %}
