Skip to content

Commit

Permalink
Correction des "newlines" manquants en fin de fichier et des espaces …
Browse files Browse the repository at this point in the history
…en trop en fin de ligne (#71)

* Fix missing newlines at end of files and trailing spaces at end of lines

* Fix missing newlines at end of files and trailing spaces at end of lines

* Update commands and documentation

* Fix link in LICENSE

* Run pre-commit on all

* Fix warnings in js code

* Remove pre-commit
  • Loading branch information
Ash-Crow authored Oct 31, 2023
1 parent a709eed commit d825334
Show file tree
Hide file tree
Showing 57 changed files with 113 additions and 101 deletions.
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
exclude: 'dsfr/static/dsfr/dist'
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.283
rev: v0.1.3
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.10.1
hooks:
- id: black
language_version: python3.10
args:
- --line-length=88
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.5
hooks:
- id: bandit
language_version: python3
Expand Down
12 changes: 10 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ L’installation a été testée sur Ubuntu 22.04 avec Python 3.10 et poetry ins

- Faire un `git clone` du projet sur votre machine et ouvrir un terminal

- Installer l’environnement virtuel, les dépendances et initialiser le site d’exemple :
- Installer l’environnement virtuel, les dépendances, les *pre-commit hooks* et initialiser le site d’exemple :
```
make init
```
Expand Down Expand Up @@ -62,9 +62,17 @@ Pour vérifier son code, on peut intégrer le linter adapté à son IDE et aussi
make checkstyle
```

Une vérification automatique est faite via des *pre-commit hooks*, qui ont normalement été installés via le `make init`.

Il est possible de les mettre à jour avec la commande :

```
pre-commit update
```

## Mise à jour du système de design

Quand une nouvelle version du système de design de l’État est publiée, il est possible de le mettre à jour automatiquement via la commande
Quand une nouvelle version du système de design de l’État est publiée, il est possible de le mettre à jour automatiquement via la commande
```
make update_dsfr
```
Expand Down
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Le contenu de ce dépôt est placé sous licence MIT License, à l'exception de la fonte Marianne.
Voir les [conditions générales d'utilisation](doc/legal/cgu.md)
Le contenu de ce dépôt est placé sous licence MIT, à l’exception de la fonte Marianne.

Voir les [conditions générales d’utilisation](https://github.com/GouvernementFR/dsfr/blob/main/doc/legal/cgu.md)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ endif

# Commands
checkstyle:
poetry run ruff check .
poetry run pre-commit run --all-files

init:
poetry install
poetry run pre-commit install
poetry run python manage.py migrate
poetry run python manage.py collectstatic --noinput
poetry run python manage.py import_sample_data
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Quick start
"dsfr",
<your_app>
]

3. In order to use forms and formsets, add to INSTALLED_APPS in your settings.py::

INSTALLED_APPS = [
Expand All @@ -52,7 +52,7 @@ Quick start
4. Add the following info in the TEMPLATES section in your settings.py so that the choice forms work::

TEMPLATES = [
{
{
[...]
"DIRS": [
os.path.join(BASE_DIR, "dsfr/templates"),
Expand Down Expand Up @@ -81,4 +81,4 @@ Quick start

7. Include the tags in your base.html file (see example file at https://github.com/entrepreneur-interet-general/django-dsfr/blob/main/example_app/templates/example_app/base.html)

8. Start the development server and visit http://127.0.0.1:8000/
8. Start the development server and visit http://127.0.0.1:8000/
2 changes: 1 addition & 1 deletion dsfr/fixtures/init.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"mourning": false,
"accessibility_status": "NOT"
}
}]
}]
1 change: 0 additions & 1 deletion dsfr/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand Down
1 change: 0 additions & 1 deletion dsfr/migrations/0002_auto_20211209_1557.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("dsfr", "0001_initial"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
("dsfr", "0002_auto_20211209_1557"),
]
Expand Down
42 changes: 21 additions & 21 deletions dsfr/static/formsets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ try {
div_remove.remove();
}
}
catch (TypeError) {}
catch (error) {}

let firstForm = formsetGroup[0].cloneNode(true); // Clone the formset

addButton.addEventListener('click', addForm);

function addForm(e) {
// Add a form to the formset

e.preventDefault();

let newForm
Expand All @@ -29,30 +29,30 @@ function addForm(e) {
} else {
newForm = firstForm; // If all other forms have been deleted
}

// Regex
let formRegex = RegExp(`\\w+-(\\d+)-`,'g'); // Regex to find all instances of the form number
let idRemoveFormRegex = RegExp(`remove-(\\d+)`,'g'); // Regex to find all instances of the form number on remove link
let idRemoveFunctionRegex = RegExp(`removeFormset\\((\\d+)\\)`,'g'); // Regex to find all instances of the form number on remove function in link
let formRegex = /\w+-(\d+)-/g; // Regex to find all instances of the form number
let idRemoveFormRegex = /remove-(\d+)/g; // Regex to find all instances of the form number on remove link
let idRemoveFunctionRegex = /removeFormset\((\d+)\)/g; // Regex to find all instances of the form number on remove function in link

// Get the number of the last form on the page
formsetGroup = document.querySelectorAll(".formset");

let last_number = 0;
if (formsetGroup.length > 0){
last_form = formsetGroup[formsetGroup.length-1]; // Get the last form in the formset
last_number = last_form.innerHTML.match(/\w+-(\d+)-\w+/)[1]; // Get the form number in the last form with a regex (fields in the form have an id following the pattern "form-X-...." where X is the number of the form)
} else {
last_number = 0;
let last_form = formsetGroup[formsetGroup.length-1]; // Get the last form in the formset
last_number = /\w+-(\d+)-\w+/.exec(last_form.innerHTML)[1]; // Get the form number in the last form with a regex (fields in the form have an id following the pattern "form-X-...." where X is the number of the form)
}
newNumber = parseInt(last_number)+1; // Number of the new form


let newNumber = parseInt(last_number)+1; // Number of the new form

// Replace last number by new number in newForm
newForm.innerHTML = newForm.innerHTML.replace(formRegex, `form-${newNumber}-`); // Update the new form to have the correct form number
newForm.setAttribute('id', `formset-${newNumber}`); // Update the new form to have the correct form id
newForm.innerHTML = newForm.innerHTML.replace(idRemoveFormRegex, `remove-${newNumber}`); // Update the new form to have the correct form number on remove link
newForm.innerHTML = newForm.innerHTML.replace(idRemoveFunctionRegex, `removeFormset\(${newNumber}\)`); // Update the new form to have the correct form number on remove function in link
newForm.innerHTML = newForm.innerHTML.replace(idRemoveFunctionRegex, `removeFormset(${newNumber})`); // Update the new form to have the correct form number on remove function in link

// Insert the new form at the end of the list of forms
container.insertBefore(newForm, addButton);

Expand All @@ -62,14 +62,14 @@ function addForm(e) {

function removeFormset(numFormset){
// Remove a form from the formset thanks to the form id

// Get the form by its id
var form_id = "formset-" + numFormset;
var form = document.getElementById(form_id);
let form_id = "formset-" + numFormset;
let form = document.getElementById(form_id);

// Remove the form from the formset
form.remove();

// Update total number of forms in the management form
formsetGroup = document.querySelectorAll(".formset");
totalForms.setAttribute('value', `${formsetGroup.length}`);
Expand Down
2 changes: 1 addition & 1 deletion dsfr/templates/django/forms/widgets/checkbox_option.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
{% endif %}
</label>
{% endif %}
{% if widget.attrs.dsfr == "dsfr" %}</div>{% endif %}
{% if widget.attrs.dsfr == "dsfr" %}</div>{% endif %}
2 changes: 1 addition & 1 deletion dsfr/templates/django/forms/widgets/multiple_input.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{% include option.template_name with widget=option %}
{% endfor %}
{% endfor %}
{% endwith %}
{% endwith %}
2 changes: 1 addition & 1 deletion dsfr/templates/django/forms/widgets/radio_option.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
{% endif %}
</label>
{% endif %}
{% if widget.attrs.dsfr == "dsfr" %}</div>{% endif %}
{% if widget.attrs.dsfr == "dsfr" %}</div>{% endif %}
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/accordion.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<div class="fr-collapse" id="{{ self.id }}">
{{ self.content | safe }}
</div>
</section>
</section>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/alert.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
</button>
{% endif %}
</div>
{% if self.is_collapsible %}</div>{% endif %}
{% if self.is_collapsible %}</div>{% endif %}
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/badge.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p class="fr-badge{% if self.extra_classes %} {{ self.extra_classes }}{% endif %}">{{ self.label }}</p>
<p class="fr-badge{% if self.extra_classes %} {{ self.extra_classes }}{% endif %}">{{ self.label }}</p>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/badge_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
{% dsfr_badge item %}
</li>
{% endfor %}
</ul>
</ul>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
{% dsfr_js nonce=request.csp_nonce %}
{% block extra_js %}{% endblock extra_js %}
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/breadcrumb.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
</li>
</ol>
</div>
</nav>
</nav>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
{% if self.name %}name="{{ self.name }}"{% endif %}
>
{{ self.label }}
</button>
</button>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/callout.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
<a href="{{ self.button.url }}" class="fr-btn">{{ self.button.label }}</a>
{% endif %}
{% endif %}
</div>
</div>
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/favicon.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<link rel="apple-touch-icon" href="{% static 'dsfr/dist/favicon/apple-touch-icon.png' %}" integrity="{{ self.INTEGRITY_FAVICON_APPLE }}" /><!-- 180×180 -->
<link rel="icon" href="{% static 'dsfr/dist/favicon/favicon.svg' %}" type="image/svg+xml" integrity="{{ self.INTEGRITY_FAVICON_SVG }}" />
<link rel="shortcut icon" href="{% static 'dsfr/dist/favicon/favicon.ico' %}" type="image/x-icon" integrity="{{ self.INTEGRITY_FAVICON_ICO }}" /><!-- 32×32 -->
<link rel="manifest" href="{% static 'dsfr/dist/favicon/manifest.webmanifest' %}" crossorigin="use-credentials" integrity="{{ self.INTEGRITY_FAVICON_MANIFEST }}" />
<link rel="manifest" href="{% static 'dsfr/dist/favicon/manifest.webmanifest' %}" crossorigin="use-credentials" integrity="{{ self.INTEGRITY_FAVICON_MANIFEST }}" />
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
</div>
</div>
</div>
</footer>
</footer>
14 changes: 7 additions & 7 deletions dsfr/templates/dsfr/form_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{% comment %}
Radio button and multiple checkboxes :
-Help text under each button/checkbox :
-Help text under each button/checkbox :
In your forms.py, in the ChoiceField or MultipleChoiceField,
instead of choices=(("a", "label a"), ("b", "label b"), ...),
put choices=(("a", {"label":"label a", "help_text":"help text a"}), ("b", {"label":"label b", "help_text":"help text b"})),
Expand All @@ -32,7 +32,7 @@
<div id="form">
<form method="POST" enctype="multipart/form-data" id="form-base">
{% csrf_token %}

{# Everything that needs to be in the form but before the fields (form title for example) #}
{% block head_form %}
{% endblock head_form %}
Expand All @@ -46,23 +46,23 @@
{# Everything that needs to be in the for loop #}
{% block inside_form %}
{% endblock inside_form %}

{% include "dsfr/form_field_snippets/field_snippet.html" %}
{% endfor %}

{# If you need to add formsets after the form #}
{% block extra_formset_after %}
{% endblock extra_formset_after %}

{# Everything that needs to be in the form but after the fields (the buttons for example) #}
<div class="foot-form">
<div class="foot-form">
{% block foot_form %}
{% endblock foot_form %}
</div>
</form>
</div>

{# Everything that needs to be outside the form, after #}
{% block after_form %}
{% endblock after_form %}
{% endblock content %}
{% endblock content %}
4 changes: 2 additions & 2 deletions dsfr/templates/dsfr/form_field_snippets/checkbox_snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
{% else %}
{{ field|attr:"type:checkbox" }}
{% endif %}

<label for="{{ field.id_for_label }}" class="fr-label">
{{ field.label_tag }}
{% if field.help_text %}
<span class="fr-hint-text">{{ field.help_text }}</span>
{% endif %}
</label>

{% if field.errors %}
<div id="{{ field.auto_id }}-desc-error" class="fr-error-text">
{{ field.errors }}
Expand Down
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/form_snippet.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% for field in form %}
{% include "dsfr/form_field_snippets/field_snippet.html" %}
{% endfor %}
{% endfor %}
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/formset_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<br/>
{% endif %}
{% endblock form_set %}

{% block extra_js %}
<script src="{% static 'formsets.js' %}"></script>
{% endblock %}
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/global_css.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
<link rel="stylesheet" href="{% static 'dsfr/dist/dsfr/dsfr.min.css' %}" integrity="{{ self.INTEGRITY_CSS }}">
<link rel="stylesheet" href="{% static 'dsfr/dist/utility/icons/icons.min.css' %}" integrity="{{ self.INTEGRITY_CSS_ICONS }}">

<meta name="theme-color" content="#000091"><!-- Définit la couleur de thème du navigateur (Safari/Android) -->
<meta name="theme-color" content="#000091"><!-- Définit la couleur de thème du navigateur (Safari/Android) -->
2 changes: 1 addition & 1 deletion dsfr/templates/dsfr/global_js.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% load static %}
<script type="module" src="{% static 'dsfr/dist/dsfr/dsfr.module.min.js' %}" integrity="{{ self.INTEGRITY_JS_MODULE }}"{% if self.nonce %} nonce="{{self.nonce}}"{% endif %}></script>
<script nomodule src="{% static 'dsfr/dist/dsfr/dsfr.nomodule.min.js' %}" integrity="{{ self.INTEGRITY_JS_NOMODULE }}" {% if self.nonce %} nonce="{{self.nonce}}"{% endif %}></script>
<script nomodule src="{% static 'dsfr/dist/dsfr/dsfr.nomodule.min.js' %}" integrity="{{ self.INTEGRITY_JS_NOMODULE }}" {% if self.nonce %} nonce="{{self.nonce}}"{% endif %}></script>
Loading

0 comments on commit d825334

Please sign in to comment.