diff --git a/app/views.py b/app/views.py index c6ba780..c626cb6 100644 --- a/app/views.py +++ b/app/views.py @@ -84,6 +84,57 @@ class ReindexPageView(TemplateView): return HttpResponsePermanentRedirect(reverse('admin:index')) +class RefreshPageView(TemplateView): + template_name = "" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + return context + + def post(self, request): + global c_progress + c_progress = 0 + + def generate(): + stats = [] + total = 0 + for fmt in DATAFORMATS: + global c_filename + c_filename = fmt['filename'] + filename = get_datafile(fmt) + c = 1 + c_counter = 0 + rd = refresh_data(filename, fmt) + while c is not None: + try: + c, p = next(rd) + except Exception as e: + yield 'error: %s' % str(e) + #traceback.print_exc() + return + if isinstance(c, (int, float)): + global c_progress + c_counter = c + if isinstance(p, (int, float)): + c_progress = p + yield str(c) + "\n\n" + elif isinstance(p, str) and isinstance(c, str): + # Error condition + yield p + ": " + c + "\n\n" + return + + stats.append({'format': fmt['dataformat'], 'count': c_counter}) + print("Refresh: %d counted at %s" % (c_counter, fmt['dataformat'])) + total = total + c_counter + + yield "done: %d objects updated" % total + print("Refresh: %d objects updated" % total) + + c_progress = 0 + c_filename = "" + return HttpResponse(generate(), content_type='text/html') + + class ConfigurationPageView(TemplateView): template_name = "app/admin/config.html"