lib.itmens/journal/forms.py

72 lines
2 KiB
Python
Raw Normal View History

2022-12-25 13:45:24 -05:00
from django import forms
from django.utils.translation import gettext_lazy as _
from markdownx.fields import MarkdownxFormField
2022-12-28 01:09:55 -05:00
from common.forms import PreviewImageInput
2022-12-25 13:45:24 -05:00
from .models import *
2022-12-25 13:45:24 -05:00
class ReviewForm(forms.ModelForm):
class Meta:
model = Review
2022-12-29 23:57:02 -05:00
fields = ["id", "item", "title", "body", "visibility"]
2022-12-25 13:45:24 -05:00
widgets = {
2022-12-29 23:57:02 -05:00
"item": forms.TextInput(attrs={"hidden": ""}),
2022-12-25 13:45:24 -05:00
}
2022-12-29 23:57:02 -05:00
2022-12-25 13:45:24 -05:00
title = forms.CharField(label=_("评论标题"))
2023-06-04 11:47:17 -04:00
body = MarkdownxFormField(label=_("评论正文 (Markdown格式可参考下方语法范例)"), strip=False)
2022-12-25 13:45:24 -05:00
share_to_mastodon = forms.BooleanField(
2023-07-04 17:21:17 -04:00
label=_("分享到联邦宇宙"), initial=False, required=False
2022-12-29 23:57:02 -05:00
)
2022-12-25 13:45:24 -05:00
id = forms.IntegerField(required=False, widget=forms.HiddenInput())
visibility = forms.TypedChoiceField(
label=_("可见性"),
initial=0,
coerce=int,
choices=VisibilityType.choices,
2022-12-29 23:57:02 -05:00
widget=forms.RadioSelect,
2022-12-25 13:45:24 -05:00
)
2022-12-28 01:09:55 -05:00
COLLABORATIVE_CHOICES = [
(0, _("仅限创建者")),
(1, _("创建者及其互关用户")),
]
class CollectionForm(forms.ModelForm):
# id = forms.IntegerField(required=False, widget=forms.HiddenInput())
title = forms.CharField(label=_("标题"))
2023-01-31 09:07:33 -05:00
brief = MarkdownxFormField(label=_("介绍 (Markdown)"), strip=False)
2023-07-04 17:21:17 -04:00
# share_to_mastodon = forms.BooleanField(label=_("分享到联邦宇宙"), initial=True, required=False)
2022-12-28 01:09:55 -05:00
visibility = forms.TypedChoiceField(
label=_("可见性"),
initial=0,
coerce=int,
choices=VisibilityType.choices,
2022-12-29 23:57:02 -05:00
widget=forms.RadioSelect,
2022-12-28 01:09:55 -05:00
)
collaborative = forms.TypedChoiceField(
label=_("协作整理权限"),
initial=0,
coerce=int,
choices=COLLABORATIVE_CHOICES,
2022-12-29 23:57:02 -05:00
widget=forms.RadioSelect,
2022-12-28 01:09:55 -05:00
)
class Meta:
model = Collection
fields = [
2022-12-29 23:57:02 -05:00
"title",
"cover",
"visibility",
"collaborative",
"brief",
2022-12-28 01:09:55 -05:00
]
widgets = {
2022-12-29 23:57:02 -05:00
"cover": PreviewImageInput(),
2022-12-28 01:09:55 -05:00
}