Skip to content

Commit

Permalink
Merge pull request #161 from elixir-luxembourg/25-compact-editor-forms
Browse files Browse the repository at this point in the history
closes: 25 compact editor forms
  • Loading branch information
jLebioda authored Apr 27, 2020
2 parents 5152570 + 0ae0fdb commit 91578ba
Show file tree
Hide file tree
Showing 37 changed files with 198 additions and 156 deletions.
11 changes: 7 additions & 4 deletions core/forms/access.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.forms import ModelForm, DateInput, ChoiceField
from django.forms import ModelForm, DateInput, ChoiceField, Textarea

from core.models import Access, DataLocation

Expand All @@ -11,7 +11,9 @@ class Meta:
widgets = {
# Date pickers
'granted_on': DateInput(attrs={'class': 'datepicker'}),
'grant_expires_on': DateInput(attrs={'class': 'datepicker'})
'grant_expires_on': DateInput(attrs={'class': 'datepicker'}),
# Textareas
'access_notes': Textarea(attrs={'rows': 2, 'cols': 40}),
}

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -40,7 +42,9 @@ class Meta:
widgets = {
# Date pickers
'granted_on': DateInput(attrs={'class': 'datepicker'}),
'grant_expires_on': DateInput(attrs={'class': 'datepicker'})
'grant_expires_on': DateInput(attrs={'class': 'datepicker'}),
# Textareas
'access_notes': Textarea(attrs={'rows': 2, 'cols': 40}),
}

