diff --git a/.gitignore b/.gitignore index 643c2da..5f74f36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -wiki-pages/* +deadwiki/wiki-pages/* +settings.py venv/ __pycache__/ data/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e6e6fe6 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +DJANGO_ROOT=deadwiki + +all: users.json main_page + +users.json: $(DJANGO_ROOT)/data/users.json +$(DJANGO_ROOT)/data/users.json: + echo [] > $(DJANGO_ROOT)/data/users.json + +main_page: $(DJANGO_ROOT)/wiki-pages/main.md +$(DJANGO_ROOT)/wiki-pages/main.md: + echo 'Welcome to my DeaDwiki Instance!' > $(DJANGO_ROOT)/wiki-pages/main.md diff --git a/config.py b/deadwiki/config.py similarity index 100% rename from config.py rename to deadwiki/config.py diff --git a/deadwiki/data/menu.json b/deadwiki/data/menu.json new file mode 100644 index 0000000..c5b5e84 --- /dev/null +++ b/deadwiki/data/menu.json @@ -0,0 +1,17 @@ +{ + "Characters": { + "Humans": { + "Gregor": "gregor", + "Queen Luxa": "luxa" + }, + "Gnawers": { + + }, + "Crawlers": { + + } + }, + "Locations": { + "Regalia": "regalia" + } +} diff --git a/deadwiki/data/users.json b/deadwiki/data/users.json new file mode 100644 index 0000000..e4e8c50 --- /dev/null +++ b/deadwiki/data/users.json @@ -0,0 +1,6 @@ +[ + { + "username": "deadvey", + "password_hash": "3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2" + } +] diff --git a/data_management.py b/deadwiki/data_management.py similarity index 100% rename from data_management.py rename to deadwiki/data_management.py diff --git a/deadwiki/db.sqlite3 b/deadwiki/db.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/deadwiki/deadwiki/__init__.py b/deadwiki/deadwiki/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/deadwiki/deadwiki/asgi.py b/deadwiki/deadwiki/asgi.py new file mode 100644 index 0000000..4411b76 --- /dev/null +++ b/deadwiki/deadwiki/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for deadwiki project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'deadwiki.settings') + +application = get_asgi_application() diff --git a/deadwiki/deadwiki/urls.py b/deadwiki/deadwiki/urls.py new file mode 100644 index 0000000..de9cfb7 --- /dev/null +++ b/deadwiki/deadwiki/urls.py @@ -0,0 +1,89 @@ +from django.shortcuts import render, redirect +from django.urls import path +from django.http import HttpResponse +from markdown2 import markdown +import os +import config +import functions +import data_management + +# Redirect to /wiki/main which is the home page +def index(request): + return redirect('/wiki/main') + +def wiki_page(request, page): + if os.path.isfile(f'./wiki-pages/{page}.md'): + with open(f'./wiki-pages/{page}.md', 'r') as file: + file_contents = markdown(file.read()) + return render(request, 'wiki-page.html', { + 'functions': functions, + 'content': file_contents, + 'page': page, + }) + else: + return HttpResponse('Page does not exist') + +# Show the raw markdown +def wiki_source(request, page): + if os.path.isfile(f'./wiki-pages/{page}.md'): + with open(f'./wiki-pages/{page}.md', 'r') as file: + file_contents = (file.read()).replace('\n', '
') + return render(request, 'wiki-page.html', { + 'functions': functions, + 'content': file_contents, + 'page': page, + }) + else: + return HttpResponse('Page does not exist') + +def create_page(request): + return render(request, 'forms/create_page.html', { + 'functions': functions, + 'config': config + }) + +def edit_page(request, page): + if os.path.isfile(f'./wiki-pages/{page}.md'): + with open(f'./wiki-pages/{page}.md', 'r') as file: + file_contents = file.read() + return render(request, 'forms/edit-page.html', { + 'content': file_contents, + 'functions': functions, + 'page_title': page + }) + else: + return render(request, 'forms/edit-page.html', { + 'content': 'New Page!', + 'page_title': page + }) + +def submit_create_page(request): + if request.method == 'POST': + page_name = request.POST['page_name'] + return redirect(f'/edit/{page_name}') + +def submit_edit_page(request): + if request.method == 'POST': + page = request.POST['page'] + content = request.POST['content'] + username = request.POST['username'] + password_hash = functions.sha512_hash(request.POST['password']) + + user_object = data_management.get_data('users', 'username', username) + + if user_object['password_hash'] == password_hash: + with open(f'./wiki-pages/{page}.md', 'w') as file: + file.write(content) + return redirect(f'/wiki/{page}') + else: + return HttpResponse('Incorrect password') + +urlpatterns = [ + path('', index, name='index'), + path('wiki/', wiki_page, name='wiki_page'), + path('source/', wiki_source, name='wiki_source'), + path('create', create_page, name='create_page'), + path('edit/', edit_page, name='edit_page'), + path('submit_create_page', submit_create_page, name='submit_create_page'), + path('submit-edit', submit_edit_page, name='submit_edit_page'), +] diff --git a/deadwiki/deadwiki/wsgi.py b/deadwiki/deadwiki/wsgi.py new file mode 100644 index 0000000..7be6161 --- /dev/null +++ b/deadwiki/deadwiki/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for deadwiki project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'deadwiki.settings') + +application = get_wsgi_application() diff --git a/functions.py b/deadwiki/functions.py similarity index 100% rename from functions.py rename to deadwiki/functions.py diff --git a/deadwiki/manage.py b/deadwiki/manage.py new file mode 100755 index 0000000..eafbe17 --- /dev/null +++ b/deadwiki/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'deadwiki.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/static/custom.css b/deadwiki/static/custom.css similarity index 73% rename from static/custom.css rename to deadwiki/static/custom.css index 86420a3..3c59a34 100644 --- a/static/custom.css +++ b/deadwiki/static/custom.css @@ -5,11 +5,9 @@ body { background: #fbf1d7; } a { - background: #83c5b8; text-decoration: none; } a:hover { - background: #fe8019; text-decoration: underline; } diff --git a/deadwiki/static/default.css b/deadwiki/static/default.css new file mode 100644 index 0000000..1b099a0 --- /dev/null +++ b/deadwiki/static/default.css @@ -0,0 +1,34 @@ +/* The sidebar menu */ +#sidenav { + height: 100%; /* Full-height: remove this if you want "auto" height */ + width: 80px; /* Set the width of the sidebar */ + position: fixed; /* Fixed Sidebar (stay in place on scroll) */ + z-index: 1; /* Stay on top */ + top: 0; /* Stay at the top */ + left: 0; + overflow-x: hidden; /* Disable horizontal scroll */ + border-right: 2px solid grey; + padding: 10px 10px; +} +hr { + border-top: 1px solid grey; +} +#top-hr { + margin-left: -8px; +} +#bottom-hr { + margin-left: 92px; +} +/* Style page content */ +#content, #header, #footer { + margin-left: 100px; /* Same as the width of the sidebar */ + padding: 0px 10px; +} +.header-link { + margin: 10px; + padding: 10px 10px; +} +textarea { + width: 80%; + height: 400px; +} diff --git a/static/robots.txt b/deadwiki/static/robots.txt similarity index 100% rename from static/robots.txt rename to deadwiki/static/robots.txt diff --git a/templates/forms/create_page.html b/deadwiki/templates/forms/create_page.html similarity index 100% rename from templates/forms/create_page.html rename to deadwiki/templates/forms/create_page.html diff --git a/templates/forms/edit-page.html b/deadwiki/templates/forms/edit-page.html similarity index 94% rename from templates/forms/edit-page.html rename to deadwiki/templates/forms/edit-page.html index 3e88b4d..ba271f4 100644 --- a/templates/forms/edit-page.html +++ b/deadwiki/templates/forms/edit-page.html @@ -19,7 +19,7 @@

- +