Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

YC-1136 #859

Merged
merged 26 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b2407a9
WIP remake contacts to use the db instead of being an enum.
AlexandreJunod Aug 3, 2023
2539427
wip
AlexandreJunod Aug 9, 2023
ad006b1
add some small fixes and fix contact summary
AlexandreJunod Aug 9, 2023
be3902b
fix ux for multiple contacts
AlexandreJunod Aug 14, 2023
d76be19
adapt api and sections of report
AlexandreJunod Aug 14, 2023
df2df64
fix reports
AlexandreJunod Aug 15, 2023
26d6999
fix report tests
AlexandreJunod Aug 15, 2023
91ef7fb
add factory for ContactType
AlexandreJunod Aug 15, 2023
0237f89
fix mistake of factory model
AlexandreJunod Aug 15, 2023
e05e625
fix test
AlexandreJunod Aug 17, 2023
dc7487c
fix test
AlexandreJunod Aug 17, 2023
4ef904c
squash migration
AlexandreJunod Aug 17, 2023
15a9486
rebase + fix node leaf
AlexandreJunod Aug 17, 2023
180ed31
fix missing migration from develop....
AlexandreJunod Aug 17, 2023
e4934f6
change the choicefield to int, then migrate the data as int, then mak…
AlexandreJunod Aug 22, 2023
6f5bf1b
fix typo
AlexandreJunod Aug 22, 2023
bde037e
manage de case when there's no type
AlexandreJunod Aug 22, 2023
982ee2b
try a fix for cannot ALTER TABLE X because it has pending trigger events
AlexandreJunod Aug 23, 2023
5028a7a
fix attempt
AlexandreJunod Aug 23, 2023
cd37b0a
fix attempt
AlexandreJunod Aug 23, 2023
caaa4c8
add on_delete on models fk
AlexandreJunod Aug 23, 2023
ccd628b
fix case where 0 is interpreted at None in migration
AlexandreJunod Aug 23, 2023
569555b
add data migration for reports
AlexandreJunod Aug 23, 2023
27f88e4
get pk instead of object in data migration
AlexandreJunod Aug 23, 2023
4d0c9c7
Fix order on migration
AlexandreJunod Aug 23, 2023
b658404
inform the limit of contacts is reached
AlexandreJunod Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion geocity/admin_jazzmin_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"constance.Config": "fas fa-cogs",
"django_cron.CronJobLog": "fas fa-tasks",
"forms.AdministrativeEntityForAdminSite": "fas fa-landmark",
"forms.ContactTypeForAdminSite": "fas fa-address-card",
"forms.ContactFormForAdminSite": "fas fa-address-card",
"forms.ContactTypeForAdminSite": "fas fa-hard-hat",
"forms.PaymentSettings": "fas fa-shopping-cart",
"forms.Price": "fas fa-coins",
"forms.Field": "fas fa-list-ol",
Expand Down
2 changes: 1 addition & 1 deletion geocity/apps/accounts/permissions_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"form",
"field",
"formfield",
"contacttypeforadminsite",
"contactformforadminsite",
"paymentsettings",
"price",
"formprice",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h3>{% translate "Mon compte" %}</h3>
<label class="col-md-3 col-form-label" for="id_chk_accept_policy">{% translate "Conditions d'utilisation" %}</label>
<div class="col-md-9 login-policy">
<input type="checkbox" id="chk_accept_policy" name="chk_accept_policy">
<label for="chk_accept_policy">{% translate "J'ai lu et accepte les" %} <b><a href="{{config.GENERAL_CONDITIONS_URL}}" target="_blank" rel="noreferrer">{% translate "conditions d'utilisation" %}</a></b> {% translate "et la" %} <b><a href="{{config.PRIVACY_POLICY_URL}}" target="_blank" rel="noreferrer">{% translate "politique de confidentialité" %}</a></b>.</label><br>
<label for="chk_accept_policy">{% translate "J'ai lu et accepte les" %} <b><a href="{{config.GENERAL_CONDITIONS_URL}}" target="_blank" rel="noreferrer">{% translate "conditions d'utilisation de Geocity" %}</a></b> {% translate "et la" %} <b><a href="{{config.PRIVACY_POLICY_URL}}" target="_blank" rel="noreferrer">{% translate "politique de confidentialité" %}</a></b>.</label><br>
</div>
</div>
{% bootstrap_button "Confirmer" button_type="submit" id="user_profile_edit" button_class="btn-primary mr-3" value="Enregistrer" name="disabled"%}
Expand Down
18 changes: 13 additions & 5 deletions geocity/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,23 @@ def to_representation(self, value):
rep = {}
for submission_contact in value.submission_contacts.select_related("contact"):
contact_object = {
"contact_type_display": submission_contact.get_contact_type_display()
"contact_form_display": submission_contact.contact_form.name
}
for field in submission_contact.contact._meta.fields:
contact_object[field.name] = getattr(
submission_contact.contact, field.name
)
rep[
convert_string_to_api_key(submission_contact.get_contact_type_display())
] = contact_object
if (
not convert_string_to_api_key(submission_contact.contact_form.name)
in rep
):
rep[
convert_string_to_api_key(submission_contact.contact_form.name)
] = list()

