Skip to content

Commit

Permalink
Merge pull request #25 from jaap3/renovate
Browse files Browse the repository at this point in the history
Renovate
  • Loading branch information
jaap3 authored Mar 7, 2024
2 parents 95ead14 + 99a2b9b commit d34b4f0
Show file tree
Hide file tree
Showing 24 changed files with 288 additions and 227 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ end_of_line = lf

[*.py]
max_line_length = 119

[{*.yml,*.yaml}]
indent_size = 2
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @jaap3
70 changes: 70 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Lint
run: make lint

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
# Keep in sync with tox.ini
- '3.8'
- '3.10'
- '3.12'

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox

coverage:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Collect coverage
run: |
coverage run --source djrichtextfield --branch manage.py test
coverage xml
- name: Report coverage
uses: orgoro/coverage@v3.1
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

7 changes: 2 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ Django Rich Text Field
:target: https://pypi.python.org/pypi/django-richtextfield/
:alt: Latest Version

.. image:: https://travis-ci.org/jaap3/django-richtextfield.svg?branch=master
:target: https://travis-ci.org/jaap3/django-richtextfield

.. image:: https://coveralls.io/repos/jaap3/django-richtextfield/badge.svg?branch=master
:target: https://coveralls.io/r/jaap3/django-richtextfield?branch=master
.. image:: https://github.com/jaap3/django-richtextfield/actions/workflows/ci.yml/badge.svg?branch=master
:target: https://github.com/jaap3/django-richtextfield/actions/workflows/ci.yml

A Django model field and widget that renders a customizable rich
text/WYSIWYG widget.
Expand Down
2 changes: 1 addition & 1 deletion djrichtextfield/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, *args, field_settings=None, **kwargs):
super(RichTextField, self).__init__(*args, **kwargs)

