Skip to content

Commit 4c9a1a4

Browse files
committed
Merge branch 'fix/files-from-edl' of github.com:betagouv/recommandations-collaboratives into develop
2 parents ab79cb7 + cec628e commit 4c9a1a4

7 files changed

Lines changed: 127 additions & 6 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import projects from '../../../fixtures/projects/projects.json';
2+
import file from '../../../fixtures/documents/file.json';
3+
4+
const currentProject = projects[1];
5+
6+
describe('I can fill a project survey @critical', () => {
7+
beforeEach(() => {
8+
cy.login('collectivité1');
9+
cy.visit(`/project/${currentProject.pk}`);
10+
});
11+
12+
it('fills up the survey and upload a file', () => {
13+
cy.visit(`/project/${currentProject.pk}`);
14+
15+
cy.get('[data-test-id="project-navigation-knowledge"]').click({
16+
force: true,
17+
});
18+
cy.get('[data-test-id="link-fill-survey"]').first().click({ force: true });
19+
20+
// cy.url().should('include', '/projects/survey/')
21+
22+
cy.get('#form_answer-1').check({ force: true });
23+
24+
cy.get('#input-project-comment')
25+
.type('Fake comment on first survey question', { force: true })
26+
.should('have.value', 'Fake comment on first survey question');
27+
28+
cy.get('[name="attachment"]').selectFile(file.path, { force: true });
29+
30+
cy.get('[data-test-id="button-submit-survey-questionset"]').click({
31+
force: true,
32+
});
33+
34+
cy.get('#form_answer-1').check({ force: true });
35+
36+
cy.get('#input-project-comment')
37+
.type('Fake comment on first survey question', { force: true })
38+
.should('have.value', 'Fake comment on first survey question');
39+
40+
41+
cy.get('[data-test-id="button-submit-survey-questionset"]').click({
42+
force: true,
43+
});
44+
45+
cy.get('[data-test-id="project-navigation-knowledge"]').click({
46+
force: true,
47+
});
48+
cy.url().should('include', '/connaissance');
49+
cy.contains('Propriété du site');
50+
cy.contains('100%');
51+
cy.contains('Fake comment on first survey question');
52+
});
53+
54+
it('can see and download the file', () => {
55+
cy.visit(`/project/${currentProject.pk}/documents`);
56+
57+
cy.contains('Fichier récupéré de l\'état des lieux');
58+
59+
// test download with cy verification
60+
// cy.get('[data-test-id="project-navigation-documents"]').click({
61+
// force: true,
62+
// });
63+
// cy.get('[data-test-id="download-attachment"]').click({ force: true });
64+
// cy.readFile(`${Cypress.config('downloadsFolder')}/ui-screenshot.png`)
65+
66+
67+
});
68+
});

frontend_tests/cypress/fixtures/settings/siteWithOnboardingAndSurvey.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"why": "Selon le type de propriétaire, les procédures, financements et acteurs à solliciter ne seront pas les mêmes pour renouveler le site.\r\n\r\nIl est généralement nécessaire de maîtriser le terrain d’une façon ou d’une autre pour permettre son renouvellement selon un scénario d’usage acceptable pour la collectivité :\r\n\r\n- soit en achetant le site (parfois pour un euro symbolique)\r\n- soit en le laissant en propriété privée mais en cadrant ses usages nouveaux (avec des documents d’urbanisme et de la négociation avec les propriétaires, par exemple)",
102102
"is_multiple": false,
103103
"deleted": null,
104-
"upload_title": "",
104+
"upload_title": "titre de propriété, acte de vente, bail, etc.",
105105
"comment_title": "Précisions éventuelles (propriétaire qui ne paie pas sa taxe foncière, complexités, droits d’usage etc.)"
106106
}
107107
},
@@ -119,7 +119,7 @@
119119
"why": "Pour anticiper les prescriptions éventuelles des services de l’État liés à la culture.\r\n\r\nCes services peuvent prescrire un diagnostic en fonction de la richesse pressentie du site, voire des fouilles archéologiques si le projet peut impacter les sols diagnostiqués.",
120120
"is_multiple": false,
121121
"deleted": null,
122-
"upload_title": "",
122+
"upload_title": "document archéologique, diagnostic, etc.",
123123
"comment_title": "Précisions éventuelles"
124124
}
125125
},

