diff options
Diffstat (limited to 'pages')
-rw-r--r-- | pages/__init__.py | 0 | ||||
-rw-r--r-- | pages/management/__init__.py | 0 | ||||
-rw-r--r-- | pages/management/commands/__init__.py | 0 | ||||
-rw-r--r-- | pages/management/commands/parse_markdown.py | 31 | ||||
-rw-r--r-- | pages/models.py | 3 | ||||
-rw-r--r-- | pages/urls.py | 5 | ||||
-rw-r--r-- | pages/views.py | 18 |
7 files changed, 57 insertions, 0 deletions
diff --git a/pages/__init__.py b/pages/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pages/__init__.py diff --git a/pages/management/__init__.py b/pages/management/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pages/management/__init__.py diff --git a/pages/management/commands/__init__.py b/pages/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/pages/management/commands/__init__.py diff --git a/pages/management/commands/parse_markdown.py b/pages/management/commands/parse_markdown.py new file mode 100644 index 0000000..8c193df --- /dev/null +++ b/pages/management/commands/parse_markdown.py @@ -0,0 +1,31 @@ +import os +import markdown + +from django.core.management.base import BaseCommand, CommandError + +from settings import MARKDOWN_PATH, DEPLOY_PATH + +class Command(BaseCommand): + help = 'Parse markdown files in %s' % MARKDOWN_PATH + + def handle(self, *args, **options): + for root, dirs, files in os.walk(MARKDOWN_PATH): + for file in files: + subdir = root.replace(MARKDOWN_PATH, "") + mdfile = '%s/%s' % (root, file) + mdname = '%s/%s' % (subdir, os.path.splitext(file)[0]) + htmlpath = '%s/templates/html_pages/%s' % (DEPLOY_PATH, mdname) + htmlfile = '%s/index.html' % htmlpath + + if os.path.exists(mdfile) and not os.path.exists(htmlfile) \ + or os.path.getmtime(mdfile) > os.path.getmtime(htmlfile): + + if not os.path.exists(htmlpath): + os.makedirs(htmlpath) + + md = markdown.Markdown() + print 'Converting ', mdname, '-->', htmlfile, + wikiExtension = 'wikilinks(base_url=%s/)' % subdir + markdown.markdownFromFile(input=mdfile, output=htmlfile, encoding="utf-8", extensions=[wikiExtension]) + print ' ... succeeded' + diff --git a/pages/models.py b/pages/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/pages/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/pages/urls.py b/pages/urls.py new file mode 100644 index 0000000..1c0cf82 --- /dev/null +++ b/pages/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls.defaults import * + +urlpatterns = patterns('pages.views', + (r'^(?P<page>.+)/$', 'index'), +) diff --git a/pages/views.py b/pages/views.py new file mode 100644 index 0000000..7a44701 --- /dev/null +++ b/pages/views.py @@ -0,0 +1,18 @@ +import os.path + +from django.http import Http404 +from django.views.generic.simple import direct_to_template + +from settings import DEPLOY_PATH + +def index(request, page): + + template = 'html_pages/%s/index.html' % page + if not os.path.exists('%s/templates/%s' % (DEPLOY_PATH, template)): + raise Http404 + + c = { + "page": template, + } + + return direct_to_template(request, "pages/index.html", c) |