Skip to content

Commit

Permalink
Regularize template structure for forms
Browse files Browse the repository at this point in the history
Create a standard inheritance for form templates:

- Each type of model has its own base template that inherits from cv/forms/_base.html
- Create formgroups directory that contains reusable code for form groups used in multiple types of models (e.g., title, abstract)
- Create template for each model that inherits from appropriate type
  • Loading branch information
mikebader committed Dec 30, 2021
1 parent d6afbbd commit 01850ba
Show file tree
Hide file tree
Showing 25 changed files with 207 additions and 355 deletions.
18 changes: 16 additions & 2 deletions cv/templates/cv/forms/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
<h2 class="display-4">{{method}} {{model_verbose_name|title}}</h2>
<form method="POST" id="{{model}}-form" class="post-form small" action="{{action_url}}">{% csrf_token %}
<span class="invalid-feedback">{{form.non_field_errors}}</span>

{% if form.display %}
<div class="form-group row">
<span class="col-3 align-items-center pt-4">
Display?: {{form.display}}
</span>
</div>
{% endif %}
{% block formcontent %}
<div class="form-group row form-row">
{% for field in form %}
Expand All @@ -29,4 +35,12 @@ <h2 class="display-4">{{method}} {{model_verbose_name|title}}</h2>
</div>
</form>
</div>
{% endblock %}
{% endblock %}

{% block endscripts %}
{{ block.super }}
<script>
$(document).on('keyup', '.slugify > input', function(event){slugify(this)});
</script>

{% endblock endscripts %}
1 change: 1 addition & 0 deletions cv/templates/cv/forms/_base_achievement.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'cv/forms/_base.html' %}
13 changes: 13 additions & 0 deletions cv/templates/cv/forms/_base_person.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'cv/forms/_base.html' %}

{% load widget_tweaks %}

{% block formcontent %}
<!-- NAME -->
{% include 'cv/forms/formgroups/name.html' %}

{% block other_information %}{% endblock other_information %}


{% endblock %}

70 changes: 6 additions & 64 deletions cv/templates/cv/forms/_base_publication.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block formcontent %}
<div class="form-group row align-items-start">

{% include 'cv/forms/_title_group.html' %}
{% include 'cv/forms/formgroups/title.html' %}

<div class="col-12 col-lg-6 form-row">
<span class="col-12 col-lg-7">
Expand All @@ -32,22 +32,16 @@
</div>
<div class="form-group row">
<!-- ABSTRACT -->
<div class="col-12 col-lg-6 mt-3 form-row">
<h5 class="col-12 form-title">Abstract</h5>
<span class="col-12">
{% with form.abstract as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
<span class="form-text text-muted">Use <a href="https://daringfireball.net/projects/markdown/syntax" alt="Markdown syntax">Markdown syntax</a>: e.g., **<b>bold</b>**, *<i>italics</i>*, `<code>code</code>`, [link text]&lt;url&gt;</span>
</span>
</div>
{% include 'cv/forms/formgroups/abstract.html' %}

<!-- CITATION INFORMATION -->
<div class="col-12 col-lg-6 mt-3 form-row align-content-start">
<h5 class="col-12 form-title">Citation Information</h5>
{% block citation_information %}
{% endblock %}
</div>
</div>

<!-- AUTHORSHIP INFORMATION -->
<div class="form-group row">
<div class="col-12 row mt-3">
Expand Down Expand Up @@ -95,61 +89,9 @@ <h5 class="col-12 form-title">Authors</h5>
{% endblock %}

<!-- DISCIPLINARY INFORMATION -->
<div class="form-group row">
<h5 class="col-12 form-title">Disciplinary information</h5>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.primary_discipline as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.other_disciplines as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
</div>
{% include 'cv/forms/formgroups/discipline.html' %}

<!-- GRANT INFORMATION -->
<div class="form-group row">
<h5 class="col-12 form-title">Grant information</h5>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.grants as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.pmcid as field %}{% with noprinthelp=True %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}{% endwith %}
</span>
<span class="col-12">
{% with form.pmid as field %}{% with noprinthelp=True %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}{% endwith %}
</span>
{% if form.pmid or form.pmcid %}
<span class="col-12">
<span class="form-text text-muted">
For information on the above see <a href="https://publicaccess.nih.gov/include-pmcid-citations.htm#Difference" title="The Difference Between a PMCID and a PMID">explanation from NIH</a>
</span>
</span>
{% endif %}
</div>
</div>
{% include 'cv/forms/formgroups/grant.html' %}

{% endblock formcontent %}

{% block endscripts %}
{{ block.super }}
<script>
$(document).on('keyup', '.slugify > input', function(event){slugify(this)});
</script>

{% endblock endscripts %}
1 change: 1 addition & 0 deletions cv/templates/cv/forms/_base_service.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'cv/forms/_base.html' %}
1 change: 1 addition & 0 deletions cv/templates/cv/forms/_base_teaching.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'cv/forms/_base.html' %}
25 changes: 25 additions & 0 deletions cv/templates/cv/forms/_base_work.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'cv/forms/_base.html' %}

{% block formcontent %}
<div class="form-group row align-items-start ">
{% include 'cv/forms/formgroups/title.html' %}

{% block work_details %}{% endblock work_details%}
</div>
<div class="form-group row align-items-start ">
{% include 'cv/forms/formgroups/abstract.html' %}

{% block work_description %}{% endblock work_description %}
</div>

{% block formset %}{% endblock formset %}

{% block discipline %}
{% include 'cv/forms/formgroups/discipline.html' %}
{% endblock discipline %}

{% block grant %}
{% include 'cv/forms/formgroups/grant.html' %}
{% endblock grant %}

