Add comment count and collapse
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11 on 2017-10-11 16:22
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('webapp', '0018_auto_20171011_1856'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='kaehmymessage',
|
||||
name='timestamp',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Timestamp'),
|
||||
),
|
||||
]
|
||||
@@ -11,6 +11,8 @@ from auditlog.registry import auditlog
|
||||
from phonenumber_field.modelfields import PhoneNumberField
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
VERBOSE_NAME = _('Webapp')
|
||||
|
||||
@@ -133,6 +135,7 @@ class KaehmyMessage(MessageParent):
|
||||
email = models.EmailField(_('Email'))
|
||||
message = models.TextField(_('Message'))
|
||||
parent = models.ForeignKey('MessageParent', related_name='messages')
|
||||
timestamp = models.DateTimeField(_('Timestamp'), default=timezone.now)
|
||||
|
||||
|
||||
class KaehmyForm(MessageParent):
|
||||
@@ -159,6 +162,21 @@ class KaehmyForm(MessageParent):
|
||||
def __str__(self):
|
||||
return _('Kaehmy application: {}').format(self.name)
|
||||
|
||||
def comment_count(self):
|
||||
total = 0
|
||||
|
||||
def recurse(message):
|
||||
count = 0
|
||||
for msg in message.messages.all():
|
||||
count += recurse(msg)
|
||||
|
||||
return count + 1
|
||||
|
||||
for message in self.messages.all():
|
||||
total += recurse(message)
|
||||
|
||||
return total
|
||||
|
||||
|
||||
class Role(PresetRole):
|
||||
"""
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
<script src="{% static "js/lib/jquery-3.1.0.min.js" %}"></script>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="{% static "css/lib/bootstrap.min.css" %}">
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||
<script src="{% static "js/lib/underscore-min.js" %}"></script>
|
||||
</head>
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
{% block navigation %}
|
||||
{% include "navigation.html" %}
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
@@ -30,9 +30,14 @@
|
||||
|
||||
<p>{{ application.text }}</p>
|
||||
|
||||
<a type="button" style="cursor: pointer" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
|
||||
{% trans "Show comments" %} ({{ application.comment_count }})
|
||||
</a>
|
||||
<div class="collapse" id="collapseExample">
|
||||
{% for message in application.messages.all %}
|
||||
{% include "kaehmy_message.html" with messages=message.messages.all %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
<div class="card">
|
||||
<div class="card" style="margin-top: 0.5rem">
|
||||
<div class="card-block">
|
||||
<h4>{{ message.name }}</h4>
|
||||
<p>{{ message.message }}</p>
|
||||
|
||||
{% for message in messages %}
|
||||
{% include "kaehmy_message.html" with messages=message.messages.all %}
|
||||
{% endfor %}
|
||||
<h6 class="card-subtitle mb-2 text-muted">{{ message.timestamp }}</h6>
|
||||
|
||||
<div>
|
||||
{% for message in messages %}
|
||||
{% include "kaehmy_message.html" with messages=message.messages.all %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user