forked from django-cms/djangocms-link
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added file option to link (django-cms#172)
* Add link to filer file (if django_filer is installed) * Add option for document link to a Filer file (only if django-filer is installed) * Bug fix: __version__ not guaranteed in django_select2 * Remove migration necessary for Filer document * Base "Filer" detection on INSTALLED_APPS and not on availability as import * Drop Django 1.8 and 1.9 test since django_select2 does not support those versions any more * Newer tests * Fix cms 3.5 site_id reference * revert change * fix isort * added filer as a requirement * fix sorting * remove * make sure to tear down files
- Loading branch information
1 parent
932a406
commit ffb470b
Showing
10 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 2.2.2 on 2019-06-20 04:49 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations | ||
|
||
import filer.fields.file | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('filer', '0011_auto_20190418_0137'), | ||
('djangocms_link', '0013_fix_hostname'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='link', | ||
name='file_link', | ||
field=filer.fields.file.FilerFileField(blank=True, help_text='If provided links a file from the filer app.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='filer.File', verbose_name='File link'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
REQUIREMENTS = [ | ||
'django-cms>=3.4.5', | ||
'django-filer>=1.3.0', | ||
'djangocms-attributes-field>=0.4.0', | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
from django.conf import settings | ||
from django.core.files import File as DjangoFile | ||
|
||
from cms.api import add_plugin, create_page | ||
|
||
from djangocms_helper.base_test import BaseTestCase | ||
from filer.models.filemodels import File as FilerFile | ||
from filer.utils.compatibility import PILImage, PILImageDraw | ||
|
||
|
||
# from https://github.com/divio/django-filer/blob/develop/tests/helpers.py#L46-L52 | ||
def create_image(mode="RGB", size=(800, 600)): | ||
image = PILImage.new(mode, size) | ||
draw = PILImageDraw.Draw(image) | ||
x_bit, y_bit = size[0] // 10, size[1] // 10 | ||
draw.rectangle((x_bit, y_bit * 2, x_bit * 7, y_bit * 3), "red") | ||
draw.rectangle((x_bit * 2, y_bit, x_bit * 3, y_bit * 8), "red") | ||
return image | ||
|
||
|
||
class LinkTestCase(BaseTestCase): | ||
|
||
def setUp(self): | ||
self.page = create_page( | ||
title="help", | ||
template="page.html", | ||
language="en", | ||
) | ||
|
||
self.img = create_image() | ||
self.image_name = "test_file.jpg" | ||
self.filename = os.path.join(settings.FILE_UPLOAD_TEMP_DIR, self.image_name) | ||
self.img.save(self.filename, "JPEG") | ||
|
||
def tearDown(self): | ||
os.remove(self.filename) | ||
self.page.delete() | ||
self.filer_object.delete() | ||
pass | ||
|
||
def create_filer_file(self): | ||
filer_file = DjangoFile(open(self.filename, "rb"), name=self.image_name) | ||
self.filer_object = FilerFile.objects.create( | ||
original_filename=self.image_name, | ||
file=filer_file, | ||
) | ||
return self.filer_object | ||
|
||
def test_file(self): | ||
sample_file = self.create_filer_file() | ||
|
||
plugin = add_plugin( | ||
self.page.placeholders.get(slot="content"), | ||
"LinkPlugin", | ||
"en", | ||
file_link=sample_file | ||
) | ||
self.assertIn("test_file.jpg", plugin.get_link()) | ||
self.assertIn("/media/filer_public/", plugin.get_link()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters