Skip to content

Instantly share code, notes, and snippets.

@bmispelon
Last active May 8, 2018
Embed
What would you like to do?
Regionalify: Supercharge your Django Admin with the power of regional character indicators
# github gists don't like empty files

Regionalify

Make your Django admin prettier with regional indicator characters!

Installation

Put the regionalify directory somewhere on your Python PATH (in your project root for example, next to manage.py).

Add this line to your settings.INSTALLED_APPS:

INSTALLED_APPS = (
    ...,
    'regionalify.apps.RegionalifyMonkeyConfig',
    ...
)

Now visit your admin page and be amazed.

from django.apps import AppConfig, apps
from .utils import cool_name
class RegionalifyMonkeyConfig(AppConfig):
name = 'regionalify'
def ready(self):
"""
Monkeypatch the verbose_name of all installed apps to be much cooler.
"""
for config in apps.get_app_configs():
new_name = "✨{}✨".format(cool_name(config.verbose_name))
config.verbose_name = new_name
import unicodedata
def regional_indicator(letter):
"""
Return the regional indicator character corresponding to the given letter.
If none exist, return the letter itself instead.
"""
name = 'REGIONAL INDICATOR SYMBOL LETTER {}'.format(letter.upper())
try:
return unicodedata.lookup(name)
except LookupError:
return letter
def cool_name(s):
"""
Turn all the letter inside the given string into regional indicator
characters.
"""
return "\N{ZERO WIDTH SPACE}".join(map(regional_indicator, s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment