-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New icon app in contrib including icon picker for wide set of i…
…con libraries (#110) * Upgrade to bootstrap5, add inital icon contrib package * Optimize css and js * Fix djlint * Update readme and changelog * Update docs * Add tests * Update test * fix flake8 * No coverage of IconPickerWidget * Update test * isort tests * Improve test coverage * add migration command * Fix flake8 * Fix: migration of icons * Fix icon migration * Dark mode css tweak, docs update, naming typos and spacings for icons * Improve flake8 and isort friendlyness * Fix: Display empty content
- Loading branch information
Showing
177 changed files
with
59,771 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ | |
13. Github actions will publish the new package to pypi | ||
""" | ||
|
||
__version__ = "1.0.2" | ||
__version__ = "1.1.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
|
Empty file.
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,7 @@ | ||
from django.apps import AppConfig | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class IconConfig(AppConfig): | ||
name = "djangocms_frontend.contrib.icon" | ||
verbose_name = _("Icon") |
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,56 @@ | ||
from cms.plugin_pool import plugin_pool | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from ... import settings | ||
from ...cms_plugins import CMSUIPlugin | ||
from ...common.attributes import AttributesMixin | ||
from ...common.background import BackgroundMixin | ||
from ...common.responsive import ResponsiveMixin | ||
from ...common.spacing import SpacingMixin | ||
from .. import icon | ||
from . import forms, models | ||
|
||
mixin_factory = settings.get_renderer(icon) | ||
|
||
|
||
class IconPlugin( | ||
mixin_factory("Icon"), | ||
AttributesMixin, | ||
ResponsiveMixin, | ||
SpacingMixin, | ||
BackgroundMixin, | ||
CMSUIPlugin, | ||
): | ||
""" | ||
Universal icon picker | ||
https://github.com/migliori/universal-icon-picker | ||
""" | ||
|
||
name = _("Icon") | ||
module = _("Frontend") | ||
model = models.Icon | ||
form = forms.IconForm | ||
text_enabled = True | ||
|
||
fieldsets = [ | ||
( | ||
None, | ||
{ | ||
"fields": ( | ||
( | ||
"icon", | ||
"icon_size", | ||
), | ||
"icon_foreground", | ||
"icon_rounded", | ||
) | ||
}, | ||
), | ||
] | ||
|
||
|
||
if "IconPlugin" in plugin_pool.plugins: | ||
# Unregister already installed IconPlugin | ||
del plugin_pool.plugins["IconPlugin"] | ||
|
||
plugin_pool.register_plugin(IconPlugin) |
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,60 @@ | ||
from django.conf import settings | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
ICON_CDN = { | ||
"bootstrap-icons": "https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css", | ||
"font-awesome": "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css", | ||
"material-icons-filled": "https://fonts.googleapis.com/css2?family=Material+Icons", | ||
"material-icons-outlined": "https://fonts.googleapis.com/css2?family=Material+Icons+Outlined", | ||
"material-icons-round": "https://fonts.googleapis.com/css2?family=Material+Icons+Round", | ||
"material-icons-sharp": "https://fonts.googleapis.com/css2?family=Material+Icons+Sharp", | ||
"material-icons-two-tone": "https://fonts.googleapis.com/css2?family=Material+Icons+Two+Tone", | ||
"fomantic-ui": "fomantic-ui-icons.css", | ||
} | ||
|
||
ICON_LIBRARIES_SHOWN = getattr(settings, "DJANGOCMS_FRONTEND_ICONS_LIBRARIES_SHOWN", ( | ||
"font-awesome", | ||
"bootstrap-icons", | ||
"material-icons-filled", | ||
"material-icons-outlined", | ||
"material-icons-round", | ||
"material-icons-sharp", | ||
"material-icons-two-tone", | ||
"fomantic-ui", | ||
"foundation-icons", | ||
"elegant-icons", | ||
"feather-icons", | ||
"happy-icons", | ||
"icomoon", | ||
"open-iconic", | ||
"tabler-icons", | ||
"zondicons", | ||
"weather-icons", | ||
)) | ||
|
||
ICON_LIBRARIES = getattr( | ||
settings, | ||
"DJANGOCMS_FRONTEND_ICON_LIBRARIES", | ||
{ | ||
library: (f"{library}.min.json", ICON_CDN.get(library, f"{library}.css")) | ||
for library in getattr( | ||
settings, | ||
"DJANGOCMS_FRONTEND_ICON_LIBRARIES_SHOWN", | ||
ICON_LIBRARIES_SHOWN | ||
) | ||
}, | ||
) | ||
|
||
ICON_SIZE_CHOICES = getattr( | ||
settings, | ||
"DJANGOCMS_FRONTEND_ICON_SIZE_CHOICES", | ||
( | ||
("", _("Regular")), | ||
("200%", _("x 2")), | ||
("300%", _("x 3")), | ||
("400%", _("x 4")), | ||
("500%", _("x 5")), | ||
("800%", _("x 8")), | ||
("1200%", _("x 12")), | ||
), | ||
) |
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,34 @@ | ||
import json | ||
|
||
from cms.utils.urlutils import static_with_version | ||
from django.forms.fields import JSONField, TextInput | ||
|
||
from djangocms_frontend.contrib.icon.conf import ICON_LIBRARIES | ||
|
||
|
||
class IconPickerWidget(TextInput): # pragma: no cover | ||
class Media: | ||
js = ("djangocms_frontend/icon/vendor/assets/js/universal-icon-picker.min.js",) | ||
css = {"all": (static_with_version("cms/css/cms.icons.css"),)} | ||
|
||
template_name = "djangocms_frontend/admin/widgets/icon_picker.html" | ||
|
||
def get_context(self, name, value, attrs): | ||
context = super().get_context(name, value, attrs) | ||
try: | ||
json_obj = json.loads(value) or {} | ||
except ValueError: | ||
json_obj = {} | ||
context["widget"]["preview"] = json_obj.get("iconHtml", "") | ||
context["widget"]["library"] = json_obj.get("library", "") | ||
context["icon_libraries"] = [ | ||
(key, key.title(), value[0], value[1]) | ||
for key, value in ICON_LIBRARIES.items() | ||
] | ||
return context | ||
|
||
|
||
class IconPickerField(JSONField): | ||
def __init__(self, *args, **kwargs): | ||
kwargs.setdefault("widget", IconPickerWidget) | ||
super().__init__(*args, **kwargs) |
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,60 @@ | ||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
from entangled.forms import EntangledModelForm | ||
|
||
from djangocms_frontend.fields import ( | ||
AttributesFormField, | ||
ColoredButtonGroup, | ||
TagTypeFormField, | ||
) | ||
|
||
from ... import settings | ||
from ...common.background import BackgroundFormMixin | ||
from ...common.responsive import ResponsiveFormMixin | ||
from ...common.spacing import SpacingFormMixin | ||
from ...helpers import first_choice | ||
from ...models import FrontendUIItem | ||
from ...settings import COLOR_STYLE_CHOICES | ||
from .conf import ICON_SIZE_CHOICES | ||
from .fields import IconPickerField | ||
|
||
|
||
class IconForm(BackgroundFormMixin, ResponsiveFormMixin, SpacingFormMixin, EntangledModelForm): | ||
""" | ||
Layout > "Media" Plugin | ||
http://getbootstrap.com/docs/4.0/layout/media-object/ | ||
""" | ||
|
||
class Meta: | ||
model = FrontendUIItem | ||
entangled_fields = { | ||
"config": [ | ||
"icon", | ||
"icon_size", | ||
"icon_foreground", | ||
"icon_rounded", | ||
"attributes", | ||
] | ||
} | ||
untangled_fields = ("tag_type",) | ||
|
||
icon = IconPickerField() | ||
icon_size = forms.ChoiceField( | ||
label=_("Icon size"), | ||
choices=ICON_SIZE_CHOICES, | ||
initial=first_choice(ICON_SIZE_CHOICES), | ||
required=False, | ||
) | ||
icon_foreground = forms.ChoiceField( | ||
label=_("Foreground context"), | ||
choices=settings.EMPTY_CHOICE + COLOR_STYLE_CHOICES, | ||
initial=settings.EMPTY_CHOICE[0][0], | ||
widget=ColoredButtonGroup(), | ||
required=False, | ||
) | ||
icon_rounded = forms.BooleanField( | ||
label=_("Circular icon"), | ||
required=False, | ||
) | ||
attributes = AttributesFormField() | ||
tag_type = TagTypeFormField() |
Empty file.
Oops, something went wrong.