### Run Django Development Server Source: https://github.com/samueljennings/django-easy-icons/blob/main/example/README.md Command to start the Django development server for the easy-icons project. It requires navigating to the project directory and specifying the settings file. ```bash cd /path/to/django-easy-icons python manage.py runserver --settings=example.settings ``` -------------------------------- ### Install and Configure Django Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Installation instructions using pip and adding 'easy_icons' to Django's INSTALLED_APPS. This is the initial setup step for using the library. ```bash pip install django-easy-icons ``` ```python INSTALLED_APPS = [ # ... other apps 'easy_icons', ] ``` -------------------------------- ### Python Programmatic Icon Rendering Source: https://github.com/samueljennings/django-easy-icons/blob/main/example/README.md Demonstrates how to render icons programmatically in Python using the `easy_icons` library. Includes examples for default rendering, specific renderers, applying classes, and retrieving renderer instances. ```python import easy_icons from easy_icons.utils import get_renderer # Render icons svg_icon = easy_icons.icon("home") fa_icon = easy_icons.icon("heart", renderer="fontawesome") styled_icon = easy_icons.icon("star", renderer="fontawesome", class_="gold") # Get renderer info (if needed) fontawesome_renderer = get_renderer("fontawesome") ``` -------------------------------- ### Install Dependencies and Run Tests with Poetry Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Provides commands for setting up the project and running its tests using Poetry. It covers installing project dependencies, running the test suite, and generating a coverage report. This is essential for development and ensuring code quality. ```bash # Install dependencies poetry install # Run tests poetry run pytest # Run tests with coverage poetry run pytest --cov=easy_icons --cov-report=html ``` -------------------------------- ### Install and Configure Django Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/index.md This snippet shows how to install the `django-easy-icons` package using pip and configure it within your Django project's settings. It includes adding the app to `INSTALLED_APPS` and defining basic renderer configurations. ```bash pip install django-easy-icons ``` ```python INSTALLED_APPS = [ # ... other apps 'easy_icons', ] EASY_ICONS = { "default": { "renderer": "easy_icons.renderers.SvgRenderer", "config": { "svg_dir": "icons", # default template directory for SVG files "default_attrs": { "height": "1em", "fill": "currentColor" } }, } } ``` -------------------------------- ### Implement Sidebar Navigation with Icons in Django Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Provides a complete example of creating a sidebar navigation menu using Django templates. It integrates the `icon` template tag to display icons next to navigation links, enhancing visual clarity. ```django {% load easy_icons %} ``` -------------------------------- ### Dynamic Icon Loading Example Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Demonstrates how to dynamically load icons using Python within a Django application. This snippet would typically be part of a view or utility function that determines which icon to load based on certain conditions or data. ```python # This is a placeholder for the actual Python code. # The actual implementation would involve importing necessary modules # and logic to determine which icon to load dynamically. # Example: # from easy_icons.tags import icon # def get_dynamic_icon(icon_name, **kwargs): # Logic to determine icon name or attributes # For example, based on user role, settings, etc. # return icon(icon_name, **kwargs) pass ``` -------------------------------- ### Django Template Icon Rendering Source: https://github.com/samueljennings/django-easy-icons/blob/main/example/README.md Examples of rendering icons within Django templates using the `easy_icons` template tags. Demonstrates default SVG rendering, specific renderer usage (Font Awesome, Sprites), and attribute customization. ```django {% load easy_icons %} {% icon "home" %} {% icon "home" width="32" height="32" class="large" %} {% icon "heart" renderer="fontawesome" %} {% icon "star" renderer="fontawesome" class="gold" %} {% icon "logo" renderer="sprites" width="24" height="24" %} ``` -------------------------------- ### Django Easy Icons Configuration (`settings.py`) Source: https://github.com/samueljennings/django-easy-icons/blob/main/example/README.md Configuration for Django Easy Icons, defining multiple renderers (SVG, Font Awesome, Sprites) with their respective settings, default attributes, and icon mappings. ```python EASY_ICONS = { # Default SVG renderer "default": { "renderer": "easy_icons.renderers.SvgRenderer", "config": { "svg_dir": "icons", "default_attrs": {"height": "1em", "fill": "currentColor"}, }, "icons": { "home": "home.svg", "alt_dir": "../alt_dir/alt_dir.svg", }, }, # Font Awesome provider renderer "fontawesome": { "renderer": "easy_icons.renderers.ProviderRenderer", "config": { "tag": "i", "default_attrs": {"class": "fas"}, }, "icons": { "heart": "fa-heart", "star": "fa-star", "admin": "fa-toolbox", }, }, # SVG sprite renderer (example) "sprites": { "renderer": "easy_icons.renderers.SpritesRenderer", "config": { "sprite_path": "sprites/icons.svg", "default_attrs": {"class": "icon"}, }, "icons": { "logo": "company-logo", "menu": "hamburger-menu", }, }, } ``` -------------------------------- ### Django Search Form with Icon Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This example illustrates a search form implementation using Bootstrap's flex utilities and input groups. It features an icon next to the search input field and a 'Search' button with an icon, utilizing the 'search' icon from the library. ```django {% load easy_icons %} ``` -------------------------------- ### Configure Multiple Icon Renderers in Django Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Example of configuring multiple icon renderers ('default', 'fontawesome', 'sprites') within the `EASY_ICONS` setting in Django. This allows for flexible icon management across different sources. ```python EASY_ICONS = { "default": { "renderer": "easy_icons.renderers.SvgRenderer", "config": {"svg_dir": "icons"}, "icons": {"home": "home.svg"} }, "fontawesome": { "renderer": "easy_icons.renderers.ProviderRenderer", "config": {"tag": "i"}, "icons": {"heart": "fas fa-heart"} }, "sprites": { "renderer": "easy_icons.renderers.SpritesRenderer", "config": {"sprite_url": "/static/icons.svg"}, "icons": {"logo": "brand"} } } ``` -------------------------------- ### Testing Renderer Cache with Pytest Source: https://context7.com/samueljennings/django-easy-icons/llms.txt An example using `pytest` to test the renderer caching mechanism. It demonstrates how to use `override_settings` to provide a temporary configuration and a fixture to ensure the cache is cleared before each test, guaranteeing isolated test environments. ```python import pytest from django.test import override_settings from easy_icons.utils import clear_cache, icon @pytest.fixture(autouse=True) def clear_icon_cache(): """Clear renderer cache after each test.""" yield clear_cache() @override_settings(EASY_ICONS={ "default": { "renderer": "easy_icons.renderers.SvgRenderer", "config": {"svg_dir": "test_icons"}, "icons": {"test": "test.svg"} } }) def test_custom_config(): # Cache is empty, renderer will be created with test config result = icon("test") assert "test.svg" in result ``` -------------------------------- ### Render Icons with Template Tags in Django Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Demonstrates basic and advanced usage of the `icon` template tag to render icons with customizable attributes like CSS classes, height, and title. It also shows how to specify different icon renderers. ```django {% load easy_icons %} {% icon 'home' %} {% icon 'home' class='nav-icon' %} {% icon 'home' class='nav-icon' height='2em' title='Go Home' %} {% icon 'heart' renderer='fontawesome' class='text-red' %} ``` -------------------------------- ### Configure Default Icon Renderers in Django Settings Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Example of configuring the default icon set using SvgRenderer, specifying the SVG directory and default attributes for icons. This setup enables basic SVG icon usage. ```python EASY_ICONS = { "default": { "renderer": "easy_icons.renderers.SvgRenderer", "config": { "svg_dir": "icons", # Template directory for SVG files "default_attrs": { "height": "1em", "fill": "currentColor" } }, "icons": { "home": "home.svg", "user": "user.svg", "settings": "cog.svg" } } } ``` -------------------------------- ### Configure Provider Renderer for Font Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Configuration example for the `ProviderRenderer` in Django settings, suitable for font icon libraries like Font Awesome. It defines the HTML tag to use and maps icon names to font class names. ```python EASY_ICONS = { "fontawesome": { "renderer": "easy_icons.renderers.ProviderRenderer", "config": { "tag": "i" }, "icons": { "home": "fas fa-home", "user": "fas fa-user", "heart": "fas fa-heart" } } } ``` -------------------------------- ### Profile Page with Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Renders a user profile page using django-easy-icons to display various icons for user information, actions, and activity logs. It leverages conditional logic for avatar display and icon selection based on activity type. ```django {% load easy_icons %}
{% if user.avatar %} {% else %}
{% icon 'user' height='3em' class='text-muted' %}
{% endif %}

