Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
astynax committed Apr 4, 2020
0 parents commit 60a2f40
Show file tree
Hide file tree
Showing 28 changed files with 1,293 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv/
__pycache__/
db.sqlite3
media/
3 changes: 3 additions & 0 deletions README.md
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 added djaif/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions djaif/asgi.py
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 added djaif/book/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions djaif/book/admin.py
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)
5 changes: 5 additions & 0 deletions djaif/book/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BookConfig(AppConfig):
name = 'book'
21 changes: 21 additions & 0 deletions djaif/book/migrations/0001_initial.py
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)),
],
),
]
23 changes: 23 additions & 0 deletions djaif/book/migrations/0002_bookpage.py
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')),
],
),
]
25 changes: 25 additions & 0 deletions djaif/book/migrations/0003_pagelink.py
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')},
},
),
]
19 changes: 19 additions & 0 deletions djaif/book/migrations/0004_pagelink_name.py
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,
),
]
19 changes: 19 additions & 0 deletions djaif/book/migrations/0005_book_first_page.py
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'),
),
]
18 changes: 18 additions & 0 deletions djaif/book/migrations/0006_book_cover_art.py
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.
43 changes: 43 additions & 0 deletions djaif/book/models.py
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']
17 changes: 17 additions & 0 deletions djaif/book/templates/book.html
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>
20 changes: 20 additions & 0 deletions djaif/book/templates/book_index.html
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>
17 changes: 17 additions & 0 deletions djaif/book/templates/page.html
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>
3 changes: 3 additions & 0 deletions djaif/book/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
9 changes: 9 additions & 0 deletions djaif/book/urls.py
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'),
]
29 changes: 29 additions & 0 deletions djaif/book/views.py
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,
),
})
Loading

0 comments on commit 60a2f40

Please sign in to comment.