Skip to content

Commit

Permalink
Fix example app
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed May 16, 2021
1 parent 0fb8c5c commit 02a1693
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 4.0.0 - In development

- Fix example app.
- Rename `FontAwesomeRenderer` to `FontAwesome4Renderer` (#48).
- Fix PyPI description.
- Fix PyPI classifiers.
Expand Down
4 changes: 3 additions & 1 deletion example/README.rst → example/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Example project for django-icons

This example project only supports the latest version of Django.

## Instructions

To run the example:

```
```bash
git clone https://github.com/zostera/django-icons.git

cd django-icons/example
Expand Down
Empty file added example/__init__.py
Empty file.
33 changes: 33 additions & 0 deletions example/app/renderers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from django_icons.renderers import BaseRenderer, ImageRenderer


class CustomSvgRenderer(BaseRenderer):
"""
Render an SVG.
<svg class="svg-icon" viewBox="0 0 32 32"><use xlink:href="#icon-feather"></use></svg>
"""

def get_tag(self):
return "svg"

def get_class(self):
return "svg-icon"

def get_attrs(self):
attrs = super(CustomSvgRenderer, self).get_attrs()
attrs["viewBox"] = "0 0 32 32"
return attrs

def get_content(self):
return '<use xlink:href="#icon-{name}"></use>'.format(name=self.name)


class CustomImageRenderer(ImageRenderer):
def get_image_root(cls):
return "hd-icons"


class CustomIcons8Renderer(ImageRenderer):
def get_image_prefix(self):
return "icons8-"
9 changes: 0 additions & 9 deletions example/app/urls.py

This file was deleted.

Binary file added example/assets/icons/wikimedia-download.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added example/db.sqlite3
Empty file.
116 changes: 77 additions & 39 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,49 @@

BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ""))

# Include SRC_FOLDER in path
SRC_FOLDER = os.path.abspath(os.path.join(BASE_DIR, "..", "src"))
if SRC_FOLDER not in sys.path:
sys.path.insert(0, SRC_FOLDER)
DJANGO_ICONS_FOLDER = os.path.abspath(os.path.join(BASE_DIR, "..", "django_icons"))
if DJANGO_ICONS_FOLDER not in sys.path:
sys.path.insert(0, DJANGO_ICONS_FOLDER)

SECRET_KEY = "Thank you for using django-icons!"
DEBUG = True
ALLOWED_HOSTS = []

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_icons",
"tests.app",
]
ADMINS = ()

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

ALLOWED_HOSTS = ["localhost", "127.0.0.1"]

TIME_ZONE = "Europe/Amsterdam"

LANGUAGE_CODE = "en-us"

USE_I18N = True

USE_L10N = True

USE_TZ = True

MEDIA_ROOT = ""

MEDIA_URL = ""

STATIC_ROOT = ""

STATIC_URL = "/static/"

STATICFILES_DIRS = ("assets",)

STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

SECRET_KEY = "8s)l4^2s&&0*31-)+6lethmfy3#r1egh^6y^=b9@g!q63r649_"

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
Expand All @@ -33,52 +57,66 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "tests.app.urls"
ROOT_URLCONF = "urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": ["templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.request",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
"django.template.context_processors.media",
"django.template.context_processors.static",
"django.template.context_processors.tz",
"django.contrib.messages.context_processors.messages",
]
},
}
]

WSGI_APPLICATION = "tests.app.wsgi.application"

DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = "/static/"
INSTALLED_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.admin",
"django_icons",
"app",
)

LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
"handlers": {
"mail_admins": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
}
},
"loggers": {"django.request": {"handlers": ["mail_admins"], "level": "ERROR", "propagate": True}},
}

DJANGO_ICONS = {
"DEFAULTS": {"renderer": "fontawesome", "attrs": {"aria-hidden": True}},
"DEFAULTS": {"renderer": "fontawesome4", "attrs": {"aria-hidden": True}},
"RENDERERS": {
"fontawesome": "FontAwesomeRenderer",
"fontawesome4": "FontAwesome4Renderer",
"bootstrap3": "Bootstrap3Renderer",
"material": "MaterialRenderer",
"image": "ImageRenderer",
},
"ICONS": {
"delete": "trash",
"edit": {"name": "pencil", "title": "Edit"},
"feather": {"renderer": "tests.app.renderers.CustomSvgRenderer"},
"paperplane": {"renderer": "tests.app.renderers.CustomSvgRenderer"},
"feather": {"renderer": "app.renderers.CustomSvgRenderer"},
"paperplane": {"renderer": "app.renderers.CustomSvgRenderer"},
},
}
File renamed without changes.
11 changes: 5 additions & 6 deletions example/app/templates/home.html → example/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

<p>
{% icon 'user' %}
The `user` icon from FontAwesome
The `user` icon from FontAwesome 4
</p>

<p>
{% icon 'delete' size='lg' %}
The `trash` icon from FontAwesome in a larger size, connected to the `delete` name in `settings.py`.
The `trash` icon from FontAwesome 4 in a larger size, connected to the `delete` name in `settings.py`.
</p>

<p>
{% icon 'star' renderer='Bootstrap3Renderer' %}
The `star` icon from Bootstrap3, with the renderer explicitly set
The `star` icon from Bootstrap 3, with the renderer explicitly set
</p>

<p>
Expand All @@ -31,8 +31,8 @@
</p>

<p>
{% icon 'icons8-icons8-48' renderer='ImageRenderer' %}
The `icons8` icon from Icons8, with the renderer explicitly set
{% icon 'wikimedia-download' renderer='ImageRenderer' %}
The <a href="https://commons.wikimedia.org/wiki/File:Download-Icon.png" target="_blank">WikiMedia Download Icon</a>, with the renderer explicitly set
</p>

<p>
Expand All @@ -45,5 +45,4 @@
A `feather` icon that is included in the source as SVG, with an extra class to render the outline
</p>


{% endblock %}
7 changes: 7 additions & 0 deletions example/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.conf.urls import url

from app.views import HomeView

urlpatterns = [
url(r"^$", HomeView.as_view(), name="home"),
]

0 comments on commit 02a1693

Please sign in to comment.