{{ user.get_full_name }}

{{ user.email }}

{% icon 'chart-bar' class='me-2' %} Quick Stats
{% icon 'calendar' class='text-primary mb-2' %}
{{ user.date_joined|timesince }}
Member Since
{% icon 'activity' class='text-success mb-2' %}
{{ user.last_login|timesince }}
Last Active
{% icon 'clock' class='me-2' %} Recent Activity
{% for activity in recent_activities %}
{% if activity.type == 'login' %} {% icon 'login' class='text-success' %} {% elif activity.type == 'edit' %} {% icon 'edit' class='text-warning' %} {% elif activity.type == 'create' %} {% icon 'plus' class='text-primary' %} {% endif %}
{{ activity.description }}
{{ activity.timestamp|timesince }} ago
{% empty %}
{% icon 'inbox' class='me-2' %} No recent activity
{% endfor %}
``` -------------------------------- ### Configure SVG Renderer in Django Settings Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Configuration example for the `SvgRenderer` in Django settings. It specifies the directory for SVG files and default attributes to be applied to rendered SVG icons. ```python EASY_ICONS = { "svg": { "renderer": "easy_icons.renderers.SvgRenderer", "config": { "svg_dir": "icons", "default_attrs": {"class": "svg-icon"} }, "icons": { "home": "house.svg", "user": "person.svg" } } } ``` -------------------------------- ### Render Font Awesome Icons with Django Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/example/templates/base.html Demonstrates rendering Font Awesome icons using the `ProviderRenderer`. This requires specifying the renderer in the template tag and uses Font Awesome's CSS classes for icon representation. Examples include basic rendering and applying custom classes. ```django {% load easy_icons %} {% icon "heart" renderer="fontawesome" %} {% icon "star" renderer="fontawesome" class="text-warning" %} {% icon "user" renderer="fontawesome" class="fs-1 text-primary" %} {% icon "admin" renderer="fontawesome" %} ``` -------------------------------- ### Confirmation Modal with Icons (Django) Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Implements a Bootstrap confirmation modal using django-easy-icons for the title icon and action buttons. Requires the 'easy_icons' template tag to be loaded and uses standard Bootstrap modal markup. ```django {% load easy_icons %} ``` -------------------------------- ### Configure Sprites Renderer for SVG Sprite Sheets Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Configuration example for the `SpritesRenderer` in Django settings, used for rendering icons from SVG sprite sheets. It requires the URL to the sprite sheet and maps icon names to sprite IDs. ```python EASY_ICONS = { "sprites": { "renderer": "easy_icons.renderers.SpritesRenderer", "config": { "sprite_url": "/static/icons.svg" }, "icons": { "logo": "brand-logo", "menu": "hamburger-menu" } } } ``` -------------------------------- ### Create Breadcrumb Navigation with Icons in Django Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Demonstrates how to implement breadcrumb navigation in Django templates using the `icon` template tag. This enhances user experience by providing clear visual cues for navigation hierarchy. ```django {% load easy_icons %} ``` -------------------------------- ### Create Custom Renderer by Extending BaseRenderer Source: https://context7.com/samueljennings/django-easy-icons/llms.txt Provides a Python example of creating a custom icon renderer by inheriting from `easy_icons.base.BaseRenderer`. This custom renderer, `CustomRenderer`, generates web component-like HTML tags and can be configured with custom attributes like 'prefix'. ```python # myapp/renderers.py from easy_icons.base import BaseRenderer from django.utils.safestring import SafeString from typing import Any class CustomRenderer(BaseRenderer): """Custom renderer for web component icons.""" def __init__(self, *, prefix: str = "icon", **kwargs: Any): super().__init__(**kwargs) self.prefix = prefix def render(self, name: str, **kwargs: Any) -> SafeString: # Resolve icon name through mappings resolved_name = self.get_icon(name) # Build HTML attributes from config and kwargs attrs = self.build_attrs(**kwargs) # Generate custom HTML structure html = f'<{self.prefix}-icon name="{resolved_name}" {attrs}>' # Return as safe HTML return self.safe_return(html) ``` -------------------------------- ### Configure Renderers - EASY_ICONS Setting Source: https://context7.com/samueljennings/django-easy-icons/llms.txt Provides an example of how to configure the `EASY_ICONS` setting in Django's `settings.py`. This configuration allows for defining multiple icon renderers, specifying their default attributes, and mapping icon names to specific file paths or classes. The setting is a dictionary where keys are renderer names and values are dictionaries of their configurations. ```python # settings.py EASY_ICONS = { "icon_renderers": { "default": { "class": "easy_icons.renderers.SvgFragmentRenderer", "base_dir": "static/svgs", # Directory for SVG files "default_attrs": { "fill": "currentColor", "height": "1em", "width": "1em" } }, "fontawesome": { "class": "easy_icons.renderers.FontAwesomeRenderer", "prefix": "fas fa-" # Font Awesome icon prefix }, "custom_svg": { "class": "easy_icons.renderers.SvgFragmentRenderer", "base_dir": "path/to/your/custom/svgs", "default_attrs": { "width": "24px", "height": "24px" }, "icon_mapping": { "my_custom_icon": "custom_icon_file.svg" } } } } ``` -------------------------------- ### Django Form Action Buttons with Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This snippet demonstrates creating styled action buttons for forms (Save, Cancel, Preview, Delete) using the {% icon %} tag. It includes examples for primary, secondary, outline, and danger button styles, incorporating icons like 'save', 'cancel', 'preview', and 'delete'. ```django {% load easy_icons %}
``` -------------------------------- ### Statistics Dashboard with Icons (Django) Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Displays key statistics using cards, each featuring an icon from django-easy-icons. This snippet requires the 'easy_icons' template tag to be loaded and assumes context variables like 'total_users', 'total_revenue', etc., are available. ```django {% load easy_icons %}
Total Users
{{ total_users }}
{% icon 'users' height='3em' class='text-white-50' %}
Revenue
$ {{ total_revenue }}
{% icon 'currency-dollar' height='3em' class='text-white-50' %}
Orders
{{ total_orders }}
{% icon 'shopping-cart' height='3em' class='text-white-50' %}
Products
{{ total_products }}
{% icon 'box' height='3em' class='text-white-50' %}
``` -------------------------------- ### Get and Clear Renderer Cache Source: https://context7.com/samueljennings/django-easy-icons/llms.txt Explains how to use `get_renderer` to retrieve configured renderer instances, which are cached for performance. `clear_cache` is provided to invalidate the cache, useful for testing or when settings change dynamically. ```python from easy_icons.utils import get_renderer, clear_cache from django.core.exceptions import ImproperlyConfigured # Get a configured renderer instance (cached after first call) try: svg_renderer = get_renderer("default") # Renderer is cached and reused on subsequent calls fa_renderer = get_renderer("fontawesome") # Call renderer directly (instances are callable) home_icon = svg_renderer("home", **{"class": "large"}) heart_icon = fa_renderer("heart") except ImproperlyConfigured as e: # Raised when renderer is not configured or cannot be imported print(f"Configuration error: {e}") # Clear cache (useful in tests or when settings change) clear_cache() ``` -------------------------------- ### Create SVG Sprite File Source: https://context7.com/samueljennings/django-easy-icons/llms.txt An example of an SVG sprite file containing icon symbols. Each symbol is defined with a unique ID (e.g., 'brand-logo') and a path element defining its shape. This file should be placed at the location specified in the sprite_url setting. ```html ``` -------------------------------- ### Render SVG Icons with Django Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/example/templates/base.html Example of rendering SVG icons using the default SVG renderer. This shows how to display a basic icon and an icon with custom attributes like width, height, and CSS classes directly within Django templates. ```django {% load easy_icons %} {% icon "home" %} {% icon "home" width="32" height="32" class="text-primary" %} ``` -------------------------------- ### Django: Dashboard View with Status Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This Django view retrieves user data and creates a list of dictionaries, including user information, status icons, and action buttons. It utilizes the `get_status_icon` function to render status icons. The view prepares data for the template, including icons for actions such as viewing and editing user details. ```python from django.shortcuts import render from django.urls import reverse from easy_icons import icon def dashboard_view(request): users = User.objects.all() user_data = [] for user in users: user_data.append({ 'user': user, 'status_icon': get_status_icon(user.status), 'actions': [ { 'icon': icon('eye', class_='text-info'), 'url': reverse('user_detail', args=[user.id]), 'title': 'View' }, { 'icon': icon('edit', class_='text-warning'), 'url': reverse('user_edit', args=[user.id]), 'title': 'Edit' } ] }) return render(request, 'dashboard.html', {'user_data': user_data}) ``` -------------------------------- ### Alert Messages with Icons (Django) Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Dynamically renders alert messages based on Django's messages framework, using django-easy-icons to display appropriate icons for different message tags (success, error, warning, info). The 'easy_icons' template tag must be loaded. ```django {% load easy_icons %} {% if messages %}
{% for message in messages %} {% endfor %}
{% endif %} ``` -------------------------------- ### Configure Sprite Renderer in settings.py Source: https://context7.com/samueljennings/django-easy-icons/llms.txt Configures the SpritesRenderer for Django Easy Icons in settings.py. It specifies the path to the sprite file and defines mappings between icon names and their corresponding IDs within the sprite. This setup is essential for rendering icons using SVG sprites. ```python EASY_ICONS = { "sprites": { "renderer": "easy_icons.renderers.SpritesRenderer", "config": { "sprite_url": "/static/icons.svg", # Required - path to sprite file "default_attrs": { "class": "icon", "height": "1em", "width": "1em", "fill": "currentColor" } }, "icons": { "logo": "brand-logo", "menu": "hamburger", "close": "x", "search": "magnify" } } } ``` -------------------------------- ### ProviderRenderer - Font Icon Libraries Configuration and Usage Source: https://context7.com/samueljennings/django-easy-icons/llms.txt Configures the ProviderRenderer for integrating font icon libraries like Font Awesome and Material Icons. It defines the HTML tag to use and default attributes, mapping icon names to their respective class names. Includes template usage examples and Python integration. ```python # settings.py EASY_ICONS = { "fontawesome": { "renderer": "easy_icons.renderers.ProviderRenderer", "config": { "tag": "i", # Use or "default_attrs": { "aria-hidden": "true" } }, "icons": { "home": "fas fa-home", "user": "fas fa-user", "heart": "fas fa-heart", "star": "fas fa-star", "check": "fas fa-check-circle" } }, "bootstrap": { "renderer": "easy_icons.renderers.ProviderRenderer", "config": { "tag": "i", }, "icons": { "house": "bi bi-house", "person": "bi bi-person", "cart": "bi bi-cart" } } } # In template: {% load easy_icons %} {% icon "heart" renderer="fontawesome" class="text-danger fs-4" %} {% icon "cart" renderer="bootstrap" class="ms-2" %} # Output: # # # Python usage: from easy_icons import icon fa_heart = icon("heart", renderer="fontawesome", **{"class": "text-danger"}) # ``` -------------------------------- ### Output Example for SpritesRenderer (HTML) Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/renderers.md Demonstrates the HTML output generated by the SpritesRenderer. Each icon is rendered as an SVG element with a nested `` tag pointing to the corresponding symbol in the SVG sprite file. Custom attributes are also applied to the SVG element. ```html ``` -------------------------------- ### Generate Icons Programmatically with Python Function in Django Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md Shows how to use the `icon` function from `easy_icons` within Django views and forms to dynamically generate icon HTML. This is useful for embedding icons in dynamic content or form help text. ```python from easy_icons import icon # In views def dashboard_view(request): home_icon = icon('home', class_='page-icon') return render(request, 'dashboard.html', {'home_icon': home_icon}) # In forms class ContactForm(forms.Form): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['email'].help_text = f"{icon('info')} Enter your email address" ``` -------------------------------- ### Django Card Layout with Product Information and Icons using Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This Django template snippet displays a grid of product cards, each featuring product details and interactive elements. It utilizes the `{% load easy_icons %}` tag and `{% icon %}` template tag to embed icons for image placeholders, 'Add to Cart' button, viewing product details, and star ratings. The snippet includes conditional rendering for product images and a dynamic display of star ratings based on review counts. ```django {% load easy_icons %}
{% for product in products %}
{% if product.image %} {{ product.name }} {% else %}
{% icon 'image' class='text-muted' height='3em' %}
{% endif %}
{{ product.name }}

{{ product.description|truncatewords:20 }}

${{ product.price }}
{% icon 'eye' %}
{% icon 'star-fill' class='text-warning' %} {% icon 'star-fill' class='text-warning' %} {% icon 'star-fill' class='text-warning' %} {% icon 'star-fill' class='text-warning' %} {% icon 'star' class='text-muted' %} ({{ product.reviews.count }} reviews)
{% endfor %}
``` -------------------------------- ### SvgRenderer - Template-based SVG Icons Configuration and Usage Source: https://context7.com/samueljennings/django-easy-icons/llms.txt Demonstrates the configuration for rendering SVG icons from Django template files using SvgRenderer. It includes settings for the SVG directory and default attributes, along with an example of how to use the icon tag in templates and the resulting HTML output. ```python # settings.py EASY_ICONS = { "svg": { "renderer": "easy_icons.renderers.SvgRenderer", "config": { "svg_dir": "icons", # Template directory name "default_attrs": { "class": "svg-icon", "height": "1em", "fill": "currentColor" } }, "icons": { "home": "house.svg", "user": "person.svg", "search": "magnifying-glass.svg" } } } # Create template at: templates/icons/house.svg """ """ # In template: {% load easy_icons %} {% icon "home" renderer="svg" class="large-icon" height="2em" %} # Output: # # # # Note: Attributes are injected into the tag, overriding defaults # The original fill="currentColor" is replaced by any provided fill attribute ``` -------------------------------- ### Django File Upload Interface with Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This snippet demonstrates a file upload interface within a Django template. It uses the `easy_icons` template tags to render icons, enhancing the UI for file uploading and listing. The interface includes basic JavaScript for handling file selection and displaying uploaded files dynamically. Dependencies include the `django-easy-icons` library and Bootstrap for styling. ```django {% load easy_icons %}
{% icon 'cloud-upload' height='4em' class='text-muted' %}

Upload Files

Drag and drop files here or click to browse

``` -------------------------------- ### Django: Custom Template Tags with Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This Python code defines custom template tags using Django's template library to render status badges and action buttons with icons from the `easy_icons` library. It includes two tags: `status_badge` to display status with corresponding icons and colors, and `action_button` to generate action buttons with appropriate icons and URLs. These tags enhance the reusability and maintainability of the templates. ```python from django import template from easy_icons import icon register = template.Library() @register.simple_tag def status_badge(status): """Render a status badge with appropriate icon and color.""" status_config = { 'active': {'icon': 'check-circle', 'class': 'badge bg-success', 'text': 'Active'}, 'inactive': {'icon': 'x-circle', 'class': 'badge bg-danger', 'text': 'Inactive'}, 'pending': {'icon': 'clock', 'class': 'badge bg-warning', 'text': 'Pending'}, } config = status_config.get(status, {'icon': 'question', 'class': 'badge bg-secondary', 'text': 'Unknown'}) icon_html = icon(config['icon'], class_='me-1') return f'{icon_html}{config["text"]}' @register.simple_tag def action_button(action_type, url, **kwargs): """Render an action button with appropriate icon.""" actions = { 'view': {'icon': 'eye', 'class': 'btn-outline-info', 'title': 'View'}, 'edit': {'icon': 'edit', 'class': 'btn-outline-warning', 'title': 'Edit'}, 'delete': {'icon': 'trash', 'class': 'btn-outline-danger', 'title': 'Delete'}, } action = actions.get(action_type, {'icon': 'question', 'class': 'btn-outline-secondary', 'title': 'Action'}) # Merge any additional kwargs action.update(kwargs) icon_html = icon(action['icon']) return f'{icon_html}' ``` -------------------------------- ### Django: Template Usage of Custom Tags Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This code demonstrates the usage of custom template tags within a Django template. It loads the custom tags and utilizes `status_badge` and `action_button` to render status badges and action buttons with appropriate icons. The code showcases how to integrate and use the custom template tags in a practical scenario, like displaying user status and actions. ```django html {% load custom_tags %} {% status_badge user.status %} {% action_button 'view' user.get_absolute_url %} {% action_button 'edit' user.get_edit_url %} {% action_button 'delete' user.get_delete_url %} ``` -------------------------------- ### Running Pytest Commands for Django Easy Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/tests/README.md This section provides common pytest commands to execute the test suite. It includes options for running all tests, verbose output, coverage reporting, and targeting specific test files, classes, or methods. ```bash # Run all tests pytest # Run with verbose output pytest -v # Run tests with coverage pytest --cov=easy_icons # Run specific test file pytest tests/test_config.py # Run specific test class pytest tests/test_config.py::TestEasyIconsConfig # Run specific test method pytest tests/test_config.py::TestEasyIconsConfig::test_get_config_caching ``` -------------------------------- ### Django Form with Icon Labels Source: https://github.com/samueljennings/django-easy-icons/blob/main/docs/usage-examples.md This example shows how to use the {% icon %} template tag to display icons next to form labels for fields like email, password, and a checkbox. It utilizes the 'email', 'lock', and 'check' icons with custom classes for styling. ```django {% load easy_icons %}
{% csrf_token %}
``` -------------------------------- ### Configure Default Attributes for Icons Source: https://github.com/samueljennings/django-easy-icons/blob/main/README.md Example of setting default attributes within the `config` section of an icon renderer configuration in Django settings. These attributes are applied to all icons rendered by that specific configuration. ```python "config": { "default_attrs": { "class": "icon", "aria-hidden": "true", "height": "1em" } } ``` -------------------------------- ### Run Verification Script (Bash) Source: https://github.com/samueljennings/django-easy-icons/blob/main/tests/README.md Executes the `verify_tests.py` script to perform a basic health check and test the core functionality of the `django-easy-icons` library. This script verifies imports, renderer functionality, and Django integration without requiring external dependencies. ```bash python verify_tests.py ```