field_order = [
Expand All @@ -56,4 +60,3 @@ def __init__(self, *args, **kwargs):
# we don't allow editing dataset
self.fields.pop('dataset')
self.fields['defined_on_locations'].choices = [(d.id, d) for d in kwargs['instance'].dataset.data_locations.all()]

5 changes: 4 additions & 1 deletion core/forms/cohort.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.forms import ModelForm
from django.forms import ModelForm, Textarea

from core.forms.input import SelectWithModal
from core.models import Cohort
Expand All @@ -8,6 +8,9 @@ class CohortForm(ModelForm):
class Meta:
model = Cohort
fields = '__all__'
widgets = {
'comments': Textarea(attrs={'rows': 2, 'cols': 40}),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
5 changes: 4 additions & 1 deletion core/forms/contract.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.forms import ModelForm, ModelChoiceField
from django.forms import ModelForm, ModelChoiceField, Textarea
from django.utils.text import slugify

from core.forms.input import SelectWithModal
Expand All @@ -11,6 +11,9 @@ class Meta:
model = Contract
fields = '__all__'
exclude = ['partners_roles']
widgets = {
'comments': Textarea(attrs={'rows': 2, 'cols': 40}),
}

def __init__(self, *args, **kwargs):
kwargs['label_suffix'] = ""
Expand Down
6 changes: 5 additions & 1 deletion core/forms/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class DatasetForm(forms.ModelForm):
class Meta:
model = Dataset
fields = ['local_custodians', 'title', 'comments']
widgets = {
'comments': forms.Textarea(attrs={'rows': 2, 'cols': 40}),
}


def __init__(self, *args, **kwargs):
dataset = None
Expand Down Expand Up @@ -70,7 +74,7 @@ def save(self, commit=True):
class DatasetFormEdit(DatasetForm):

class Meta(DatasetForm.Meta):
fields = DatasetForm.Meta.fields +['other_external_id', 'sensitivity']
fields = DatasetForm.Meta.fields + ['other_external_id', 'sensitivity']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
8 changes: 4 additions & 4 deletions core/forms/document.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django import forms
from django.forms import DateInput, Textarea

from core.models import Document
from core.forms.input import CustomClearableFileInput
from django.forms import DateInput


class DocumentForm(forms.ModelForm):
Expand All @@ -13,10 +14,9 @@ class Meta:
'content': CustomClearableFileInput,
'content_type': forms.HiddenInput(),
'object_id': forms.HiddenInput(),
'expiry_date': DateInput(attrs={'class': 'datepicker'})
'expiry_date': DateInput(attrs={'class': 'datepicker'}),
'content_notes': Textarea(attrs={'rows': 2, 'cols': 40}),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


8 changes: 6 additions & 2 deletions core/forms/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class Meta:
# Date pickers
'start_date': DateInput(attrs={'class': 'datepicker'}),
'end_date': DateInput(attrs={'class': 'datepicker'}),
# Smaller text-areas
'description': forms.Textarea(attrs={'rows': 6, 'cols': 40}),
'cner_notes': forms.Textarea(attrs={'rows': 2, 'cols': 40}),
'erp_notes': forms.Textarea(attrs={'rows': 2, 'cols': 40}),
'comments': forms.Textarea(attrs={'rows': 2, 'cols': 40}),
'dpia': forms.Textarea(attrs={'rows': 2, 'cols': 40})
}
exclude = ['publications', 'contacts']

Expand Down Expand Up @@ -129,5 +135,3 @@ class Meta:
heading_help = 'Select the the dataset the project uses.'

dataset = forms.ModelChoiceField(queryset=Dataset.objects.all(), help_text='Select the dataset.')


5 changes: 3 additions & 2 deletions core/forms/share.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from django.forms import ModelForm, DateInput
from django.forms import ModelForm, DateInput, Textarea

from core.models import Share, Partner, Contract, PartnerRole

Expand All @@ -12,7 +12,8 @@ class Meta:
widgets = {
# Date pickers
'granted_on': DateInput(attrs={'class': 'datepicker'}),
'grant_expires_on': DateInput(attrs={'class': 'datepicker'})
'grant_expires_on': DateInput(attrs={'class': 'datepicker'}),
'share_notes': Textarea(attrs={'rows': 2, 'cols': 40}),
}
help_texts = {
'contract': ''
Expand Down
5 changes: 5 additions & 0 deletions web/static/css/daisy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,8 @@ body {
color: #d9d9d9;
font-weight: bolder;
}

/* Reduce padding in forms */
form.col-md-12.nice-selects > .form-group.bmd-form-group {
padding-top: 0.75rem;
}
1 change: 0 additions & 1 deletion web/templates/_includes/field.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{% load widget_tweaks %}

<div class="form-group {% if field.field.required %}required{% endif %}">

{% if field.field.widget.input_type == 'checkbox' %}
{% include '_includes/checkbox.html' %}
{% elif field.field.widget.input_type == 'radio' %}
Expand Down
33 changes: 20 additions & 13 deletions web/templates/_includes/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@
</button>
</div>
{% endfor %}
<form {% if form_id %}id="{{ form_id }}"{% endif %}class="form {% if half %}col-md-6{% else %}col-md-12{% endif %} nice-selects {{ form_class }}"
{% if enctype %}enctype="{{ enctype }}"{% endif %} method="post"
{% if submit_url %}action="{{ submit_url }}"{% endif %}novalidate>
{% csrf_token %}
{% for hidden_field in form.hidden_fields %}
{{ hidden_field }}
{% endfor %}
{% for field in form.visible_fields %}
{% include '_includes/field.html' with field=field %}
{% endfor %}

<form {% if form_id %}id="{{ form_id }}"{% endif %}
class="form {% if half %}col-md-6{% else %}col-md-12{% endif %} nice-selects {{ form_class }}"
method="post" novalidate
{% if enctype %}enctype="{{ enctype }}"{% endif %}
{% if submit_url %}action="{{ submit_url }}"{% endif %}>

{% csrf_token %}

{% for hidden_field in form.hidden_fields %}
{{ hidden_field }}
{% endfor %}

{% for field in form.visible_fields %}
{% include '_includes/field.html' with field=field %}
{% endfor %}
{% if not hide_submit %}
{% if wizard and wizard_url_name %}
<div class="row">
Expand All @@ -33,10 +39,11 @@
{% else %}
<button type="submit"
{% if submit_disabled %}disabled="disabled"{% endif %}
class="btn btn-primary btn-raised">{{ submit_label | default:"Submit" }}</button>
class="btn btn-primary btn-raised btn-block">{{ submit_label | default:"Submit" }}</button>
{% endif %}
{% endif %}
{% if cancel_button %}
<a href="{{ cancel_button }}" class="btn btn-secondary btn-raised float-right">Cancel</a>
<a href="{{ cancel_button }}" class="btn btn-secondary btn-block btn-raised float-right">Cancel</a>
{% endif %}
</form>

</form>
51 changes: 30 additions & 21 deletions web/templates/_includes/search_form.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
<div class="row">
<h1 class="display-4">Search {{title}}</h1>
<h1 class="display-4">
Browse {{title}}
</h1>
</div>
<div class="row">
<div class="col">
<form class="form-inline" method="get" action="{% url url %}">
<div class="form-group">
<label for="query" class="bmd-label-floating">
&nbsp;<i class="material-icons">search</i> Query
</label>
<input type='text' class="form-control border border-top-0 bg-white" name='query' value='{{ query }}'/>
<div class="col-md-12 col-lg-11">
<div class="row">
<div class="col-xl-5 col-lg-12">
<form class="form-inline" method="get" action="{% url url %}">
<div class="form-group">
<label for="query" class="bmd-label-floating">
&nbsp;<i class="material-icons">search</i> Query
</label>
<input type='text' class="form-control border border-top-0 bg-white" name='query' value='{{ query }}'/>
</div>
<span class="form-group bmd-form-group"> <!-- needed to match padding for floating labels -->
<button type="submit" class="btn btn-primary">Search</button>
</span>
</form>
</div>

<div class="col-xl-7 col-lg-12 mt-4 mb-2">
{% if order_by_fields %}
<div class="mr-auto float-right">
<div class="btn-group-sm" role="group">
{% for field in order_by_fields %}
{% orderbylink search_url field %}
{% endfor %}
</div>
</div>
{% endif %}
</div>
<span class="form-group bmd-form-group"> <!-- needed to match padding for floating labels -->
<button type="submit" class="btn btn-primary">Search</button>
</span>
</form>
</div>
{% if order_by_fields %}
<div class="col mr-auto">
<div class="btn-group" role="group">
{% for field in order_by_fields %}
{% orderbylink search_url field %}
{% endfor %}
</div>
</div>
{% endif %}
</div>
</div>
2 changes: 1 addition & 1 deletion web/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1 class="display-4">About</h1>
</div>
</div>

<div class="card">
<div class="card row">
<div class="card-body">
<div class="col">
<dd>
Expand Down
4 changes: 2 additions & 2 deletions web/templates/cohorts/cohort_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Cohort - Add{% endblock %}

{% block content %}
<div class="jumbotron mt-4">
<div class="jumbotron mt-4 {% block jumbotron_class %}{% endblock %}">
<h1 class="display-4">{% block content_title %}Cohort{% endblock %}</h1>
</div>
<div class="card">
Expand All @@ -14,4 +14,4 @@ <h2 class="card-title">{% block card_title %}Add cohort{% endblock %}</h2>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
7 changes: 4 additions & 3 deletions web/templates/cohorts/cohort_form_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends 'cohorts/cohort_form.html' %}

{% block title %}Cohort - Edit{% endblock %}
{% block card_title %}Edit cohort{% endblock %}
{% block content_title %}Cohort "<strong>{{ cohort.title }}</strong>"{% endblock %}
{% block title %}{% endblock %}
{% block card_title %}Edit cohort - <strong>{{ cohort.title }}</strong>{% endblock %}
{% block jumbotron_class %}d-none{% endblock %}
{% block content_title %}Cohort {{ cohort.title }}{% endblock %}
4 changes: 2 additions & 2 deletions web/templates/contacts/contact_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Contact - Add{% endblock %}

{% block content %}
<div class="jumbotron mt-4">
<div class="jumbotron mt-4 {% block jumbotron_class %}{% endblock %}">
<h1 class="display-4">{% block content_title %}Contacts{% endblock %}</h1>
</div>
<div class="card">
Expand All @@ -17,4 +17,4 @@ <h2 class="card-title">{% block card_title %}Add a new contact{% endblock %}</h2
</div>


{% endblock %}
{% endblock %}
7 changes: 4 additions & 3 deletions web/templates/contacts/contact_form_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends 'contacts/contact_form.html' %}

