feat: basic template
This commit is contained in:
@@ -54,7 +54,9 @@ ROOT_URLCONF = "epub2go_web.urls"
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"DIRS": [
|
||||
'epub2go_web/templates/'
|
||||
],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
@@ -73,12 +75,12 @@ WSGI_APPLICATION = "epub2go_web.wsgi.application"
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3",
|
||||
}
|
||||
}
|
||||
#DATABASES = {
|
||||
# "default": {
|
||||
# "ENGINE": "django.db.backends.sqlite3",
|
||||
# "NAME": BASE_DIR / "db.sqlite3",
|
||||
# }
|
||||
#}
|
||||
|
||||
|
||||
# Password validation
|
||||
|
||||
63
src/epub2go_web/templates/index.html
Normal file
63
src/epub2go_web/templates/index.html
Normal file
@@ -0,0 +1,63 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ title }}</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>{{ title }}</h1>
|
||||
<search>
|
||||
<form onsubmit="submitSearch(event)">
|
||||
<input type="su" id="searchInput" placeholder="Search">
|
||||
</form>
|
||||
</search>
|
||||
</header>
|
||||
<table id="table">
|
||||
{% for item in items %}
|
||||
<tr>
|
||||
<td class="table-data">
|
||||
<a href= {{ item.url }}>
|
||||
{{ item.title }}
|
||||
</a>
|
||||
</td>
|
||||
<td>Download</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<footer>
|
||||
<a href="javascript:void(window.open('./?t='+encodeURIComponent(window.location.toString())))">Bookmarklet</a> <!--TODO fix domain part as variable-->
|
||||
<a href="https://github.com/eneller/epub2go.py">GitHub</a>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
// get document references
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const table = document.getElementById('table');
|
||||
const table_r = Array.from(table.getElementsByTagName('tr'));
|
||||
|
||||
// allow search from url parameter
|
||||
let searchParam = params.get('s');
|
||||
if (searchParam){
|
||||
searchInput.value = searchParam;
|
||||
search(searchParam);
|
||||
}
|
||||
|
||||
function submitSearch(event){
|
||||
event.preventDefault();
|
||||
search();
|
||||
}
|
||||
function search(searchStr = searchInput.value){
|
||||
function showMatch(tr){
|
||||
// match search with list
|
||||
let searchSuccess = Array.from(tr.getElementsByClassName('table-data')).map(e => e.textContent)
|
||||
.join(' ')
|
||||
.indexOf(searchStr) > -1;
|
||||
if (searchSuccess) tr.style.display = "";
|
||||
else tr.style.display = "none";
|
||||
}
|
||||
table_r.map(showMatch, table_r);
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -17,7 +17,25 @@ Including another URLconf
|
||||
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
def root(request:HttpRequest):
|
||||
title = 'epub2go'
|
||||
targetParam = request.GET.get('t', None)
|
||||
if targetParam is not None:
|
||||
getEpub(targetParam)
|
||||
return render(request, 'index.html', locals())
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path('',root, name='root')
|
||||
]
|
||||
|
||||
def getEpub(param):
|
||||
# TODO validate / sanitize input
|
||||
# TODO check for existing file and age
|
||||
# TODO download
|
||||
# TODO redirect to loading page
|
||||
# TODO redirect to download page
|
||||
raise NotImplementedError
|
||||
|
||||
Reference in New Issue
Block a user