Do the same for comment edition
This commit is contained in:
parent
fd65e84b62
commit
61d2d63bf4
14
models.py
14
models.py
|
@ -27,7 +27,8 @@ from re import sub
|
|||
from datetime import datetime
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models.signals import post_init, pre_delete, post_delete, post_save
|
||||
from django.db.models.signals import pre_init, post_init, pre_delete, post_delete
|
||||
from django.db.models.signals import pre_save, post_save
|
||||
from django.dispatch import receiver
|
||||
from dynastie.generators import *
|
||||
|
||||
|
@ -362,6 +363,12 @@ class Comment(models.Model):
|
|||
the_comment = models.TextField(max_length=255)
|
||||
ip = models.GenericIPAddressField()
|
||||
|
||||
def _update_line_returns(self):
|
||||
self.the_comment = self.the_comment.replace('\n', '<br />')
|
||||
|
||||
def _remove_br(self):
|
||||
self.the_comment = self.the_comment.replace('<br />', '\n')
|
||||
|
||||
@receiver(post_init, sender=Blog)
|
||||
def init_blog_signal(sender, **kwargs):
|
||||
kwargs['instance'].create_paths()
|
||||
|
@ -386,3 +393,8 @@ def delete_post_signal(sender, **kwargs):
|
|||
def pre_delete_post_signal(sender, **kwargs):
|
||||
post = kwargs['instance']
|
||||
comments = Comment.objects.filter(post=post.id).delete()
|
||||
|
||||
# Replace line returns by <br /> for generation
|
||||
@receiver(pre_save, sender=Comment)
|
||||
def pre_save_comment_signal(sender, **kwargs):
|
||||
kwargs['instance']._update_line_returns()
|
||||
|
|
|
@ -18,10 +18,12 @@
|
|||
{% for comment in comments %}
|
||||
<div class="comment">
|
||||
<div class="infos">
|
||||
<a href="/comment/edit/{{ comment.id }}">#{{ comment.id }}</a> <span class="author">{{ comment.author }}</span> <span class="mail">{{ comment.email|default:"no mail" }}</span> <span class="date">{{ comment.date|date:"D d M Y H:m" }}<span> <a href="/comment/delete/{{ comment.id }}">delete</a>
|
||||
<a href="/comment/edit/{{ comment.id }}">#{{ comment.id }}</a> <span class="author">{{ comment.author }}</span> <span class="mail">{{ comment.email|default:"no mail" }}</span> <span class="date">{{ comment.date|date:"D d M Y H:m" }}<span> <a href="/comment/delete/{{ comment.id }}" onclick="return confirm('Do you really want to delete this item ?')">delete</a>
|
||||
</div>
|
||||
<div class="content">
|
||||
{% autoescape off %}
|
||||
{{ comment.the_comment }}
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user