diff --git a/src/core/__init__.py b/src/core/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/core/admin.py b/src/core/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/src/core/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/src/core/apps.py b/src/core/apps.py
new file mode 100644
index 0000000..c0ce093
--- /dev/null
+++ b/src/core/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class CoreConfig(AppConfig):
+ default_auto_field = "django.db.models.BigAutoField"
+ name = "core"
diff --git a/src/core/management/__init__.py b/src/core/management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/core/management/commands/__init__.py b/src/core/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/core/management/commands/getbooks.py b/src/core/management/commands/getbooks.py
new file mode 100644
index 0000000..8d5b079
--- /dev/null
+++ b/src/core/management/commands/getbooks.py
@@ -0,0 +1,20 @@
+from django.core.management.base import BaseCommand, CommandError
+from django.conf import settings
+from epub2go.convert import get_all_books, Book, allbooks_url
+
+import pickle, os
+
+class Command(BaseCommand):
+ help = "Download the Book List"
+
+ filepath = os.path.join(settings.MEDIA_ROOT, 'books.pkl')
+ def handle(self, *args, **options):
+ try:
+ books = get_all_books()
+ except:
+ raise CommandError('Failed to get Book list from %s', allbooks_url)
+ try:
+ with open(self.filepath, 'wb') as file:
+ pickle.dump(books,file)
+ except:
+ raise CommandError(f'Failed to save pickle file. Did you create {settings.MEDIA_ROOT} ?')
\ No newline at end of file
diff --git a/src/core/migrations/__init__.py b/src/core/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/src/core/models.py b/src/core/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/src/core/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/src/core/tests.py b/src/core/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/src/core/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/src/core/urls.py b/src/core/urls.py
new file mode 100644
index 0000000..a9d7f56
--- /dev/null
+++ b/src/core/urls.py
@@ -0,0 +1,7 @@
+from django.urls import path
+
+from . import views
+
+urlpatterns = [
+ path("", views.index, name="index"),
+]
\ No newline at end of file
diff --git a/src/core/views.py b/src/core/views.py
new file mode 100644
index 0000000..f7227d3
--- /dev/null
+++ b/src/core/views.py
@@ -0,0 +1,21 @@
+from django.shortcuts import render
+from django.http import HttpRequest, HttpResponse
+
+from epub2go.convert import get_all_books, Book
+
+def index(request: HttpRequest):
+ title = 'epub2go'
+ targetParam = request.GET.get('t', None)
+ books = get_all_books()
+ if targetParam is not None:
+ getEpub(targetParam)
+ return render(request, 'index.html', locals())
+
+def getEpub(param):
+ print(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
diff --git a/src/epub2go_web/settings.py b/src/epub2go_web/settings.py
index 0892213..51702a0 100644
--- a/src/epub2go_web/settings.py
+++ b/src/epub2go_web/settings.py
@@ -14,6 +14,7 @@ from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
+PROJ_DIR = BASE_DIR / 'epub2go_web'
# Quick-start development settings - unsuitable for production
@@ -37,6 +38,7 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
+ "core",
]
MIDDLEWARE = [
@@ -55,7 +57,7 @@ TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
- "epub2go_web/templates/"
+ PROJ_DIR / "templates/"
],
"APP_DIRS": True,
"OPTIONS": {
@@ -119,9 +121,12 @@ USE_TZ = True
STATIC_URL = "static/"
STATICFILES_DIRS = [
- BASE_DIR / "epub2go_web/static",
+ PROJ_DIR / "static/",
]
+MEDIA_URL = "media/"
+MEDIA_ROOT = PROJ_DIR / "media/"
+
# Default primary key field type
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
diff --git a/src/epub2go_web/templates/index.html b/src/epub2go_web/templates/index.html
index a6be78d..02cd9f4 100644
--- a/src/epub2go_web/templates/index.html
+++ b/src/epub2go_web/templates/index.html
@@ -12,7 +12,7 @@
-
+
diff --git a/src/epub2go_web/urls.py b/src/epub2go_web/urls.py
index 1d639e4..37a6d04 100644
--- a/src/epub2go_web/urls.py
+++ b/src/epub2go_web/urls.py
@@ -16,29 +16,13 @@ Including another URLconf
"""
from django.contrib import admin
-from django.urls import path
+from django.urls import path, include
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render, redirect
from epub2go.convert import get_all_books, GBConvert, Book
-def root(request:HttpRequest):
- title = 'epub2go'
- targetParam = request.GET.get('t', None)
- books = get_all_books()
- if targetParam is not None:
- getEpub(targetParam)
- return render(request, 'index.html', locals())
urlpatterns = [
path("admin/", admin.site.urls),
- path('',root, name='root')
+ path('',include('core.urls'))
]
-
-def getEpub(param):
- print(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