Skip to content

Commit

Permalink
Merge pull request #295 from makinacorpus/improve_markup_public_view
Browse files Browse the repository at this point in the history
Fix media and static URL in document public HTML view
  • Loading branch information
submarcos authored Mar 27, 2024
2 parents 33e0f8e + cb10dc9 commit af5340f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
12 changes: 9 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ CHANGELOG
8.7.2+dev (XXXX-XX-XX)
-----------------------

**Bug fixes**

- Fix weasyprint html public view by converting file:// schemes with http://


8.7.2 (2024-03-22)
-------------------

**Bug fixes**

- 'Others' color config to use with leaflet overlay (#290)

8.7.1 (2024-03-13)
-------------------

8.7.1 (2024-03-13)
-----------------------

**Feature**

- Add current object in detail leaflet overlay (related to https://github.com/GeotrekCE/Geotrek-admin/issues/1300)


8.7.0 (2024-02-28)
-----------------------

Expand All @@ -34,7 +41,6 @@ CHANGELOG
- Support sub languages (see https://github.com/GeotrekCE/Geotrek-admin/issues/3801)



8.6.1 (2023-09-18)
-----------------------

Expand Down
14 changes: 14 additions & 0 deletions mapentity/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.test import TestCase, LiveServerTestCase
from django.test.testcases import to_list
from django.test.utils import override_settings
from django.urls import reverse
from django.utils import html
from django.utils.encoding import force_str
from django.utils.http import http_date
Expand All @@ -28,6 +29,7 @@
from .factories import AttachmentFactory, SuperUserFactory, UserFactory
from ..forms import MapEntityForm
from ..helpers import smart_urljoin
from ..models import ENTITY_MARKUP
from ..settings import app_settings

from paperclip.settings import get_attachment_model
Expand Down Expand Up @@ -123,6 +125,18 @@ def test_document_export(self, mock_requests):
response = self.client.get(obj.get_document_url())
self.assertEqual(response.status_code, 200)

@patch('mapentity.helpers.requests')
def test_document_markup(self, mock_requests):
if self.model is None:
return # Abstract test should not run

mock_requests.get.return_value.status_code = 200
mock_requests.get.return_value.content = b'<p id="properties">Mock</p>'

obj = self.modelfactory.create()
response = self.client.get(reverse(obj._entity.url_name(ENTITY_MARKUP), args=[obj.pk]))
self.assertEqual(response.status_code, 200)

def test_bbox_filter(self):
if self.model is None:
return # Abstract test should not run
Expand Down
12 changes: 12 additions & 0 deletions mapentity/views/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,18 @@ class MapEntityMarkupWeasyprint(MapEntityWeasyprint):
def get_entity_kind(cls):
return mapentity_models.ENTITY_MARKUP

def patch_static_file_paths(self, content):
""" Patch weasyprint renderer content to switch file://xxx paths to html scheme """
file_paths_media = f"file://{settings.MEDIA_ROOT}"
new_content = content.replace(file_paths_media, settings.MEDIA_URL)
file_paths_static = f"file://{settings.STATIC_ROOT}"
return new_content.replace(file_paths_static, settings.STATIC_URL)

def render_to_response(self, context, **response_kwargs):
response = super().render_to_response(context, **response_kwargs)
response.content = self.patch_static_file_paths(response.rendered_content)
return response


class MapEntityDocumentOdt(MapEntityDocumentBase):
response_class = OdtTemplateResponse
Expand Down

0 comments on commit af5340f

Please sign in to comment.