Skip to content

Commit a50d679

Browse files
authored
feat: Add re-usable components (#220)
1 parent d540b1e commit a50d679

File tree

122 files changed

+2240
-501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+2240
-501
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ insert_final_newline = false
3838

3939
[*plugins/image.html]
4040
insert_final_newline = false
41+
42+
[*.html]
43+
indent_size = 2

.github/workflows/codecov.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,12 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
python-version: [ 3.8, 3.9, "3.10", "3.11"] # latest release minus two
15+
python-version: ["3.10", "3.11", "3.12"] # latest release minus two
1616
requirements-file: [
17-
dj32_cms38.txt,
18-
dj32_cms39.txt,
19-
dj32_cms41.txt,
20-
dj40_cms311.txt,
21-
dj41_cms311.txt,
2217
dj42_cms311.txt,
23-
dj40_cms41.txt,
24-
dj41_cms41.txt,
2518
dj42_cms41.txt,
19+
dj50_cms41.txt,
20+
dj51_cms41.txt,
2621
]
2722
os: [
2823
ubuntu-20.04,
@@ -40,6 +35,6 @@ jobs:
4035
- name: Generate Report
4136
run: |
4237
pip install -r tests/requirements/${{ matrix.requirements-file }}
43-
coverage run setup.py test
38+
coverage run run_tests.py
4439
- name: Upload Coverage to Codecov
4540
uses: codecov/codecov-action@v4

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.in') }}
2626
restore-keys: |
2727
${{ runner.os }}-pip-
28-
- run: python -m pip install -r docs/requirements.in
28+
- run: python -m pip install -r docs/requirements.txt
2929
- name: Build docs
3030
run: |
3131
cd docs
@@ -50,7 +50,7 @@ jobs:
5050
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.in') }}
5151
restore-keys: |
5252
${{ runner.os }}-pip-
53-
- run: python -m pip install -r docs/requirements.in
53+
- run: python -m pip install -r docs/requirements.txt
5454
- name: Check spelling
5555
run: |
5656
cd docs

README.rst

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,31 @@ currently used frontend framework such as Bootstrap, or its specific version.
1414
Key features
1515
============
1616

17-
- Support of `Bootstrap 5 <https://getbootstrap.com>`_, django CMS 3.8+
18-
and the new upcoming major django CMS 4.
17+
- Support of `Bootstrap 5 <https://getbootstrap.com>`_, django CMS 3.8+
18+
and django CMS 4.
1919

20-
- **Separation of plugins from css framework**, i.e. no need to
21-
rebuild you site's plugin tree if css framework is changed in the
22-
future, e.g. from Bootstrap 5 to a future version.
20+
- **Separation of plugins from css framework**, i.e. no need to
21+
rebuild you site's plugin tree if css framework is changed in the
22+
future, e.g. from Bootstrap 5 to a future version.
2323

24-
- **New link plugin** allowing to link to internal pages provided by
25-
other applications, such as `djangocms-blog
26-
<https://github.com/nephila/djangocms-blog>`_.
24+
- **New link plugin** allowing to link to internal pages provided by
25+
other applications, such as `djangocms-blog
26+
<https://github.com/nephila/djangocms-blog>`_.
2727

28-
- **Nice and well-arranged admin frontend** of `djangocms-bootstrap4
29-
<https://github.com/django-cms/djangocms-bootstrap4>`_
28+
- **Nice and well-arranged admin frontend** of `djangocms-bootstrap4
29+
<https://github.com/django-cms/djangocms-bootstrap4>`_
30+
31+
- **Extensible** within the project and with separate project (e.g. a
32+
theme app). Create your own components with a few lines of code only.
33+
34+
- **Plugins are re-usable as UI components** anywhere in your project
35+
(e.g. in a custom app) giving your whole project a more consistent
36+
user experience.
3037

3138
- A management command to **migrate from djangocms-bootstrap4**. This
3239
command automatically migrates all ``djangocms-bootstrap4`` plugins to
3340
``djangocms-frontend``.
3441

35-
- **Extensible** within the project and with separate project (e.g. a
36-
theme app)
37-
3842

3943
Description
4044
===========
@@ -55,6 +59,10 @@ The link plugin has been rewritten to not only allow internal links to other
5559
CMS pages, but also to other django models such as, e.g., posts of
5660
`djangocms-blog <https://github.com/nephila/djangocms-blog>`_.
5761

62+
The plugins are designed to be re-usable as UI components in your
63+
project, e.g. in a custom app, giving your whole project a more
64+
consistent user experience.
65+
5866
Contributing
5967
============
6068

@@ -150,7 +158,7 @@ See readthedocs for the `documentation
150158
License
151159
=======
152160

153-
See `LICENSE <https://github.com/django-cms/djangocms-frontend/blob/master/LICENSE>`_.
161+
See `LICENSE <https://github.com/django-cms/djangocms-frontend/blob/master/LICENSE>`_.
154162

155163
.. |pypi| image:: https://badge.fury.io/py/djangocms-frontend.svg
156164
:target: http://badge.fury.io/py/djangocms-frontend

djangocms_frontend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
13. Github actions will publish the new package to pypi
2020
"""
2121

22-
__version__ = "1.3.4"
22+
__version__ = "2.0.0a"

djangocms_frontend/apps.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django import apps
2+
3+
4+
class DjangocmsFrontendConfig(apps.AppConfig):
5+
name = "djangocms_frontend"
6+
verbose_name = "DjangoCMS Frontend"
7+
8+
def ready(self):
9+
from .component_pool import setup
10+
11+
setup()

djangocms_frontend/cms_plugins.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,44 @@
1+
from cms.constants import SLUG_REGEXP
12
from cms.plugin_base import CMSPluginBase
23
from django.utils.encoding import force_str
34

5+
from djangocms_frontend.helpers import get_related
46

5-
class CMSUIPlugin(CMSPluginBase):
7+
if hasattr(CMSPluginBase, "edit_field"):
8+
# FrontendEditable functionality already implemented in core?
9+
FrontendEditableAdminMixin = object
10+
else:
11+
# If not use our own version of the plugin-enabled mixin
12+
from .helpers import FrontendEditableAdminMixin
13+
14+
15+
class CMSUIPlugin(FrontendEditableAdminMixin, CMSPluginBase):
616
render_template = "djangocms_frontend/html_container.html"
717
change_form_template = "djangocms_frontend/admin/base.html"
818

919
def __str__(self):
1020
return force_str(super().__str__())
21+
22+
def render(self, context, instance, placeholder):
23+
for key, value in instance.config.items():
24+
if isinstance(value, dict) and set(value.keys()) == {"pk", "model"}:
25+
if key not in instance.__dir__(): # hasattr would return the value in the config dict
26+
setattr(instance.__class__, key, get_related(key))
27+
return super().render(context, instance, placeholder)
28+
29+
def get_plugin_urls(self):
30+
from django.urls import re_path
31+
32+
info = f"{self.model._meta.app_label}_{self.model._meta.model_name}"
33+
34+
def pat(regex, fn):
35+
return re_path(regex, fn, name=f"{info}_{fn.__name__}")
36+
37+
return [
38+
pat(r'edit-field/(%s)/([a-z\-]+)/$' % SLUG_REGEXP, self.edit_field),
39+
]
40+
41+
def _get_object_for_single_field(self, object_id, language):
42+
from .models import FrontendUIItem
43+
44+
return FrontendUIItem.objects.get(pk=object_id)

djangocms_frontend/common/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from importlib import import_module
2+
3+
from djangocms_frontend import settings
4+
5+
from .title import TitleFormMixin, TitleMixin
6+
7+
__common = {
8+
"attributes": ("AttributesMixin",),
9+
"background": ("BackgroundFormMixin", "BackgroundMixin"),
10+
"responsive": ("ResponsiveFormMixin", "ResponsiveMixin"),
11+
"sizing": ("SizingFormMixin", "SizingMixin"),
12+
"spacing": ("SpacingFormMixin", "SpacingMixin", "MarginFormMixin", "MarginMixin", "PaddingFormMixin", "PaddingMixin"),
13+
}
14+
15+
for module, classes in __common.items():
16+
try:
17+
module = import_module(f"{__name__}.{settings.framework}.{module}", module)
18+
for cls in classes:
19+
globals()[cls] = getattr(module, cls)
20+
except ModuleNotFoundError:
21+
for cls in classes:
22+
globals()[cls] = type(cls, (object,), {})
23+
24+
__all__ = [
25+
"TitleMixin",
26+
"TitleFormMixin",
27+
"AttributesMixin",
28+
"BackgroundFormMixin",
29+
"BackgroundMixin",
30+
"ResponsiveFormMixin",
31+
"ResponsiveMixin",
32+
"SizingFormMixin",
33+
"SizingMixin",
34+
"SpacingFormMixin",
35+
"SpacingMixin",
36+
"MarginFormMixin",
37+
"MarginMixin",
38+
"PaddingFormMixin",
39+
"PaddingMixin",
40+
]

djangocms_frontend/common/background.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)