Skip to content

Commit

Permalink
matching is only triggered when the user decides
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Jan 19, 2024
1 parent a5e23b6 commit cbfabd0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lemarche/templates/tenders/admin_change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@
{% block after_related_objects %}
{{ block.super }}
{% if original %}
{% if not original.validated_at %}
<div class="submit-row">
<input type="submit" class="button" name="_calculate_tender" value="Sauvegarder et chercher les structures correspondantes" />
</div>
{% endif %}
<div class="submit-row">
{% if original.validated_at %}
<i>Validé le {{ original.validated_at }}.&nbsp;</i>
{% if original.sent_at %}
<i>Envoyé le {{ original.sent_at }}.</i>
<button type="submit" class="button" name="_restart_tender" value="1">Renvoyer aux structures</button>
<input type="submit" class="button" name="_restart_tender" value="Renvoyer aux structures" />
{% endif %}
{% else %}
<button type="submit" class="button" name="_validate_tender" value="1">Valider (sauvegarder) et envoyer aux structures</button>
<input type="submit" class="button" name="_validate_tender" value="Valider (sauvegarder) et envoyer aux structures" />
<i>L'envoi des besoins 'validés' se fait toutes les 5 minutes, du Lundi au Vendredi, entre 9h et 17h</i>
{% endif %}
</div>
Expand Down
12 changes: 5 additions & 7 deletions lemarche/tenders/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,6 @@ def save_model(self, request, obj: Tender, form, change):
obj.author = request.user
obj.save()

def save_related(self, request, form, formsets, change):
super().save_related(request=request, form=form, formsets=formsets, change=change)
tender: Tender = form.instance
# we can add `and obj.status != obj.STATUS_DRAFT` to disable matching when is draft
if not tender.is_validated_or_sent:
tender.set_siae_found_list()

def save_formset(self, request, form, formset, change):
"""
Set Note author on create
Expand Down Expand Up @@ -417,6 +410,7 @@ def question_count_with_link(self, tender):

question_count_with_link.short_description = TenderQuestion._meta.verbose_name_plural

# TODO: les siaes trouvés par l'IA apparaissent aussi ici : /admin/siaes/siae/?tenders__in=7
def siae_count_annotated_with_link(self, tender):
url = reverse("admin:siaes_siae_changelist") + f"?tenders__in={tender.id}"
return format_html(f'<a href="{url}">{getattr(tender, "siae_count_annotated", 0)}</a>')
Expand Down Expand Up @@ -499,6 +493,10 @@ def response_change(self, request, obj: Tender):
"""
Catch submit of custom admin button to Validate or Resend Tender
"""
if request.POST.get("_calculate_tender"):
obj.set_siae_found_list()
self.message_user(request, "Les structures concernées ont été mises à jour.")
return HttpResponseRedirect(".")
if request.POST.get("_validate_tender"):
obj.set_validated()
self.message_user(request, "Ce dépôt de besoin a été validé. Il sera envoyé en temps voulu :)")
Expand Down
1 change: 0 additions & 1 deletion lemarche/www/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ def csrf_failure(request, reason=""): # noqa C901
else:
setattr(tender, attribute, tender_dict.get(attribute))
tender.save()
tender.set_siae_found_list()

# remove steps data
uuid = request.session.get("tender_steps_data_uuid", None)
Expand Down
1 change: 0 additions & 1 deletion lemarche/www/tenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ def done(self, _, form_dict, **kwargs):
tender_dict = cleaned_data | {"author": user, "source": tender_constants.SOURCE_FORM}
is_draft: bool = self.request.POST.get("is_draft", False)
self.save_instance_tender(tender_dict=tender_dict, form_dict=form_dict, is_draft=is_draft)
self.instance.set_siae_found_list()

# remove steps data
uuid = self.request.session.get("tender_steps_data_uuid", None)
Expand Down

0 comments on commit cbfabd0

Please sign in to comment.