Skip to content

Commit

Permalink
Merge pull request #3 from maykinmedia/feature/CMS4-Support
Browse files Browse the repository at this point in the history
Update for DJango CMS 4
  • Loading branch information
alextreme authored Dec 9, 2024
2 parents b5b174c + e8944dc commit 6d1eabe
Show file tree
Hide file tree
Showing 41 changed files with 658 additions and 327 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Run CI

# Run this workflow every time a new commit pushed to your repository
on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.10', '3.11', '3.12']
django: ['3.2','4.2']
cms: ['4.1']

name: Run the test suite (Python ${{ matrix.python }}, Django ${{ matrix.django }}, CMS ${{ matrix.cms }})

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

- name: Install dependencies
run: pip install tox tox-gh-actions

- name: Run tests
run: tox
env:
PYTHON_VERSION: ${{ matrix.python }}
DJANGO: ${{ matrix.django }}
CMS: ${{ matrix.cms }}

- name: Publish coverage report
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

publish:
name: Publish package to PyPI
runs-on: ubuntu-latest
needs: tests
environment: release
permissions:
id-token: write

if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Build sdist and wheel
run: |
pip install build --upgrade
python -m build
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

33 changes: 33 additions & 0 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Code quality checks

# Run this workflow every time a new commit pushed to your repository
on:
push:
branches:
- main
tags:
- '*'
paths:
- '**.py'
pull_request:
paths:
- '**.py'
workflow_dispatch:

jobs:
linting:
name: Code-quality checks
runs-on: ubuntu-latest
strategy:
matrix:
toxenv: [isort, black, flake8, docs]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: pip install tox
- run: tox
env:
TOXENV: ${{ matrix.toxenv }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ venv.bak/

# mypy
.mypy_cache/

# Pycharm
.idea/
14 changes: 11 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Django CMS Export Page
:Keywords: ``django`` ``cms`` ``export`` ``docx``
:PythonVersion: 3.4

|build-status| |requirements| |coverage|
|build-status| |code-quality| |black| |coverage|

|python-versions| |django-versions| |pypi-version|

Expand Down Expand Up @@ -147,8 +147,9 @@ So with the cms settings it will look like this:
'test.html': ['test-placeholder']
}
.. |build-status| image:: https://travis-ci.org/maykinmedia/djangocms-export-page.svg?branch=develop
:target: https://travis-ci.org/maykinmedia/djangocms-export-page
.. |build-status| image:: https://github.com/maykinmedia/djangocms-export-page/workflows/Run%20CI/badge.svg
:alt: Build status
:target: https://github.com/maykinmedia/djangocms-export-page/actions?query=workflow%3A%22Run+CI%22

.. |requirements| image:: https://requires.io/github/maykinmedia/djangocms-export-page/requirements.svg?branch=develop
:target: https://requires.io/github/maykinmedia/djangocms-export-page/requirements/?branch=develop
Expand All @@ -164,3 +165,10 @@ So with the cms settings it will look like this:

.. |pypi-version| image:: https://img.shields.io/pypi/v/djangocms-export-page.svg
:target: https://pypi.org/project/djangocms-export-page/

.. |code-quality| image:: https://github.com/maykinmedia/djangocms-export-page/workflows/Code%20quality%20checks/badge.svg
:alt: Code quality checks
:target: https://github.com/maykinmedia/djangocms-export-page/actions?query=workflow%3A%22Code+quality+checks%22

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
3 changes: 0 additions & 3 deletions blogapp/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions blogapp/apps.py

This file was deleted.

Empty file removed blogapp/migrations/__init__.py
Empty file.
11 changes: 0 additions & 11 deletions blogapp/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions blogapp/tests.py

This file was deleted.

3 changes: 0 additions & 3 deletions blogapp/views.py

This file was deleted.

2 changes: 0 additions & 2 deletions djangocms_export_page/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
__version__ = "0.1.5"

default_app_config = 'djangocms_export_page.apps.DjangoCmsExportPageConfig'
2 changes: 1 addition & 1 deletion djangocms_export_page/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class DjangoCmsExportPageConfig(AppConfig):
Expand Down
18 changes: 10 additions & 8 deletions djangocms_export_page/cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cms.api import get_page_draft
from cms.toolbar.items import Break
Expand All @@ -19,7 +19,7 @@ def populate(self):
if not page or not user_can_change_page(self.request.user, page=page):
return

current_page_menu = self.toolbar.get_or_create_menu('page')
current_page_menu = self.toolbar.get_or_create_menu("page")
position = self.get_position(current_page_menu)

file_formats = FILE_FORMATS.values()
Expand All @@ -28,16 +28,18 @@ def populate(self):
menu = current_page_menu
else:
menu = current_page_menu.get_or_create_menu(
'export-page', _('Export'), position=position)
"export-page", _("Export"), position=position
)

for file_format in file_formats:
label = _('Export to {ext}').format(ext='.' + file_format.ext)
url = reverse('export-page:cms_page', kwargs={
'page_pk': page.pk,
'file_format': file_format.name})
label = _("Export to {ext}").format(ext="." + file_format.ext)
url = reverse(
"export-page:cms_page",
kwargs={"page_pk": page.pk, "file_format": file_format.name},
)
menu.add_link_item(label, url=url, position=position)

current_page_menu.add_break('export-page-break', position=position)
current_page_menu.add_break("export-page-break", position=position)

def get_position(self, menu):
# Last separator
Expand Down
9 changes: 4 additions & 5 deletions djangocms_export_page/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

from .export.docx import DocxPageExport

FileFormat = namedtuple('FileFormat', ['name', 'ext', 'content_type'])
FileFormat = namedtuple("FileFormat", ["name", "ext", "content_type"])

DOCX = 'docx'
DOCX = "docx"
DOCX_CONTENT_TYPE = (
'application/vnd'
'.openxmlformats-officedocument.wordprocessingml.document'
"application/vnd" ".openxmlformats-officedocument.wordprocessingml.document"
)

FILE_FORMATS = {
DOCX: FileFormat(DOCX, ext='docx', content_type=DOCX_CONTENT_TYPE),
DOCX: FileFormat(DOCX, ext="docx", content_type=DOCX_CONTENT_TYPE),
}


Expand Down
Loading

0 comments on commit 6d1eabe

Please sign in to comment.