rep[convert_string_to_api_key(submission_contact.contact_form.name)].append(
contact_object
)

return rep

Expand Down Expand Up @@ -629,7 +637,7 @@ class SubmissionPrintSerializer(gis_serializers.GeoFeatureModelSerializer):

def get_creditor_type(self, obj):
if obj.creditor_type is not None:
creditor = obj.get_creditor_type_display()
creditor = obj.creditor_type.name
elif obj.author:
creditor = (
_("Auteur de la demande, ")
Expand Down
27 changes: 22 additions & 5 deletions geocity/apps/core/static/js/submission_contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,33 @@ let update_form_value = function(item, userprofile) {
}
}

// Create a label to replace "readonly hidden select" readonly
// Create a label to replace .form-control without .extra-form in classes inside of forms-container
window.addEventListener('load', function () {
var selects = document.querySelectorAll("select[readonly][hidden]");
for (select of selects) {
var forms_control = document.querySelectorAll("[id=forms-container] select[class=form-control]");
for (form_control of forms_control) {
let elem = document.createElement('label');
let text = select.querySelector("option[selected]").text
let div = select.closest('.col-md-9');
let text = form_control.querySelector("option[selected]").text
let div = form_control.closest('.col-md-9');

elem.innerHTML = text;
elem.classList.add('col-form-label', 'bold');
div.appendChild(elem);
}

// Hide .extra-form and show first hidden .extra-form on click of .show-extra-form
var extra_forms = document.querySelectorAll("[id=forms-container] select.form-control.extra-form");
for (extra_form of extra_forms) {
let form = extra_form.closest("[class=contact-form]")
form.setAttribute("hidden", true)
}

// addEventListener for button .show-extra-form
var button = document.querySelector("button.show-extra-form");
button.addEventListener("click", (event) => {
var hidden_extra_forms = document.querySelector(".contact-form[hidden]")
if (hidden_extra_forms == null){
document.getElementById('contact-alert').style.display = "block"
}
hidden_extra_forms.removeAttribute("hidden")
});
AlexandreJunod marked this conversation as resolved.
Show resolved Hide resolved
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.1 on 2023-08-02 13:49

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("forms", "0022_datamigration_form_and_field_api_name_and_input_type"),
]

operations = [
migrations.AlterField(
model_name="form",
name="category",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="forms",
to="forms.formcategory",
verbose_name="catégorie",
),
),
migrations.DeleteModel(
name="ContactTypeForAdminSite",
),
]
38 changes: 38 additions & 0 deletions geocity/apps/forms/migrations/0024_contactformforadminsite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 4.2.1 on 2023-08-03 06:12

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("forms", "0023_alter_form_category_and_delete_contacttypeforadminsite"),
("submissions", "0022_contactform_and_more"),
]

