From b973f3583a8fda64b6cc2571208ee2cac48945b3 Mon Sep 17 00:00:00 2001 From: Piotr Mitros Date: Sun, 25 Dec 2011 12:52:19 -0500 Subject: [PATCH] Forgot to add textbook directory --- textbook/__init__.py | 0 textbook/models.py | 3 +++ textbook/tests.py | 16 ++++++++++++++++ textbook/views.py | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 textbook/__init__.py create mode 100644 textbook/models.py create mode 100644 textbook/tests.py create mode 100644 textbook/views.py diff --git a/textbook/__init__.py b/textbook/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/textbook/models.py b/textbook/models.py new file mode 100644 index 0000000000..71a8362390 --- /dev/null +++ b/textbook/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/textbook/tests.py b/textbook/tests.py new file mode 100644 index 0000000000..501deb776c --- /dev/null +++ b/textbook/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/textbook/views.py b/textbook/views.py new file mode 100644 index 0000000000..6cc9e8ba6c --- /dev/null +++ b/textbook/views.py @@ -0,0 +1,18 @@ +from djangomako.shortcuts import render_to_response, render_to_string +from django.shortcuts import redirect +import os +from django.conf import settings +from django.http import Http404 + +# We don't do subdirectories to reduce odds of possible future +# security issues. Feel free to re-add them if needed -- just make +# sure things like /../../etc/passwd are handled okay. + +valid_files=os.listdir(settings.TEXTBOOK_DIR) + +def index(request, filename): + if filename in valid_files: + text=open(settings.TEXTBOOK_DIR+filename).read() + return render_to_response('textbook.html',{'text':text}) + else: + raise Http404