lib.itmens/collection/forms.py

46 lines
1.2 KiB
Python
Raw Normal View History

2021-12-20 21:02:50 -05:00
from django import forms
from django.utils.translation import gettext_lazy as _
from .models import Collection
from common.forms import *
2022-06-10 17:12:30 -04:00
COLLABORATIVE_CHOICES = [
(0, _("仅限创建者")),
(1, _("创建者及其互关用户")),
]
2021-12-20 21:02:50 -05:00
class CollectionForm(forms.ModelForm):
# id = forms.IntegerField(required=False, widget=forms.HiddenInput())
2021-12-24 11:54:12 -08:00
title = forms.CharField(label=_("标题"))
2021-12-26 15:55:16 -05:00
description = MarkdownxFormField(label=_("详细介绍 (Markdown)"))
# share_to_mastodon = forms.BooleanField(label=_("分享到联邦网络"), initial=True, required=False)
2021-12-24 11:54:12 -08:00
visibility = forms.TypedChoiceField(
label=_("可见性"),
initial=0,
coerce=int,
choices=VISIBILITY_CHOICES,
widget=forms.RadioSelect
)
2022-06-10 17:12:30 -04:00
collaborative = forms.TypedChoiceField(
label=_("协作整理权限"),
initial=0,
coerce=int,
choices=COLLABORATIVE_CHOICES,
widget=forms.RadioSelect
)
2021-12-20 21:02:50 -05:00
class Meta:
model = Collection
fields = [
2021-12-24 11:54:12 -08:00
'title',
2021-12-20 21:02:50 -05:00
'description',
'cover',
2021-12-26 15:55:16 -05:00
'visibility',
2022-06-10 17:12:30 -04:00
'collaborative',
2021-12-20 21:02:50 -05:00
]
widgets = {
'cover': PreviewImageInput(),
}