change review date; edit review won't share to mastodon by default
This commit is contained in:
parent
9e21854dce
commit
842cc4969d
4 changed files with 36 additions and 6 deletions
|
@ -20,7 +20,7 @@ class ReviewForm(forms.ModelForm):
|
|||
title = forms.CharField(label=_("评论标题"))
|
||||
body = MarkdownxFormField(label=_("评论正文 (Markdown)"))
|
||||
share_to_mastodon = forms.BooleanField(
|
||||
label=_("分享到联邦网络"), initial=True, required=False
|
||||
label=_("分享到联邦网络"), initial=False, required=False
|
||||
)
|
||||
id = forms.IntegerField(required=False, widget=forms.HiddenInput())
|
||||
visibility = forms.TypedChoiceField(
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
|
||||
{% endif %}
|
||||
|
||||
<span class="review-head__time">{{ review.edited_time }}</span>
|
||||
<span class="review-head__time">{{ review.created_time|date }}</span>
|
||||
|
||||
</div>
|
||||
<div class="review-head__actions">
|
||||
|
|
|
@ -54,9 +54,22 @@
|
|||
{{ form.share_to_mastodon }}{{ form.share_to_mastodon.label }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix">
|
||||
<input class="button float-right" type="submit" value="{% trans '提交' %}">
|
||||
<div class="clearfix"></div>
|
||||
<input class="button float-right" type="submit" value="{% trans '提交' %}">
|
||||
<div>
|
||||
<label for="mark_anotherday">更改标记日期:
|
||||
<input type="checkbox" name="mark_anotherday" value="1" id="mark_anotherday">
|
||||
<input type="date" name="mark_date" id="mark_date" min="1900-01-01" max="{{date_today}}" value="{{date_today}}" style="display: none;"></label>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$("#mark_anotherday").on('click', ()=>{
|
||||
if ($("#mark_anotherday:checked").val() == '1') {
|
||||
$("#mark_date").show()
|
||||
} else {
|
||||
$("#mark_date").hide()
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{{ form.media }}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -405,9 +405,17 @@ def review_edit(request, item_uuid, review_uuid=None):
|
|||
form = (
|
||||
ReviewForm(instance=review)
|
||||
if review
|
||||
else ReviewForm(initial={"item": item.id})
|
||||
else ReviewForm(initial={"item": item.id, "share_to_mastodon": True})
|
||||
)
|
||||
return render(
|
||||
request,
|
||||
"review_edit.html",
|
||||
{
|
||||
"form": form,
|
||||
"item": item,
|
||||
"date_today": timezone.localdate().isoformat(),
|
||||
},
|
||||
)
|
||||
return render(request, "review_edit.html", {"form": form, "item": item})
|
||||
elif request.method == "POST":
|
||||
form = (
|
||||
ReviewForm(request.POST, instance=review)
|
||||
|
@ -418,6 +426,15 @@ def review_edit(request, item_uuid, review_uuid=None):
|
|||
if not review:
|
||||
form.instance.owner = request.user
|
||||
form.instance.edited_time = timezone.now()
|
||||
mark_date = None
|
||||
if request.POST.get("mark_anotherday"):
|
||||
mark_date = timezone.get_current_timezone().localize(
|
||||
parse_datetime(request.POST.get("mark_date") + " 20:00:00")
|
||||
)
|
||||
if mark_date and mark_date >= timezone.now():
|
||||
mark_date = None
|
||||
if mark_date:
|
||||
form.instance.created_time = mark_date
|
||||
form.save()
|
||||
if form.cleaned_data["share_to_mastodon"]:
|
||||
form.instance.save = lambda **args: None
|
||||
|
|
Loading…
Add table
Reference in a new issue