400 on long running form post

I’m working on a yearly “archive” process for my models to reduce some clutter in the UI. This process will just change a flag on each model and related models from true to false. The process is running file and updating all the records, but the UI is getting a 400 error while the process is still running. I have been unable to find a way to change the timeout of the post and I don’t want to add complexity of celery/redis for this single process.

Any help would be appreciated.

View.py:

class ToArchiveView(TemplateView):#LoginRequiredMixin
    template_name = "visits/tree.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context["visits_2_archive"] = Visit.get_visits_to_archive()
        return context

    def post(self, request, *args, **kwargs):
        context = self.get_context_data(**kwargs)

        visits=context['visits_2_archive']
        for visit in visits:
            stdlogger.debug("===============================")
            visit.archive()

        return self.render_to_response(context)

Template/html:

<div class="container ms-0 ps-0">
   <div class="row ">
      <div class="col">
         <div class="btn-toolbar mb-2 mb-md-0 p-2">
            <div class="btn-group me-2 me-auto">
               <form method="post" onsubmit="openLoader()">
                  {% csrf_token %}
                 <button class="button btn btn-primary" name="archive" value="Archive all records below">Archive all records below</button>
               </form>
            </div>
         </div>
      </div>
   </div>
</div>

   <ul id="tree">
   {% for visit in visits_2_archive %}
      <li><span class="caret">{{ visit.visit_tree_str }}</span>
      <ul class="nested">   
         <li><b>EOB:</b>{{ visit.eob }}</li>
         <li><span class="caret">Documents</span>
            <ul class="nested">
               {% for document in visit.get_documents %}
               <li>{{ document }}</li>
               {% endfor %}                  
            </ul>
         </li>
         <li><span class="caret">Payments</span>
            <ul class="nested">
               {% for payment in visit.get_payments %}
               <li>{{ payment }}</li>
               {% endfor %}
            </ul>
         </li>   
      </ul>
      </li>
   {% endfor %}
   </ul>

Either:

  • Make this a celery process.

  • Make this a custom management command that you run directly from the command line and not through the browser.

If I had other cases where I would/could use Celery, I would think about that, but when this is the only one it seems to be overkill. I’m hoping someone else might have another bright idea with a smaller component.