Implement ReindexPageView

This commit is contained in:
PCoder 2021-07-28 09:49:13 +05:30
parent 7fd62dd68b
commit 13b2995c34
1 changed files with 28 additions and 4 deletions

View File

@ -1,12 +1,16 @@
import os
from django.contrib import messages
from django.conf import settings
from django.views.generic.base import TemplateView
from django.http import FileResponse
from django.http import FileResponse , HttpResponsePermanentRedirect
from django.urls import reverse
import os.path as ospath
from os import makedirs
from tempfile import gettempdir
from .formats import *
from .convert import reindex_data
# Get temporary file storage
UPLOAD_PATH = gettempdir()
@ -23,8 +27,12 @@ def get_datafile(fmt):
)
class HomePageView(TemplateView):
# Data update tracking
c_progress = 0
c_filename = ""
class HomePageView(TemplateView):
template_name = "app/index.html"
def get_context_data(self, **kwargs):
@ -36,7 +44,6 @@ class HomePageView(TemplateView):
class OfflinePageView(TemplateView):
template_name = "app/offline.html"
def get_context_data(self, **kwargs):
@ -45,7 +52,6 @@ class OfflinePageView(TemplateView):
class DemoPageView(TemplateView):
template_name = "app/demo.html"
def get_context_data(self, **kwargs):
@ -53,6 +59,24 @@ class DemoPageView(TemplateView):
return context
class ReindexPageView(TemplateView):
template_name = "app/demo.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
return context
def post(self, request, **kwargs):
global c_progress
c_progress = 0
global c_filename
c_filename = ""
reindex_data()
messages.add_message(request, messages.INFO, 'Search engine refresh complete')
print("Search engine reindexed")
return HttpResponsePermanentRedirect(reverse('admin:index'))
def send_from_file(request, path):
request_for = ''
if request.path.startswith('/geodata'):