mirror of
https://git.cmoser.eu/tinytools/django-tinywiki.git
synced 2026-02-04 06:06:33 +01:00
2025.09.14-18:02:28
This commit is contained in:
42
tinywiki/enums.py
Normal file
42
tinywiki/enums.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from enum import StrEnum
|
||||
from django.utils.translation import gettext,gettext_lazy,gettext_noop as _
|
||||
|
||||
class WikiContentType(StrEnum):
|
||||
MARKDOWN = "markdown"
|
||||
BBCODE = "bbcode"
|
||||
|
||||
@property
|
||||
def str_raw(self)->str:
|
||||
mapping = {
|
||||
WikiContentType.MARKDOWN: _("Markdown"),
|
||||
WikiContentType.BBCODE: _("BBCode")
|
||||
}
|
||||
return mapping[self]
|
||||
|
||||
@staticmethod
|
||||
def from_string(string:str)->"WikiContentType":
|
||||
mapping = {
|
||||
WikiContentType.MARKDOWN.value: WikiContentType.MARKDOWN,
|
||||
WikiContentType.BBCODE.value: WikiContentType.BBCODE,
|
||||
}
|
||||
return mapping[string.lower()]
|
||||
|
||||
@property
|
||||
def str_lazy(self)->str:
|
||||
return gettext_lazy(self.str_raw)
|
||||
|
||||
@property
|
||||
def str(self)->str:
|
||||
return gettext(self.str_raw)
|
||||
|
||||
def __str__(self):
|
||||
return self.str
|
||||
|
||||
def __repr__(self):
|
||||
return f"<{self.__qualname__}: {self.value.upper()}>"
|
||||
|
||||
|
||||
WIKI_CONTENT_TYPES = (
|
||||
WikiContentType.MARKDOWN,
|
||||
WikiContentType.BBCODE,
|
||||
)
|
||||
Reference in New Issue
Block a user