diff --git a/blog/admin.py b/blog/admin.py index a328eaf3..9685db91 100644 --- a/blog/admin.py +++ b/blog/admin.py @@ -18,15 +18,19 @@ class PostAdmin(admin.ModelAdmin): readonly_fields = ("preview_html",) fieldsets = ( - (None, { - "fields": ( - "author", "title", - "content", - "preview_html", - "file", - "tags", - ) - }), + ( + None, + { + "fields": ( + "author", + "title", + "content", + "preview_html", + "file", + "tags", + ) + }, + ), ) def preview_html(self, obj): diff --git a/blog/elasticsearch/documents.py b/blog/elasticsearch/documents.py index beb05ddb..9a2c8b70 100644 --- a/blog/elasticsearch/documents.py +++ b/blog/elasticsearch/documents.py @@ -18,8 +18,12 @@ class PostDocument(ActiveOnlyMixin, Document): class Index: name = "posts" - settings = {"number_of_shards": 1, "number_of_replicas": 0, - "analysis": COMMON_ANALYSIS, "index": {"max_ngram_diff": 18}} + settings = { + "number_of_shards": 1, + "number_of_replicas": 0, + "analysis": COMMON_ANALYSIS, + "index": {"max_ngram_diff": 18}, + } class Django: model = Post @@ -28,4 +32,5 @@ class PostDocument(ActiveOnlyMixin, Document): def prepare_title(self, instance): return getattr(instance, "title", "") or "" + registry.register_document(PostDocument) diff --git a/blog/models.py b/blog/models.py index 267ffaf3..2bc80275 100644 --- a/blog/models.py +++ b/blog/models.py @@ -10,51 +10,49 @@ from core.abstract import NiceModel class Post(NiceModel): is_publicly_visible = True - author = ForeignKey( - to="vibes_auth.User", on_delete=CASCADE, blank=False, null=False, related_name="posts" + author = ForeignKey(to="vibes_auth.User", on_delete=CASCADE, blank=False, null=False, related_name="posts") + title = CharField( + unique=True, max_length=128, blank=False, null=False, help_text=_("post title"), verbose_name=_("title") + ) + content = MarkdownField( + "content", + extensions=[ + TocExtension(toc_depth=3), + "pymdownx.arithmatex", + "pymdownx.b64", + "pymdownx.betterem", + "pymdownx.blocks.admonition", + "pymdownx.blocks.caption", + "pymdownx.blocks.definition", + "pymdownx.blocks.details", + "pymdownx.blocks.html", + "pymdownx.blocks.tab", + "pymdownx.caret", + "pymdownx.critic", + "pymdownx.emoji", + "pymdownx.escapeall", + "pymdownx.extra", + "pymdownx.fancylists", + "pymdownx.highlight", + "pymdownx.inlinehilite", + "pymdownx.keys", + "pymdownx.magiclink", + "pymdownx.mark", + "pymdownx.pathconverter", + "pymdownx.progressbar", + "pymdownx.saneheaders", + "pymdownx.smartsymbols", + "pymdownx.snippets", + "pymdownx.striphtml", + "pymdownx.superfences", + "pymdownx.tasklist", + "pymdownx.tilde", + ], + blank=True, + null=True, ) - title = CharField(unique=True, max_length=128, blank=False, null=False, help_text=_("post title"), - verbose_name=_("title")) - content = MarkdownField("content", - extensions=[ - TocExtension(toc_depth=3), - "pymdownx.arithmatex", - "pymdownx.b64", - "pymdownx.betterem", - "pymdownx.blocks.admonition", - "pymdownx.blocks.caption", - "pymdownx.blocks.definition", - "pymdownx.blocks.details", - "pymdownx.blocks.html", - "pymdownx.blocks.tab", - "pymdownx.caret", - "pymdownx.critic", - "pymdownx.emoji", - "pymdownx.escapeall", - "pymdownx.extra", - "pymdownx.fancylists", - "pymdownx.highlight", - "pymdownx.inlinehilite", - "pymdownx.keys", - "pymdownx.magiclink", - "pymdownx.mark", - "pymdownx.pathconverter", - "pymdownx.progressbar", - "pymdownx.saneheaders", - "pymdownx.smartsymbols", - "pymdownx.snippets", - "pymdownx.striphtml", - "pymdownx.superfences", - "pymdownx.tasklist", - "pymdownx.tilde" - ], blank=True, null=True) file = FileField(upload_to="posts/", blank=True, null=True) - slug = AutoSlugField( - populate_from='title', - allow_unicode=True, - unique=True, - editable=False - ) + slug = AutoSlugField(populate_from="title", allow_unicode=True, unique=True, editable=False) tags = ManyToManyField(to="blog.PostTag", blank=True, related_name="posts") def __str__(self): diff --git a/blog/widgets.py b/blog/widgets.py index df5e1abf..bcb63b0e 100644 --- a/blog/widgets.py +++ b/blog/widgets.py @@ -4,18 +4,12 @@ from django.utils.safestring import mark_safe class MarkdownEditorWidget(forms.Textarea): class Media: - css = { - 'all': ( - 'https://cdnjs.cloudflare.com/ajax/libs/easymde/2.14.0/easymde.min.css', - ) - } - js = ( - 'https://cdnjs.cloudflare.com/ajax/libs/easymde/2.14.0/easymde.min.js', - ) + css = {"all": ("https://cdnjs.cloudflare.com/ajax/libs/easymde/2.14.0/easymde.min.css",)} + js = ("https://cdnjs.cloudflare.com/ajax/libs/easymde/2.14.0/easymde.min.js",) def render(self, name, value, attrs=None, renderer=None): textarea_html = super().render(name, value, attrs, renderer) - textarea_id = attrs.get('id', f'id_{name}') + textarea_id = attrs.get("id", f"id_{name}") init_js = f"""