Skip to content

Commit

Permalink
Download documents inline
Browse files Browse the repository at this point in the history
* Fixed issue of documents not being viewed inline without explicitly setting the download attribute on an <a> tag.
* Minor bug fixes
  • Loading branch information
Cory Sutyak authored and vsalvino committed Sep 14, 2018
1 parent b1406a0 commit 221f92c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 42 deletions.
42 changes: 0 additions & 42 deletions coderedcms/models/snippet_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,48 +280,6 @@ def __str__(self):
return self.name


@register_snippet
class ContentWall(models.Model):
"""
Snippet that restricts access to a page with a modal.
"""
class Meta:
verbose_name = _('Content Wall')

name = models.CharField(
max_length=255,
verbose_name=_('Name'),
)
content = StreamField(
LAYOUT_STREAMBLOCKS,
verbose_name=_('Content'),
)
is_dismissible = models.BooleanField(
default=True,
verbose_name=_('Dismissible'),
)
show_once = models.BooleanField(
default=True,
verbose_name=_('Show once'),
help_text=_('Do not show the content wall to the same user again after it has been closed.')
)

panels = [
MultiFieldPanel(
[
FieldPanel('name'),
FieldPanel('is_dismissible'),
FieldPanel('show_once'),
],
heading=_('Content Wall')
),
StreamFieldPanel('content'),
]

def __str__(self):
return self.name


class CoderedEmail(ClusterableModel):
"""
General purpose abstract clusterable model used for holding email information.
Expand Down
14 changes: 14 additions & 0 deletions coderedcms/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.http.response import HttpResponse
from django.utils.html import format_html
from wagtail.contrib.forms.models import AbstractForm
from wagtail.core import hooks
Expand All @@ -8,6 +9,7 @@
from coderedcms import utils
from coderedcms.models import CoderedFormPage

import mimetypes

@hooks.register('insert_global_admin_css')
def global_admin_css():
Expand Down Expand Up @@ -50,3 +52,15 @@ def codered_forms(user, editable_forms):
editable_forms = editable_forms.filter(content_type__in=form_types)

return editable_forms

@hooks.register('before_serve_document')
def serve_document_directly(document, request):
"""
This hook prevents documents from being downloaded unless specified by an <a> tag with the download attribute.
"""
content_type, content_encoding = mimetypes.guess_type(document.filename)
response = HttpResponse(document.file.read(), content_type=content_type)
response['Content-Disposition'] = 'inline;filename="{0}"'.format(document.filename)
response['Content-Encoding'] = content_encoding
return response

0 comments on commit 221f92c

Please sign in to comment.