* reuse current logic for edit html * fixed save_message for comment form * ref * changed views with current logic * create some filters and tags for jinja * pass comment to battle forms * save message in battle
This commit is contained in:
parent
58b3da5755
commit
fbfa32a97d
|
@ -6,6 +6,8 @@ from django.utils.safestring import mark_safe
|
|||
from club import settings
|
||||
from common.markdown.markdown import markdown_text
|
||||
|
||||
from comments.forms import BattleCommentForm
|
||||
|
||||
register = template.Library()
|
||||
|
||||
TreeComment = namedtuple("TreeComment", ["comment", "replies"])
|
||||
|
@ -68,3 +70,16 @@ def render_comment(context, comment):
|
|||
comment.save()
|
||||
|
||||
return mark_safe(comment.html or "")
|
||||
|
||||
|
||||
@register.filter
|
||||
def edit_form(form):
|
||||
return "comments/forms/battle.html" if isinstance(form, BattleCommentForm) else "comments/forms/comment.html"
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def selected_battle_side(context):
|
||||
try:
|
||||
return "selected" if context['comment'].battle_side == context['side']['name'] else ""
|
||||
except Exception:
|
||||
return ""
|
||||
|
|
|
@ -132,6 +132,8 @@ def edit_comment(request, comment_id):
|
|||
|
||||
if request.method == "POST":
|
||||
form = CommentForm(request.POST, instance=comment)
|
||||
if post.type == Post.TYPE_BATTLE:
|
||||
form = BattleCommentForm(request.POST, instance=comment)
|
||||
if form.is_valid():
|
||||
comment = form.save(commit=False)
|
||||
comment.is_deleted = False
|
||||
|
@ -145,6 +147,8 @@ def edit_comment(request, comment_id):
|
|||
return redirect("show_comment", post.slug, comment.id)
|
||||
else:
|
||||
form = CommentForm(instance=comment)
|
||||
if post.type == Post.TYPE_BATTLE:
|
||||
form = BattleCommentForm(instance=comment)
|
||||
|
||||
return render(request, "comments/edit.html", {
|
||||
"comment": comment,
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
{% extends "layout.html" %}
|
||||
{% load text_filters %}
|
||||
{% load comments %}
|
||||
|
||||
{% block content %}
|
||||
<div class="content comment">
|
||||
<form action="{% url "edit_comment" comment.id %}" method="post" class="form comment-form-form">
|
||||
<div class="comment-form">
|
||||
<div class="comment-form-avatar">
|
||||
<div class="avatar"><img src="{% if form.instance.author.avatar %}{{ form.instance.author.get_avatar }}{% else %}{{ me.get_avatar }}{% endif %}" alt="Аватар" /></div>
|
||||
</div>
|
||||
<div class="comment-form-body">
|
||||
<comment-markdown-editor post-slug="{{ post.slug }}">
|
||||
{{ form.text }}
|
||||
</comment-markdown-editor>
|
||||
{% if form.text.errors %}<span class="form-errors">{{ form.full_name.errors }}</span>{% endif %}
|
||||
</div>
|
||||
<div class="comment-form-footer">
|
||||
<button type="submit" class="button">Сохранить</button>
|
||||
{% include form|edit_form with post=post form=form comment=comment save_message="Сохранить" %}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
{% load comments %}
|
||||
|
||||
<form action="{% url "create_comment" post.slug %}" method="post" class="form comment-form-form">
|
||||
<input type="hidden" name="post_comment_order" value="{{ comment_order }}">
|
||||
<div class="comment-form">
|
||||
|
@ -8,7 +10,7 @@
|
|||
<div class="comment-form-body-battle-side">Я за
|
||||
<select name="{{ form.battle_side.name }}" id="{{ form.battle_side.id_for_label }}">
|
||||
{% for code, side in post.metadata.battle.sides.items %}
|
||||
<option value="{{ code }}">{{ side.name }}</option>
|
||||
<option value="{{ code }}" {% selected_battle_side %}>{{ side.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -22,7 +24,7 @@
|
|||
<div class="comment-form-subscribe">
|
||||
{{ form.subscribe_to_post }} {{ form.subscribe_to_post.label_tag }}
|
||||
</div>
|
||||
<button type="submit" class="button comment-form-button">Отправить</button>
|
||||
<button type="submit" class="button comment-form-button"> {{save_message}} </button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<div class="comment-form-subscribe">
|
||||
{{ form.subscribe_to_post }} {{ form.subscribe_to_post.label_tag }}
|
||||
</div>
|
||||
<button type="submit" class="button comment-form-button">Отправить</button>
|
||||
<button type="submit" class="button comment-form-button">{{ save_message }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -114,7 +114,7 @@
|
|||
|
||||
{% if me and me.is_active_membership and post.is_commentable and post.is_visible or me.is_moderator %}
|
||||
<div class="post-comments-form">
|
||||
{% include "comments/forms/battle.html" with post=post form=comment_form %}
|
||||
{% include "comments/forms/battle.html" with post=post form=comment_form save_message="Отправить" %}
|
||||
</div>
|
||||
|
||||
<div class="post-comments-rules">
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
|
||||
{% if me and me.is_active_membership and post.is_commentable and post.is_visible or me.is_moderator %}
|
||||
<div class="post-comments-form" id="post-comments-form">
|
||||
{% include "comments/forms/comment.html" with post=post form=comment_form %}
|
||||
{% include "comments/forms/comment.html" with post=post form=comment_form save_message="Отправить"%}
|
||||
</div>
|
||||
|
||||
<div class="post-comments-rules">
|
||||
|
|
Loading…
Reference in New Issue