From e7e7128907f804c70701704dc8caf91a6e5e4ea9 Mon Sep 17 00:00:00 2001 From: Charles Holbrow Date: Thu, 18 Apr 2013 13:04:21 -0400 Subject: [PATCH] updating raw file rendering to class based view #105 --- karmaworld/apps/notes/views.py | 6 ------ karmaworld/templates/notes/note_raw.html | 6 +++++- karmaworld/urls.py | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/karmaworld/apps/notes/views.py b/karmaworld/apps/notes/views.py index 7a39dbe..9fc83ca 100644 --- a/karmaworld/apps/notes/views.py +++ b/karmaworld/apps/notes/views.py @@ -82,9 +82,3 @@ class RawNoteDetailView(DetailView): template_name = u'notes/note_raw.html' context_object_name = u"note" model = Note - - -def raw_file(request, pk): - """ Display the raw html from a Note object for embedding in an iframe """ - note = get_object_or_404(Note, pk=pk) - return HttpResponse(note.html) diff --git a/karmaworld/templates/notes/note_raw.html b/karmaworld/templates/notes/note_raw.html index 8ad99fc..c22220c 100644 --- a/karmaworld/templates/notes/note_raw.html +++ b/karmaworld/templates/notes/note_raw.html @@ -1 +1,5 @@ -{{ note.html|safe }} +{% if note.html %} + {{ note.html|safe }} +{% else %} +

Error: Note has no html

+{% endif %} diff --git a/karmaworld/urls.py b/karmaworld/urls.py index 60d06e6..c085e28 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -14,7 +14,7 @@ from karmaworld.apps.courses.views import CourseDetailView from karmaworld.apps.courses.views import CourseSaveView from karmaworld.apps.courses.views import school_list from karmaworld.apps.notes.views import NoteView -from karmaworld.apps.notes.views import raw_file +from karmaworld.apps.notes.views import RawNoteDetailView # See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf admin.autodiscover() @@ -33,7 +33,7 @@ urlpatterns = patterns('', url(r'^about/$', AboutView.as_view(), name='about'), # VIEW for viewing a Note's gdrive generated html, used as iframe - url(r'^raw/(?P\d+)$', raw_file, name='note_raw'), + url(r'^raw/(?P\d+)$', RawNoteDetailView.as_view(), name='note_raw'), # VIEW for displaying a single Course url(r'^(?P[^/]+)/(?P[-A-Za-z0-9_]+)$', \ -- 2.25.1