Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/django4 #16

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Run tests

on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Run tests
run: tox -vv
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"python.pythonPath": "/Users/Zentrale/.pyenv/shims/python"
}
"python.analysis.typeCheckingMode": "basic"
}
14 changes: 6 additions & 8 deletions djangocms_slick_slider/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.contrib import admin
from django.db import models
from django.forms import Textarea
Expand All @@ -11,14 +9,14 @@


class SlickerSliderAceMixin:
change_form_template = 'djangocms_slick_slider/change_form.html'
change_form_template = "djangocms_slick_slider/change_form.html"
text_area_attrs = {
'rows': 20,
'data-editor': True,
'data-mode': get_setting('SLICK_SLIDER_ACE_THEME'),
'data-theme': get_setting('SLICK_SLIDER_ACE_MODE'),
"rows": 20,
"data-editor": True,
"data-mode": get_setting("SLICK_SLIDER_ACE_THEME"),
"data-theme": get_setting("SLICK_SLIDER_ACE_MODE"),
}

formfield_overrides = {
models.TextField: {'widget': Textarea(attrs=text_area_attrs)}
models.TextField: {"widget": Textarea(attrs=text_area_attrs)}
}
25 changes: 17 additions & 8 deletions djangocms_slick_slider/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, division

import django
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

if django.VERSION >= (4, 0):
from django.utils.translation import gettext_lazy as _
else:
from django.utils.translation import ugettext_lazy as _

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
Expand Down Expand Up @@ -31,10 +33,11 @@ class SlickSliderPlugin(SlickerSliderAceMixin, CMSPluginBase):
You can define `SLICK_SLIDER_CONTAINER_WIDTH` to change the behaviors.
Check :class:`helpers.get_slider_image_dimensions` for more information.
"""

model = SlickSlider
form = SlickSliderForm
name = _('Slick Slider')
render_template = 'djangocms_slick_slider/base.html'
name = _("Slick Slider")
render_template = "djangocms_slick_slider/base.html"
cache = False
inlines = [
SlickSliderImageInline,
Expand All @@ -48,7 +51,13 @@ def render(self, context, instance, placeholder):

# define context vars
images = instance.images.all()
child_width = get_slider_image_dimensions(4)

context.update({'images': images, 'child_width': child_width})
if instance.settings:
no_of_images = instance.settings.get("slidesToShow", 4)
else:
no_of_images = 4

child_width = get_slider_image_dimensions(no_of_images)

context.update({"images": images, "child_width": child_width})
return context
6 changes: 1 addition & 5 deletions djangocms_slick_slider/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from django import forms

from .models import SlickSlider
Expand All @@ -12,5 +9,4 @@ class SlickSliderForm(forms.ModelForm):

def __init__(self, *args, **kwargs):
super(SlickSliderForm, self).__init__(*args, **kwargs)
self.fields['settings'].initial = get_setting(
'SLICK_SLICKER_DEFAULT_OPTIONS')
self.fields["settings"].initial = get_setting("SLICK_SLICKER_DEFAULT_OPTIONS")
74 changes: 43 additions & 31 deletions djangocms_slick_slider/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import django
from django.db import models
from django.utils.translation import ugettext_lazy as _

if django.VERSION >= (4, 0):
from django.utils.translation import gettext_lazy as _
else:
from django.utils.translation import ugettext_lazy as _

from cms.models.pluginmodel import CMSPlugin
from filer.fields.image import FilerImageField
Expand All @@ -10,58 +15,64 @@ class SlickSlider(CMSPlugin):
"""
Main Plugin Model for the slider.
"""

class Meta:
verbose_name = _('slick slider')
verbose_name_plural = _('slick sliders')
verbose_name = _("slick slider")
verbose_name_plural = _("slick sliders")

title = models.CharField(
verbose_name=_('slider title'),
verbose_name=_("slider title"),
max_length=255,
null=True,
blank=True,
)

settings = JSONField(
verbose_name=_('slick settings'),
verbose_name=_("slick settings"),
blank=True,
null=True,
help_text=_('Check <a href="http://kenwheeler.github.io/slick/" '
'target="_blank">'
'Slick Documentation</a> for possible settings '
'<br>'
'Use JSON format and check the errors in the editor<br>'
'You can also use online JSON validators'))
help_text=_(
'Check <a href="http://kenwheeler.github.io/slick/" '
'target="_blank">'
"Slick Documentation</a> for possible settings "
"<br>"
"Use JSON format and check the errors in the editor<br>"
"You can also use online JSON validators"
),
)

arrow_color = models.CharField(
verbose_name=_('arrow color'),
verbose_name=_("arrow color"),
max_length=255,
default="#666",
help_text=_('Define the color of slider arrows here. All CSS '
'color values work (e.g. #efefef).'),
help_text=_(
"Define the color of slider arrows here. All CSS "
"color values work (e.g. #efefef)."
),
)

full_width = models.BooleanField(
verbose_name=_('full width'),
verbose_name=_("full width"),
default=False,
)

slider_max_height = models.IntegerField(
verbose_name=_('max. height'),
verbose_name=_("max. height"),
blank=True,
null=True,
help_text=_('Define max height of the slider.'),
help_text=_("Define max height of the slider."),
)

image_max_width = models.IntegerField(
verbose_name=_('max. width'),
verbose_name=_("max. width"),
blank=True,
null=True,
help_text=_('Define max height of the slider.'),
help_text=_("Define max height of the slider."),
)

lazy_load_images = models.BooleanField(
verbose_name=_('lazy load images'),
help_text=_('Set to true if images should load lazily.'),
verbose_name=_("lazy load images"),
help_text=_("Set to true if images should load lazily."),
default=True,
)

Expand All @@ -86,10 +97,11 @@ class SlickSliderImage(models.Model):
"""
Image model für SlickSlider class.
"""

class Meta:
verbose_name = _('slider image')
verbose_name_plural = _('slider images')
ordering = ['position']
verbose_name = _("slider image")
verbose_name_plural = _("slider images")
ordering = ["position"]

slider = models.ForeignKey(
SlickSlider,
Expand All @@ -98,31 +110,31 @@ class Meta:
)

image = FilerImageField(
verbose_name=_('slider Image'),
related_name='slider_images_filer',
verbose_name=_("slider Image"),
related_name="slider_images_filer",
on_delete=models.CASCADE,
)

link = models.URLField(
verbose_name=_('image link'),
verbose_name=_("image link"),
null=True,
blank=True,
)

link_target = models.BooleanField(
verbose_name=_('image link target'),
help_text=_('open link in new window'),
verbose_name=_("image link target"),
help_text=_("open link in new window"),
default=True,
)

caption_text = models.TextField(
_('caption text'),
_("caption text"),
null=True,
blank=True,
)

position = models.IntegerField(
_('position'),
_("position"),
default=100,
)

Expand Down
32 changes: 14 additions & 18 deletions djangocms_slick_slider/settings.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

# these are the default settings for the slider
# change to your needs, if you like to
SLIDER_DEFAULT = {
'dots': True,
'slidesToShow': 2,
'mobileFirst': False,
'slidesToScroll': 1,
'autoplay': True,
'autoplaySpeed': 1500
"dots": True,
"slidesToShow": 2,
"mobileFirst": False,
"slidesToScroll": 1,
"autoplay": True,
"autoplaySpeed": 1500,
}


Expand All @@ -21,13 +17,13 @@ def get_setting(name):
from django.conf import settings

default = {
'SLICK_SLICKER_DEFAULT_OPTIONS':
getattr(settings, 'SLICK_SLICKER_DEFAULT_OPTIONS', SLIDER_DEFAULT),
'SLICK_SLIDER_ACE_THEME':
getattr(settings, 'SLICK_SLIDER_ACE_THEME', 'json'),
'SLICK_SLIDER_ACE_MODE':
getattr(settings, 'SLICK_SLIDER_ACE_MODE', 'github'),
'SLICK_SLIDER_CONTAINER_WIDTH':
getattr(settings, 'SLICK_SLIDER_CONTAINER_WIDTH', 1200)
"SLICK_SLICKER_DEFAULT_OPTIONS": getattr(
settings, "SLICK_SLICKER_DEFAULT_OPTIONS", SLIDER_DEFAULT
),
"SLICK_SLIDER_ACE_THEME": getattr(settings, "SLICK_SLIDER_ACE_THEME", "json"),
"SLICK_SLIDER_ACE_MODE": getattr(settings, "SLICK_SLIDER_ACE_MODE", "github"),
"SLICK_SLIDER_CONTAINER_WIDTH": getattr(
settings, "SLICK_SLIDER_CONTAINER_WIDTH", 1200
),
}
return default[name]
Loading