From 8ea61dfc55662988b0b0e4f24bbbe53352865d33 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 27 Jul 2021 12:47:39 +0530 Subject: [PATCH] Create a simple class-based view for the HomePage --- app/views.py | 34 ++++++++++++++++++++++++++++++++-- gmba_django/convert.py | 2 +- gmba_django/settings/base.py | 4 ++++ gmba_django/urls.py | 2 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/app/views.py b/app/views.py index 91ea44a..886cdbb 100644 --- a/app/views.py +++ b/app/views.py @@ -1,3 +1,33 @@ -from django.shortcuts import render +from django.views.generic.base import TemplateView +import os.path as ospath -# Create your views here. +from os import makedirs +from shutil import move +from tempfile import gettempdir +from .formats import * + +# Get temporary file storage +UPLOAD_PATH = gettempdir() +DATA_PATH = ospath.join(ospath.dirname(__file__), '..') +if not ospath.exists(DATA_PATH): + makedirs(DATA_PATH) + + +def get_datafile(fmt): + return ospath.join( + DATA_PATH, + fmt['folder'], + fmt['filename'] + '.' + fmt['extension'] + ) + + +class HomePageView(TemplateView): + + template_name = "app/index.html" + + def get_context_data(self, **kwargs): + fmts = DATAFORMATS + for f in fmts: + f['ready'] = ospath.isfile(get_datafile(f)) + context = super().get_context_data(**kwargs) + return context diff --git a/gmba_django/convert.py b/gmba_django/convert.py index d260eda..1fbc5b8 100644 --- a/gmba_django/convert.py +++ b/gmba_django/convert.py @@ -3,7 +3,7 @@ import json import re from os.path import isfile from app.models import * -from .formats import * +from app.formats import * from django.db import transaction diff --git a/gmba_django/settings/base.py b/gmba_django/settings/base.py index 0680830..fcd126f 100644 --- a/gmba_django/settings/base.py +++ b/gmba_django/settings/base.py @@ -106,8 +106,12 @@ USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.2/howto/static-files/ +STATIC_ROOT = '' + STATIC_URL = '/static/' +STATICFILES_DIRS = (os.path.join('static'), ) + # Default primary key field type # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field diff --git a/gmba_django/urls.py b/gmba_django/urls.py index 8b80791..851ddf4 100644 --- a/gmba_django/urls.py +++ b/gmba_django/urls.py @@ -17,5 +17,5 @@ from django.contrib import admin from django.urls import path urlpatterns = [ - path('admin/', admin.site.urls), + path('', HomePageView.as_view(), name='home'), ]