operations = [
migrations.CreateModel(
name="ContactFormForAdminSite",
fields=[],
options={
"verbose_name": "1.5 Contact",
"verbose_name_plural": "1.5 Contacts",
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("submissions.contactform",),
),
migrations.CreateModel(
name="ContactTypeForAdminSite",
fields=[],
options={
"verbose_name": "1.9 Type de contact",
"verbose_name_plural": "1.9 Types de contacts",
"proxy": True,
"indexes": [],
"constraints": [],
},
bases=("submissions.contacttype",),
),
]
5 changes: 3 additions & 2 deletions geocity/apps/forms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from geocity.apps.accounts.fields import AdministrativeEntityFileField
from geocity.apps.accounts.models import AdministrativeEntity
from geocity.apps.api.services import convert_string_to_api_key
from geocity.apps.reports.models import Report

from ..reports.models import Report
from . import fields


Expand Down Expand Up @@ -363,7 +363,7 @@ class Form(models.Model):
category = models.ForeignKey(
FormCategory,
on_delete=models.CASCADE,
verbose_name=_("categorie"),
verbose_name=_("catégorie"),
related_name="forms",
)
administrative_entities = models.ManyToManyField(
Expand Down Expand Up @@ -518,6 +518,7 @@ class Form(models.Model):
related_name="map_widget_configuration_form",
verbose_name=_("Configuration de la carte avancée"),
)

# All objects
objects = FormQuerySet().as_manager()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Generated by Django 4.2.1 on 2023-08-03 07:58

import django.db.models.deletion
from django.db import migrations, models

CONTACT_TYPE_OTHER = 0
CONTACT_TYPE_REQUESTOR = 1
CONTACT_TYPE_OWNER = 2
CONTACT_TYPE_COMPANY = 3
CONTACT_TYPE_CLIENT = 4
CONTACT_TYPE_SECURITY = 5
CONTACT_TYPE_ASSOCIATION = 6
CONTACT_TYPE_ENGINEER = 7
CONTACT_TYPE_WORKDIRECTOR = 8
CONTACT_TYPE_CHOICES = (
(CONTACT_TYPE_OTHER, ("Autres")), # 0
(
CONTACT_TYPE_REQUESTOR,
("Requérant (si différent de l'auteur de la demande)"),
), # 1
(CONTACT_TYPE_OWNER, ("Propriétaire")), # 2
(CONTACT_TYPE_COMPANY, ("Entreprise")), # 3
(CONTACT_TYPE_CLIENT, ("Maître d'ouvrage")), # 4
(CONTACT_TYPE_SECURITY, ("Sécurité")), # 5
(CONTACT_TYPE_ASSOCIATION, ("Association")), # 6
(CONTACT_TYPE_ENGINEER, ("Architecte/Ingénieur")), # 7
(CONTACT_TYPE_WORKDIRECTOR, ("Direction des travaux")), # 8
)


def migrate_section_recipient(apps, schema_editor):
"""
As the data went from a choices field to a foreign key relation, it goes from 1 to 10 instead of 0 to 9, order remains unchanged.
Incrementing the existing value by 1 is enough to keep the data correct.
"""
SectionRecipient = apps.get_model("reports", "sectionrecipient")
ContactType = apps.get_model("submissions", "ContactType")

for recipient in SectionRecipient.objects.all():
if recipient.first_recipient != None:
if recipient.first_recipient == 999:
type = ContactType.objects.get(name="Auteur").pk
else:
type = ContactType.objects.get(
name=CONTACT_TYPE_CHOICES[recipient.first_recipient][1]
).pk
recipient.first_recipient = type
else:
recipient.first_recipient = None

if recipient.second_recipient != None:
if recipient.second_recipient == 999:
type = ContactType.objects.get(name="Auteur").pk
else:
type = ContactType.objects.get(
name=CONTACT_TYPE_CHOICES[recipient.second_recipient][1]
).pk
recipient.second_recipient = type
else:
recipient.second_recipient = None

recipient.save()


class Migration(migrations.Migration):

dependencies = [
("submissions", "0022_contactform_and_more"),
("reports", "0030_add_contact_type"),
]
atomic = False
operations = [
migrations.AlterField(
model_name="sectionrecipient",
name="first_recipient",
field=models.IntegerField(
verbose_name="Destinataire principal",
),
),
migrations.AlterField(
model_name="sectionrecipient",
name="second_recipient",
field=models.IntegerField(
verbose_name="Destinataire secondaire",
),
),
migrations.RunPython(migrate_section_recipient), # Migrate section recipient
migrations.AlterField(
model_name="sectionrecipient",
name="first_recipient",
field=models.ForeignKey(
help_text='Utilisé par défaut. Si celui-ci n\'existe pas, prend le "destinataire secondaire"',
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="first_recipient",
to="submissions.contacttype",
verbose_name="Destinataire principal",
),
),
migrations.AlterField(
model_name="sectionrecipient",
name="second_recipient",
field=models.ForeignKey(
help_text='Utilisé lorsque le "destinataire principal" n\'est pas présent dans la liste des contacts saisis',
on_delete=django.db.models.deletion.DO_NOTHING,
related_name="second_recipient",
to="submissions.contacttype",
verbose_name="Destinataire secondaire",
),
),
]
Loading