-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 60a2f40
Showing
28 changed files
with
1,293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.venv/ | ||
__pycache__/ | ||
db.sqlite3 | ||
media/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# DjaIF | ||
|
||
DjaIF, simple **Dja**ngo-powered **I**nteractive **F**iction engine. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
ASGI config for djaif 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/3.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djaif.settings') | ||
|
||
application = get_asgi_application() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
from djaif.book import models | ||
|
||
admin.site.register(models.Book) | ||
admin.site.register(models.BookPage) | ||
admin.site.register(models.PageLink) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BookConfig(AppConfig): | ||
name = 'book' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 3.0.5 on 2020-04-03 17:02 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Book', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.TextField(unique=True)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.0.5 on 2020-04-03 17:38 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('book', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BookPage', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('title', models.TextField()), | ||
('body', models.TextField()), | ||
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='book.Book')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 3.0.5 on 2020-04-03 18:05 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('book', '0002_bookpage'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PageLink', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('from_page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='book.BookPage')), | ||
('to_page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='to_page', to='book.BookPage')), | ||
], | ||
options={ | ||
'unique_together': {('from_page', 'to_page')}, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.0.5 on 2020-04-03 18:08 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('book', '0003_pagelink'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='pagelink', | ||
name='name', | ||
field=models.TextField(default='???'), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.0.5 on 2020-04-03 18:45 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('book', '0004_pagelink_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='book', | ||
name='first_page', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='first_name', to='book.BookPage'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.0.5 on 2020-04-03 19:04 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('book', '0005_book_first_page'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='book', | ||
name='cover_art', | ||
field=models.ImageField(null=True, upload_to='uploads/'), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.db import models | ||
|
||
|
||
# Create your models here. | ||
class Book(models.Model): | ||
"""Interactive function.""" | ||
title = models.TextField(name='title', unique=True) | ||
first_page = models.ForeignKey( | ||
'BookPage', null=True, on_delete=models.SET_NULL, | ||
related_name='first_name', | ||
) | ||
cover_art = models.ImageField(null=True) | ||
|
||
def __str__(self): | ||
return '{self.title} ({self.id})'.format(self=self) | ||
|
||
|
||
class BookPage(models.Model): | ||
book = models.ForeignKey(Book, on_delete=models.CASCADE) | ||
title = models.TextField(name='title') | ||
body = models.TextField(name='body') | ||
|
||
def __str__(self): | ||
return '{self.title} ({self.id})'.format(self=self) | ||
|
||
|
||
class PageLink(models.Model): | ||
from_page = models.ForeignKey(BookPage, on_delete=models.CASCADE) | ||
to_page = models.ForeignKey( | ||
BookPage, on_delete=models.CASCADE, related_name='to_page', | ||
) | ||
name = models.TextField() | ||
|
||
def __str__(self): | ||
return ( | ||
'{self.from_page.title} ➝ {self.to_page.title} ' | ||
'({self.id})'.format( | ||
self=self, | ||
) | ||
) | ||
|
||
class Meta: | ||
unique_together = ['from_page', 'to_page'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>{{ book.title }}</title> | ||
</head> | ||
<body> | ||
<h1>{{ book.title }}</h1> | ||
<ul> | ||
{% for page in book.bookpage_set.all %} | ||
<li><a href="{% url 'page' book.id page.id %}"> | ||
{{ page.title }} | ||
</a></li> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{% load static %} | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Books</title> | ||
</head> | ||
<body> | ||
<ul> | ||
{% for book in books %} | ||
<li><a href="book/{{ book.id }}"> | ||
{{ book.title }} | ||
{% if book.cover_art %} | ||
<img src="{{ book.cover_art.url }}" /> | ||
{% endif %} | ||
</a></li> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>{{ page.book.title }}: {{ page.title }}</title> | ||
</head> | ||
<body> | ||
{{ page.body }} | ||
<ul> | ||
{% for link in page.pagelink_set.all %} | ||
<li><a href="{% url 'page' page.book.id link.to_page.id %}"> | ||
{{ link.name }} | ||
</a></li> | ||
{% endfor %} | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
|
||
from djaif.book import views | ||
|
||
urlpatterns = [ | ||
path('', views.index), | ||
path('book/<int:book_id>', views.book), | ||
path('book/<int:book_id>/page/<int:page_id>', views.page, name='page'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from django.shortcuts import render, redirect, get_object_or_404 | ||
from django.urls import reverse | ||
|
||
from djaif.book import models | ||
|
||
|
||
def index(request): | ||
return render(request, "book_index.html", context={ | ||
'books': models.Book.objects.all(), | ||
}) | ||
|
||
|
||
def book(request, book_id): | ||
b = get_object_or_404(models.Book, id=book_id) | ||
if not b.first_page: | ||
return render(request, "book.html", context={ | ||
'book': b, | ||
}) | ||
return redirect(reverse('page', kwargs={ | ||
'book_id': b.id, 'page_id': b.first_page.id | ||
})) | ||
|
||
|
||
def page(request, book_id, page_id): | ||
return render(request, "page.html", context={ | ||
'page': get_object_or_404( | ||
models.BookPage, book__id=book_id, id=page_id, | ||
), | ||
}) |
Oops, something went wrong.