diff --git a/package.json b/package.json index 0b8a90e..96220ba 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,10 @@ "bootstrap": "=3.3.5", "ionicons": "=2.0.1", "jquery": "=2.1.4", - "markdown": "=0.5.0", "normalize.css": "=3.0.3", "react": "=0.13.3", "react-bootstrap": "=0.25.1", - "whatwg-fetch": "^0.10.1" + "whatwg-fetch": "=0.10.1" }, "devDependencies": { "babel-preset-es2015": "=6.1.18", diff --git a/project/common/views.py b/project/common/views.py index b6e89fc..00be20a 100644 --- a/project/common/views.py +++ b/project/common/views.py @@ -1,5 +1,7 @@ from django.views.generic import TemplateView, FormView - +from django.template import loader, Context, TemplateDoesNotExist +from django.http import Http404 +import markdown2 class CustomTemplate(TemplateView): html_title = "" @@ -23,3 +25,22 @@ class CustomFormTemplate(FormView): context['body_class'] = self.body_class context['js_redirect'] = True return context + + +class MarkdownView(CustomTemplate): + template_name = 'markdown_content.html' + page_title = "" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['page_title'] = self.page_title + try: + markdown_template = loader.get_template(self.markdown) + except TemplateDoesNotExist: + raise Http404 + c = Context(self.get_markdown_context().update(context)) + context['markdown_content'] = markdown2.markdown(markdown_template.render(c)) + return context + + def get_markdown_context(self): + return {} diff --git a/project/pages/urls.py b/project/pages/urls.py index bdac39a..bb490f6 100644 --- a/project/pages/urls.py +++ b/project/pages/urls.py @@ -6,5 +6,6 @@ urlpatterns = [ url(r'^about/website/$', views.AboutWebsiteView.as_view(), name='about-website'), url(r'^about/me/$', views.AboutMeView.as_view(), name='about-me'), url(r'^about/$', views.AboutIndexView.as_view(), name='about'), + url(r'^projects/(?P.+)/$', views.ProjectsView.as_view(), name="projects"), url(r'^$', views.IndexView.as_view(), name='index') ] diff --git a/project/pages/views.py b/project/pages/views.py index c54db78..22d6cc0 100644 --- a/project/pages/views.py +++ b/project/pages/views.py @@ -1,4 +1,4 @@ -from project.common.views import CustomTemplate, CustomFormTemplate +from project.common.views import CustomTemplate, CustomFormTemplate, MarkdownView from project.common.forms import ContactForm @@ -39,3 +39,13 @@ class AboutIndexView(CustomFormTemplate): class AboutMeView(CustomTemplate): template_name = 'about/me.html' html_title = "About Me" + + +class AllProjectsView(CustomTemplate): + template_name = 'projects/all.html' + + +class ProjectsView(MarkdownView): + def dispatch(self, request, *args, **kwargs): + self.markdown = 'projects/{0}.md'.format(kwargs['project']) + return super().dispatch(request, *args, **kwargs) diff --git a/requirements.txt b/requirements.txt index eff3d55..67ee25f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ django-bootstrap-form==3.2 git+https://github.com/RealOrangeOne/django-client-reverse django-flat-theme==1.1.3 djangorestframework==3.3.2 +markdown2==2.3.0 flake8==2.5.0 whitenoise==2.0.6 waitress==0.8.10 diff --git a/templates/markdown_content.html b/templates/markdown_content.html new file mode 100644 index 0000000..e1401bc --- /dev/null +++ b/templates/markdown_content.html @@ -0,0 +1,10 @@ +{% extends 'content_base.html' %} + +{% block pageTitle %}{{ page_title }}{% endblock %} + +{% block content %} +
+ {{ markdown_content | safe }} +
+ +{% endblock %} diff --git a/templates/projects/all.html b/templates/projects/all.html new file mode 100644 index 0000000..1021401 --- /dev/null +++ b/templates/projects/all.html @@ -0,0 +1,10 @@ +{% extends 'content_base.html' %} + +{% block pageTitle %}All Projects{% endblock %} + +{% block content %} + +
+

Stuff

+
+{% endblock %} diff --git a/templates/projects/test.md b/templates/projects/test.md new file mode 100644 index 0000000..ef93b24 --- /dev/null +++ b/templates/projects/test.md @@ -0,0 +1 @@ +# Test!