Create a simple class-based view for the HomePage

This commit is contained in:
PCoder 2021-07-27 12:47:39 +05:30
parent 54267c874f
commit 8ea61dfc55
4 changed files with 38 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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'),
]