{% block title %}Contact - Edit - {{ contact.full_name }}{% endblock %}
{% block card_title %}Edit contact{% endblock %}
{% block content_title %}{{ contact.full_name }}{% endblock %}
{% block title %}{% endblock %}
{% block jumbotron_class %}d-none{% endblock %}
{% block card_title %}Edit contact - <strong>{{ contact.full_name }}</strong>{% endblock %}
{% block content_title %}{{ contact.full_name }}{% endblock %}
4 changes: 2 additions & 2 deletions web/templates/contracts/contract_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Contract - Add{% endblock %}

{% block content %}
<div class="jumbotron mt-4">
<div class="jumbotron mt-4 {% block jumbotron_class %}{% endblock %}">
<h1 class="display-4">{% block content_title %}Contracts{% endblock %}</h1>
</div>
<div class="card">
Expand All @@ -14,4 +14,4 @@ <h2 class="card-title">{% block card_title %}Add contract{% endblock %}</h2>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
7 changes: 4 additions & 3 deletions web/templates/contracts/contract_form_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends 'contracts/contract_form.html' %}

{% block title %}Contract - Edit{% endblock %}
{% block card_title %}Edit contract{% endblock %}
{% block content_title %}{{ contract }}{% endblock %}
{% block title %}{% endblock %}
{% block jumbotron_class %}d-none{% endblock %}
{% block card_title %}Edit - <strong>{{ contract }}</strong>{% endblock %}
{% block content_title %}{{ contract }}{% endblock %}
2 changes: 1 addition & 1 deletion web/templates/datasets/dataset.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ <h1>{{ dataset.title }}</h1>
<h2 class="card-title">Data declarations</h2>

{% if dataset.data_declarations.all %}
<div class="table table-responsive">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions web/templates/datasets/dataset_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block title %}Dataset - Add{% endblock %}

{% block content %}
<div class="jumbotron mt-4">
<div class="jumbotron mt-4 {% block jumbotron_class %}{% endblock %}">
<h1 class="display-4">{% block content_title %}Datasets{% endblock %}</h1>
</div>
<div class="card">
Expand All @@ -16,4 +16,4 @@ <h2 class="card-title">{% block card_title %}Add dataset{% endblock %}</h2>
</div>


{% endblock %}
{% endblock %}
7 changes: 4 additions & 3 deletions web/templates/datasets/dataset_form_edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends 'datasets/dataset_form.html' %}

{% block title %}Dataset - Edit - {{ dataset.title }}{% endblock %}
{% block card_title %}Edit dataset - {{ dataset.title }}{% endblock %}
{% block content_title %}{{ dataset.title }}{% endblock %}
{% block title %}{% endblock %}
{% block jumbotron_class %}d-none{% endblock %}
{% block card_title %}Edit dataset - <strong>{{ dataset.title }}</strong>{% endblock %}
{% block content_title %}{{ dataset.title }}{% endblock %}
Loading

0 comments on commit 91578ba

Please sign in to comment.