Skip to content

Commit

Permalink
add batch archive view
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Dec 13, 2024
1 parent 5ccbead commit f3ec32a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion itou/templates/apply/includes/list_job_applications.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{% if display_kind.is_table %}
<div class="table-responsive mt-3 mt-md-4">
{% if job_applications_list_kind is JobApplicationsListKind.RECEIVED %}
<form hx-get="{% url 'apply:list_for_siae_actions' %}" hx-trigger="change delay:.5" hx-swap="none" data-hide-elements-when-selected=".hide-on-selection">
<form hx-get="{% url 'apply:list_for_siae_actions' %}?list_url={{ request.get_full_path|urlencode }}" hx-trigger="change delay:.5" hx-swap="none" data-hide-elements-when-selected=".hide-on-selection">
{% include "apply/includes/list_table.html" %}
</form>
{% else %}
Expand Down
10 changes: 5 additions & 5 deletions itou/templates/apply/includes/siae_actions_modals.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ <h5 class="modal-title" id="postpone_modal_title">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">Retour</button>
<form method="post" action="url 'apply:batch_archive'">
<form method="post" action="url 'apply:batch_postpone'?next_url={{ list_url|urlencode }}">
{% csrf_token %}
{% for application_id in selected_application_ids %}
<input type="hidden" name="application_ids[]" value="{{ application_id }}" />
<input type="hidden" name="application_ids" value="{{ application_id }}" />
{% endfor %}
<button class="btn btn-sm btn-primary">Confirmer</button>
</form>
Expand Down Expand Up @@ -52,10 +52,10 @@ <h5 class="modal-title" id="archive_modal_title">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-outline-secondary" data-bs-dismiss="modal">Retour</button>
<form method="post" action="url 'apply:batch_archive'">
<form method="post" action="{% url 'apply:batch_archive' %}?next_url={{ list_url|urlencode }}">
{% csrf_token %}
{% for application_id in selected_application_ids %}
<input type="hidden" name="application_ids[]" value="{{ application_id }}" />
<input type="hidden" name="application_ids" value="{{ application_id }}" />
{% endfor %}
<button class="btn btn-sm btn-primary">Confirmer</button>
</form>
Expand Down Expand Up @@ -94,7 +94,7 @@ <h5 class="modal-title" id="modal_title_{{ siae.pk }}">
{% csrf_token %}
<input type="hidden" name="target_company_id" value="{{ siae.pk }}" />
{% for application_id in selected_application_ids %}
<input type="hidden" name="application_ids[]" value="{{ application_id }}" />
<input type="hidden" name="application_ids" value="{{ application_id }}" />
{% endfor %}
<button class="btn btn-sm btn-primary">Confirmer</button>
</form>
Expand Down
3 changes: 2 additions & 1 deletion itou/www/apply/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.urls import path

from itou.www.apply.views import edit_views, list_views, process_views, submit_views
from itou.www.apply.views import batch_views, edit_views, list_views, process_views, submit_views


# https://docs.djangoproject.com/en/dev/topics/http/urls/#url-namespaces-and-included-urlconfs
Expand Down Expand Up @@ -106,6 +106,7 @@
name="list_for_siae_exports_download",
),
path("siae/list/actions", list_views.list_for_siae_actions, name="list_for_siae_actions"),
path("company/batch/archive", batch_views.archive, name="batch_archive"),
# Process.
path(
"<uuid:job_application_id>/jobseeker/details",
Expand Down
46 changes: 46 additions & 0 deletions itou/www/apply/views/batch_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import logging

from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.urls import reverse
from django.utils import timezone
from django.views.decorators.http import require_POST

from itou.job_applications.models import JobApplication
from itou.utils.auth import check_user
from itou.utils.perms.company import get_current_company_or_404
from itou.utils.urls import get_safe_url


logger = logging.getLogger(__name__)


@login_required
@check_user(lambda user: user.is_employer)
@require_POST
def archive(request):
company = get_current_company_or_404(request)
application_ids = request.POST.getlist("application_ids")
archived_ids = [
application.pk
for application in company.job_applications_received.filter(pk__in=application_ids).select_for_update()
if application.can_be_archived
]
archived_nb = JobApplication.objects.filter(pk__in=archived_ids).update(
archived_at=timezone.now(),
archived_by=request.user,
)

if archived_nb > 1:
messages.info(request, f"{archived_nb} candidatures archivées avec succès.", extra_tags="toast")
else:
messages.info(request, f"{archived_nb} candidature archivée avec succès.", extra_tags="toast")
next_url = get_safe_url(request, "next_url", fallback_url=reverse("apply:list_for_siae"))
logger.info(
"user=%s batch archived %s applications: %s",
request.user.pk,
archived_nb,
",".join(str(app_uid) for app_uid in archived_ids),
)
return HttpResponseRedirect(next_url)

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection depends on a
user-provided value
.
1 change: 1 addition & 0 deletions itou/www/apply/views/list_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def list_for_siae_actions(request):
"can_postpone": can_postpone,
"can_refuse": can_refuse,
"can_transfer": can_transfer,
"list_url": get_safe_url(request, "list_url", fallback_url=reverse("apply:list_for_siae")),
}
response = render(
request,
Expand Down

0 comments on commit f3ec32a

Please sign in to comment.