Rearranged everything, using django now

This commit is contained in:
2025-11-07 23:49:18 +00:00
parent c07c24e86f
commit d5282d9673
26 changed files with 254 additions and 30 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
wiki-pages/* deadwiki/wiki-pages/*
settings.py
venv/ venv/
__pycache__/ __pycache__/
data/* data/*

11
Makefile Normal file
View File

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

17
deadwiki/data/menu.json Normal file
View File

@@ -0,0 +1,17 @@
{
"Characters": {
"Humans": {
"Gregor": "gregor",
"Queen Luxa": "luxa"
},
"Gnawers": {
},
"Crawlers": {
}
},
"Locations": {
"Regalia": "regalia"
}
}

6
deadwiki/data/users.json Normal file
View File

@@ -0,0 +1,6 @@
[
{
"username": "deadvey",
"password_hash": "3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2"
}
]

0
deadwiki/db.sqlite3 Normal file
View File

View File

16
deadwiki/deadwiki/asgi.py Normal file
View File

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

89
deadwiki/deadwiki/urls.py Normal file
View File

@@ -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', '<br/>')
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/<str:page>', wiki_page, name='wiki_page'),
path('source/<str:page>', wiki_source, name='wiki_source'),
path('create', create_page, name='create_page'),
path('edit/<str:page>', 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'),
]

16
deadwiki/deadwiki/wsgi.py Normal file
View File

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

22
deadwiki/manage.py Executable file
View File

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

View File

@@ -5,11 +5,9 @@ body {
background: #fbf1d7; background: #fbf1d7;
} }
a { a {
background: #83c5b8;
text-decoration: none; text-decoration: none;
} }
a:hover { a:hover {
background: #fe8019;
text-decoration: underline; text-decoration: underline;
} }

View File

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

View File

@@ -19,7 +19,7 @@
<label>Content:</label><br/> <label>Content:</label><br/>
<textarea name='content'>{{content}}</textarea><br/> <textarea name='content'>{{content}}</textarea><br/>
<input type='submit'> <input type='submit' value='Submit'>
</form> </form>
<footer> <footer>
{% include 'partials/site-wide-footer.html' %} {% include 'partials/site-wide-footer.html' %}

View File

@@ -7,10 +7,8 @@
<header> <header>
{% include 'partials/site-wide-header.html' %} {% include 'partials/site-wide-header.html' %}
</header> </header>
<span> <h1>{{page_title}}</h1>
<h1>{{ config.name }}</h1> {{content|safe}}<br/>
{{config.description}}
</span>
<footer> <footer>
{% include 'partials/site-wide-footer.html' %} {% include 'partials/site-wide-footer.html' %}
</footer> </footer>

View File

@@ -1,2 +1,3 @@
<link href="/static/default.css" rel="stylesheet">
<link href="/static/custom.css" rel="stylesheet"> <link href="/static/custom.css" rel="stylesheet">
<meta charset='UTF-8'> <meta charset='UTF-8'>

View File

@@ -1,2 +1 @@
<hr/>
Powered by deadwiki Powered by deadwiki

View File

@@ -0,0 +1,9 @@
<span class='header-link'>
<a href='/create'>Create New Page</a>
</span>
<span class='header-link'>
<a href='/edit/{{page}}'>Edit Page</a>
</span>
<span class='header-link'>
<a href='/source/{{page}}'>View Source</a>
</span>

View File

@@ -0,0 +1,5 @@
<a href='/'>Main Page</a><br/>
<br/>
Charaters:<br/>
<a href='/wiki/gregor'>Gregor</a><br/>
<a href='/wiki/luxa'>Luxa</a><br/>

View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
{% include 'partials/head.html' %}
</head>
<body>
<header id='header'>
{% include 'partials/site-wide-header.html' %}
</header>
<hr id='top-hr'/>
<div id='content'>
<h1>{{page_title}}</h1>
<span>{{content|safe}}</span><br/>
</div>
<div id='sidenav'>
{% include 'partials/site-wide-sidenav.html' %}
</div>
<hr id='bottom-hr'/>
<footer id='footer'>
{% include 'partials/site-wide-footer.html' %}
</footer>
</body>
</html>

View File

@@ -1,4 +0,0 @@
<a href='/'>Home Page</a>
<a href='/create_page'>Create Page</a>
{{functions.dropdown_menu(menu)|safe}}
<hr/>

View File

@@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
{% include 'partials/head.html' %}
</head>
<body>
<header>
{% include 'partials/site-wide-header.html' %}
</header>
<h1>{{page_title}}</h1>
{{content|safe}}<br/>
<a href='/edit/{{page_title}}'>Edit Page</a>
<footer>
{% include 'partials/site-wide-footer.html' %}
</footer>
</body>
</html>