recoco/apps/projects/templates/projects/project/documents.html

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{% extends "projects/project/detail.html" %}
22
{% load humanize %}
33
{% load static %}
4+
{% load common_tags %}
5+
{% load survey %}
46
{% load gravatar %}
57
{% load guardian_tags %}
8+
{% load projects_extra %}
69
{% block title %}
710
Fichiers et liens - {{ block.super }}
811
{% endblock title %}
@@ -38,7 +41,44 @@ <h6 class="text-uppercase small fr-mb-0">
3841
{% include "projects/project/fragments/files_links/file_upload_button.html" with type="project" action=upload_action small=True %}
3942
{% endif %}
4043
</div>
41-
{% include "projects/project/fragments/files_links/file_list.html" with files=all_files %}
44+
{% include "projects/project/fragments/files_links/file_list.html" with files=all_files files_from_edl=answers_with_files.all %}
45+
{% for answer in answers_with_files.all %}
46+
{% if answer.attachment %}
47+
<div class="fr-mb-2w">
48+
<div class="rounded border fr-py-2v fr-px-2w fr-mb-2v d-flex align-items-center justify-content-between">
49+
<div class="d-flex align-items-center">
50+
<a class="d-flex align-items-center text-decoration-none"
51+
href="{{ answer.attachment.url }}"
52+
target="_new"
53+
download>
54+
<span class="fr-icon-file-line fr-icon--sm fr-mr-2v" aria-hidden="true"></span>
55+
<span class="text-info-custom text-black fr-ml-2v name">{{ answer.attachment|filename|truncatechars:30 }}</span>
56+
{% if answer.attachment.size %}
57+
<span class="text-info-custom text-black fr-ml-2v">({{ answer.attachment.size|filesizeformat }})</span>
58+
{% endif %}
59+
</a>
60+
</div>
61+
<div class="d-flex align-items-center">
62+
{% if "use_surveys" in user_project_perms %}
63+
<a class="fr-btn fr-btn--tertiary-no-outline fr-icon-download-line"
64+
href="{{ answer.attachment.url }}"
65+
data-test-id="download-attachment"
66+
target="_new"
67+
download></a>
68+
{% endif %}
69+
</div>
70+
</div>
71+
<div class="fr-pl-3w fr-ml-3w d-flex align-items-center">
72+
{% include "user/user_card.html" with user=answer.updated_by %}
73+
<span class="fr-ml-3w tiny d-flex align-items-center">
74+
<span class="fr-icon--sm fr-icon-calendar-event-line fr-mr-1v"
75+
aria-hidden="true"></span>
76+
{{ answer.updated_on|naturalday }}</span>
77+
<span class="fr-ml-3w tiny d-flex align-items-center">Fichier récupéré de l'état des lieux</span>
78+
</div>
79+
</div>
80+
{% endif %}
81+
{% endfor %}
4282
</div>
4383
<div class="col-4">
4484
<div class="d-flex align-items-center justify-content-between fr-mb-3w">

recoco/apps/projects/templates/projects/project/fragments/files_links/file_list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% if not search == False %}
33
<div x-data="Files({{ files.all.count }})" id="filesId">
44
{% include "projects/project/fragments/files_links/file_search.html" with files=files %}
5-
{% if files.count == 0 %}
5+
{% if files.count == 0 and files_from_edl.count == 0 %}
66
{% include "projects/project/fragments/files_links/empty_files.html" %}
77
{% else %}
88
<ul class="list d-flex flex-column list-unstyled">
@@ -14,7 +14,7 @@
1414
</div>
1515
{% else %}
1616
<div>
17-
{% if files.count == 0 %}
17+
{% if files.count == 0 and files_from_edl.count == 0 %}
1818
{% include "projects/project/fragments/files_links/empty_files.html" %}
1919
{% else %}
2020
<ul id="file-list" class="d-flex flex-column list-unstyled">

recoco/apps/projects/templates/projects/project/fragments/files_links/file_list_item.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</svg> {% endcomment %}
2323
<span class="fr-icon-file-line fr-icon--sm fr-mr-2v" aria-hidden="true"></span>
2424
<span class="text-info-custom text-black fw-medium description">{{ document.description|truncatechars:33 }}</span>
25-
<span class="text-info-custom text-black fr-ml-2v name">{{ document.filename|truncatechars:15 }}</span>
25+
<span class="text-info-custom text-black fr-ml-2v name">{{ document.filename|truncatechars:30 }}</span>
2626
{% if document and document.the_file.size %}
2727
<span class="text-info-custom text-black fr-ml-2v">({{ document.the_file.size|filesizeformat }})</span>
2828
{% endif %}

recoco/apps/projects/views/documents.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from django.shortcuts import get_object_or_404, redirect, render, reverse
1616
from django.utils import timezone
1717

18+
from recoco.apps.survey.models import Answer
1819
from recoco.utils import has_perm_or_403
1920

2021
from .. import models, signals
@@ -41,6 +42,11 @@ def document_list(request, project_id=None):
4142
pinned_files = all_files.filter(pinned=True)
4243
links = models.Document.objects.filter(project_id=project.pk).exclude(the_link=None)
4344

45+
# Fetch Answers from Surveys if they have attachments
46+
answers_with_files = Answer.objects.filter(session__project_id=project_id).exclude(
47+
attachment=""
48+
)
49+
4450
# Mark this project document notifications as read
4551
if not request.user.is_hijacked:
4652
project_ct = ContentType.objects.get_for_model(project)

recoco/templatetags/common_extra.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
created: 2023-06-27 15:52:06 CEST
88
"""
99

10+
import os
11+
1012
from django import template
1113

1214
from recoco import verbs
@@ -20,4 +22,9 @@ def get_verbs():
2022
return verbs
2123

2224

25+
@register.filter
26+
def filename(value):
27+
return os.path.basename(value.file.name)
28+
29+
2330
# eof

0 commit comments

Comments
 (0)