Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions baseframe/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def initials(text: str) -> str:
return ''


@baseframe.app_template_filter('avatar_type')
def avatar_type(text: str, types: int = 6) -> str:
"""Return an int from 1 to types based on initials from the given string"""
initial = initials(text)
parts = initial.split()
stringTotal = ord(parts[0][0])
if len(parts) > 1:
stringTotal += ord(parts[0][1])
return stringTotal % types or types


@baseframe.app_template_filter('usessl')
def usessl(url: str) -> str:
"""Convert a URL to https:// if SSL is enabled in site config."""
Expand Down