{% endblock formcontent %}
2 changes: 1 addition & 1 deletion cv/templates/cv/forms/award.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'cv/forms/_base.html' %}
{% extends 'cv/forms/_base_achievement.html' %}

{% load widget_tweaks %}

Expand Down
32 changes: 3 additions & 29 deletions cv/templates/cv/forms/collaborator.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
{% extends 'cv/forms/_base.html' %}
{% extends 'cv/forms/_base_person.html' %}

{% load widget_tweaks %}

{% block formcontent %}
<div class="form-group row">
<h5 class="col-12">Name</h5>
<span class="col-8 col-lg-4">
{% with form.first_name as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-4 col-lg-2">
{% with form.middle_initial as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-8 col-lg-5">
{% with form.last_name as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-4 col-lg-1">
{% with form.suffix as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
{% block other_information %}
<div class="form-group row">
<h5 class="col-12">Email</h5>
<span class="col-12 col-lg-6">
Expand All @@ -52,7 +29,4 @@ <h5 class="col-12">Other Information</h5>
{% endwith %}
</span>
</div>


{% endblock %}

{% endblock other_information %}
35 changes: 4 additions & 31 deletions cv/templates/cv/forms/course.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
{% extends 'cv/base.html' %}
{% extends 'cv/forms/_base_teaching.html' %}

{% block centerbar %}
<div id="course-add" class="alert alert-primary small">
<h2 class="display-4">{{method}} {{model}}</h2>
<form method="POST" id="{{model}}Form" class="post-form" action="">{% csrf_token %}
{% block formcontent %}
<div class="form-group row">
<span class="col-12 col-lg-6 row">
<span class="col-12">
{% with form.title as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-12">
{% with form.slug as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-6">
{% with form.student_level as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</span>
{% include 'cv/forms/formgroups/title.html' %}
</div>

<div class="form-group row">
<span class="col-12 col-lg-6">
<span class="col-12">
Expand Down Expand Up @@ -105,13 +87,4 @@ <h5 class="form-title col-12">Offerings</h5>
</div>
{% endfor %}
</div>
<div class="d-flex save-group btn-group justify-content-center justify-content-lg-start" role="group" aria-label="{{method}} {{model}}">
<button id="{{model}}FormSubmit" type="submit" class="btn btn-light">Save</button>
{% if method == "Edit" %}
<button href="{% url 'cv:cv_delete' model_name=model pk=form.instance.pk%}" class="btn btn-detail alert-danger cv-delete">Delete</button>
{% endif %}
</div>
</div>
</form>
</div>
{% endblock %}
4 changes: 0 additions & 4 deletions cv/templates/cv/forms/cv_add_form.html

This file was deleted.

1 change: 0 additions & 1 deletion cv/templates/cv/forms/cv_edit_form.html

This file was deleted.

3 changes: 1 addition & 2 deletions cv/templates/cv/forms/degree.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{% extends 'cv/forms/_base.html' %}
{% extends 'cv/forms/_base_achievement.html' %}

{% load widget_tweaks %}

{% block formcontent %}
<span class="invalid-feedback">{{form.non_field_errors}}</span>
<div class="form-group row align-items-start">
<div class="form-row col-12 col-lg-6">
<h5 class="form-title col-12">Degree Information</h5>
Expand Down
11 changes: 11 additions & 0 deletions cv/templates/cv/forms/formgroups/abstract.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% load widget_tweaks %}

<div class="col-12 col-lg-6 mt-3 form-row">
<h5 class="col-12 form-title">Abstract</h5>
<span class="col-12">
{% with form.abstract as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
<span class="form-text text-muted">Use <a href="https://daringfireball.net/projects/markdown/syntax" alt="Markdown syntax">Markdown syntax</a>: e.g., **<b>bold</b>**, *<i>italics</i>*, `<code>code</code>`, [link text]&lt;url&gt;</span>
</span>
</div>
19 changes: 19 additions & 0 deletions cv/templates/cv/forms/formgroups/discipline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load widget_tweaks %}

<div class="form-group row">
<h5 class="col-12 form-title">Disciplinary information</h5>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.primary_discipline as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.other_disciplines as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
</div>
31 changes: 31 additions & 0 deletions cv/templates/cv/forms/formgroups/grant.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% load widget_tweaks %}

<div class="form-group row">
<h5 class="col-12 form-title">Grant information</h5>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.grants as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>
<div class="col-12 col-lg-6 form-row">
<span class="col-12">
{% with form.pmcid as field %}{% with noprinthelp=True %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}{% endwith %}
</span>
<span class="col-12">
{% with form.pmid as field %}{% with noprinthelp=True %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}{% endwith %}
</span>
{% if form.pmid or form.pmcid %}
<span class="col-12">
<span class="form-text text-muted">
For information on the above see <a href="https://publicaccess.nih.gov/include-pmcid-citations.htm#Difference" title="The Difference Between a PMCID and a PMID">explanation from NIH</a>
</span>
</span>
{% endif %}
</div>
</div>
32 changes: 32 additions & 0 deletions cv/templates/cv/forms/formgroups/name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% load widget_tweaks %}

<div class="form-group row">
<h5 class="col-12">Name</h5>
<span class="col-8 col-lg-4">
{% with form.first_name as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-4 col-lg-2">
{% if form.middle_initial %}
{% with form.middle_initial as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
{% else %}
{% with form.middle_name as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
{% endif %}
</span>
<span class="col-8 col-lg-5">
{% with form.last_name as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-4 col-lg-1">
{% with form.suffix as field %}
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@
{% include "cv/forms/_form_field.html" %}
{% endwith %}
</span>
<span class="col-3 align-items-center pt-4">
Display: {{form.display}}
</span>
</div>

0 comments on commit 01850ba

Please sign in to comment.