diff --git a/cookbook/templates/generic/edit_template.html b/cookbook/templates/generic/edit_template.html index 443773c7c..189d4d91f 100644 --- a/cookbook/templates/generic/edit_template.html +++ b/cookbook/templates/generic/edit_template.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load crispy_forms_tags %} {% load i18n %} -{% load class_tag %} +{% load custom_tags %} {% block title %}{% trans 'Edit' %} - {{ title }}{% endblock %} diff --git a/cookbook/templates/generic/new_template.html b/cookbook/templates/generic/new_template.html index 5000072b6..fffc17472 100644 --- a/cookbook/templates/generic/new_template.html +++ b/cookbook/templates/generic/new_template.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load crispy_forms_tags %} {% load i18n %} -{% load class_tag %} +{% load custom_tags %} {% block title %}{% trans 'New' %} - {{ title }}{% endblock %} diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html new file mode 100644 index 000000000..6507e5191 --- /dev/null +++ b/cookbook/templates/recipe_view.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} +{% load crispy_forms_tags %} +{% load i18n %} +{% load custom_tags %} + +{% block title %}{% trans 'View' %}{% endblock %} + +{% block content %} + +

{{ recipe.name }}

+ + {{ recipe.instructions | markdown | safe }} + +{% endblock %} \ No newline at end of file diff --git a/cookbook/templatetags/class_tag.py b/cookbook/templatetags/custom_tags.py similarity index 52% rename from cookbook/templatetags/class_tag.py rename to cookbook/templatetags/custom_tags.py index 1cc6e30ff..708547060 100644 --- a/cookbook/templatetags/class_tag.py +++ b/cookbook/templatetags/custom_tags.py @@ -1,4 +1,5 @@ from django import template +import markdown as md register = template.Library() @@ -6,3 +7,8 @@ register = template.Library() @register.filter(name='get_class') def get_class(value): return value.__class__.__name__ + + +@register.filter() +def markdown(value): + return md.markdown(value, extensions=['markdown.extensions.fenced_code']) diff --git a/cookbook/urls.py b/cookbook/urls.py index 2ece95d3e..4ebf44da2 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -8,6 +8,8 @@ urlpatterns = [ path('', views.index, name='index'), path('test', views.test, name='test'), + path('view/recipe/', views.recipe_view, name='view_recipe'), + path('new/recipe/', new.RecipeCreate.as_view(), name='new_recipe'), path('new/recipe_import//', new.create_new_external_recipe, name='new_recipe_import'), path('new/keyword/', new.KeywordCreate.as_view(), name='new_keyword'), diff --git a/cookbook/views/views.py b/cookbook/views/views.py index c7a70c85b..c96db9209 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -1,4 +1,5 @@ -from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from django.shortcuts import render, get_object_or_404 from django_tables2 import RequestConfig from cookbook.filters import RecipeFilter @@ -18,5 +19,11 @@ def index(request): return render(request, 'index.html') +@login_required +def recipe_view(request, pk): + recipe = get_object_or_404(Recipe, pk=pk) + return render(request, 'recipe_view.html', {'recipe': recipe}) + + def test(request): return render(request, 'test.html') diff --git a/requirements.txt b/requirements.txt index 249224b43..9f7a0e426 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ six requests +markdown django django-tables2 django-filter