def formfield(self, **kwargs):
kwargs['widget'] = RichTextWidget(
kwargs["widget"] = RichTextWidget(
field_settings=self.field_settings, sanitizer=self.sanitizer
)
return super(RichTextField, self).formfield(**kwargs)
Expand Down
6 changes: 3 additions & 3 deletions djrichtextfield/sanitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class SanitizerMixin:
Get the field sanitizer from the provided kwargs during init, or from the settings.
"""

SANITIZER_KEY = 'sanitizer'
SANITIZER_PROFILES_KEY = 'sanitizer_profiles'
SANITIZER_KEY = "sanitizer"
SANITIZER_PROFILES_KEY = "sanitizer_profiles"

def __init__(self, *args, sanitizer=None, **kwargs):
self.sanitizer = sanitizer
Expand All @@ -34,7 +34,7 @@ def get_sanitizer(self):

if not sanitizer:
default_sanitizer = settings.CONFIG.get(self.SANITIZER_KEY)
field_settings = getattr(self, 'field_settings', None)
field_settings = getattr(self, "field_settings", None)
if isinstance(field_settings, str):
profiles = settings.CONFIG.get(self.SANITIZER_PROFILES_KEY, {})
sanitizer = profiles.get(field_settings, default_sanitizer)
Expand Down
12 changes: 6 additions & 6 deletions djrichtextfield/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from django.test.signals import setting_changed

DEFAULT_CONFIG = {
'js': [],
'css': {},
'init_template': None,
'settings': {},
"js": [],
"css": {},
"init_template": None,
"settings": {},
}
CONFIG = DEFAULT_CONFIG.copy()
CONFIG.update(getattr(settings, 'DJRICHTEXTFIELD_CONFIG', {}))
CONFIG.update(getattr(settings, "DJRICHTEXTFIELD_CONFIG", {}))


@receiver(setting_changed)
def update_settings(setting=None, value=None, **kwargs):
global CONFIG
if setting == 'DJRICHTEXTFIELD_CONFIG': # pragma: no branch
if setting == "DJRICHTEXTFIELD_CONFIG": # pragma: no branch
CONFIG = DEFAULT_CONFIG.copy()
if value: # pragma: no branch
CONFIG.update(value)
2 changes: 1 addition & 1 deletion djrichtextfield/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from djrichtextfield.views import InitView

urlpatterns = [
path('init.js', InitView.as_view(), name='djrichtextfield_init'),
path("init.js", InitView.as_view(), name="djrichtextfield_init"),
]
10 changes: 5 additions & 5 deletions djrichtextfield/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@


class InitView(TemplateView):
template_name = 'djrichtextfield/init.js'
content_type = 'application/javascript'
template_name = "djrichtextfield/init.js"
content_type = "application/javascript"

def get_settings_json(self):
return mark_safe(json.dumps(settings.CONFIG['settings'], default=force_str))
return mark_safe(json.dumps(settings.CONFIG["settings"], default=force_str))

def get_context_data(self, **kwargs):
context_data = super(InitView, self).get_context_data(**kwargs)
context_data['default_settings'] = self.get_settings_json()
context_data['init_template'] = settings.CONFIG['init_template']
context_data["default_settings"] = self.get_settings_json()
context_data["init_template"] = settings.CONFIG["init_template"]
return context_data
32 changes: 18 additions & 14 deletions djrichtextfield/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,32 @@


class RichTextWidget(SanitizerMixin, Textarea):
CSS_CLASS = 'djrichtextfield'
INIT_URL = 'djrichtextfield_init'
SETTINGS_ATTR = 'data-field-settings'
CONTAINER_CLASS = 'fieldBox'
PROFILE_KEY = 'profiles'
CSS_CLASS = "djrichtextfield"
INIT_URL = "djrichtextfield_init"
SETTINGS_ATTR = "data-field-settings"
CONTAINER_CLASS = "fieldBox"
PROFILE_KEY = "profiles"

def __init__(self, attrs=None, field_settings=None, sanitizer=None):
defaults = {'class': self.CSS_CLASS}
defaults = {"class": self.CSS_CLASS}
if attrs:
if 'class' in attrs:
attrs['class'] = ' '.join([
attrs['class'],
defaults['class'],
])
if "class" in attrs:
attrs["class"] = " ".join(
[
attrs["class"],
defaults["class"],
]
)
defaults.update(attrs)
self.field_settings = field_settings or {}
super(RichTextWidget, self).__init__(defaults, sanitizer=sanitizer)

@property
def media(self):
js = []
js.extend(settings.CONFIG['js'])
js.extend(settings.CONFIG["js"])
js.append(reverse(self.INIT_URL))
return Media(js=js, css=settings.CONFIG['css'])
return Media(js=js, css=settings.CONFIG["css"])

def get_field_settings(self):
"""
Expand All @@ -54,7 +56,9 @@ def render(self, name, value, attrs=None, renderer=None):
field_settings = self.get_field_settings()
if field_settings:
attrs[self.SETTINGS_ATTR] = json.dumps(field_settings, default=force_str)
textarea = super(RichTextWidget, self).render(name, value, attrs=attrs, renderer=renderer)
textarea = super(RichTextWidget, self).render(
name, value, attrs=attrs, renderer=renderer
)
return format_html('<div class="{0}">{1}</div>', self.CONTAINER_CLASS, textarea)

def value_from_datadict(self, *args, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Django
wheel
coverage
coveralls
flake8
tox
50 changes: 25 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@

from setuptools import setup

version = '1.6.2.dev0'
version = "1.6.2.dev0"

if sys.argv[-1] == 'publish':
os.system('python setup.py sdist bdist_wheel upload')
if sys.argv[-1] == "publish":
os.system("python setup.py sdist bdist_wheel upload")
print("You probably want to also tag the version now:")
print(" git tag -a %s -m 'version %s'" % (version, version))
print(" git push --tags")
sys.exit()

readme = open('README.rst').read()
history = open('HISTORY.rst').read()
readme = open("README.rst").read()
history = open("HISTORY.rst").read()

setup(
name='django-richtextfield',
name="django-richtextfield",
version=version,
description='A Django model field and widget that renders a customizable WYSIWYG/rich text editor',
long_description=readme + '\n\n' + history,
author='Jaap Roes',
author_email='jaap.roes@gmail.com',
url='https://github.com/jaap3/django-richtextfield',
description="A Django model field and widget that renders a customizable WYSIWYG/rich text editor",
long_description=readme + "\n\n" + history,
author="Jaap Roes",
author_email="jaap.roes@gmail.com",
url="https://github.com/jaap3/django-richtextfield",
packages=[
'djrichtextfield',
"djrichtextfield",
],
include_package_data=True,
install_requires=[],
python_requires='>=3.6',
license='MIT',
python_requires=">=3.6",
license="MIT",
zip_safe=False,
keywords='django-richtextfield, djrichtextfield django wywiwyg field',
keywords="django-richtextfield, djrichtextfield django wywiwyg field",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Natural Language :: English',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
"Development Status :: 5 - Production/Stable",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)
Loading

0 comments on commit d34b4f0

Please sign in to comment.