Browse Source

Enforce blog posts not allowing commenting on them

pull/2/head
Noah Petherbridge 4 years ago
parent
commit
c665db20b8
3 changed files with 74 additions and 63 deletions
  1. +1
    -0
      rophako/modules/blog/templates/blog/entry.inc.html
  2. +8
    -2
      rophako/modules/comment/__init__.py
  3. +65
    -61
      rophako/modules/comment/templates/comment/form.inc.html

+ 1
- 0
rophako/modules/blog/templates/blog/entry.inc.html View File

@@ -81,6 +81,7 @@
{{ include_page("comment.partial_index",
thread="blog-"+post["post_id"]|string,
subject=post["subject"],
addable=post["comments"],
) | safe }}
{% endif %}


+ 8
- 2
rophako/modules/comment/__init__.py View File

@@ -168,8 +168,13 @@ def unsubscribe():
return template("comment/unsubscribed.html")


def partial_index(thread, subject, header=True):
"""Partial template for including the index view of a comment thread."""
def partial_index(thread, subject, header=True, addable=True):
"""Partial template for including the index view of a comment thread.

* thread: unique name for the comment thread
* subject: subject name for the comment thread
* header: show the Comments h1 header
* addable: boolean, can new comments be added to the thread"""

comments = Comment.get_comments(thread)

@@ -199,6 +204,7 @@ def partial_index(thread, subject, header=True):
g.info["header"] = header
g.info["thread"] = thread
g.info["subject"] = subject
g.info["commenting_disabled"] = not addable
g.info["url"] = request.url
g.info["comments"] = sorted_comments
g.info["photo_url"] = Config.photo.root_public

+ 65
- 61
rophako/modules/comment/templates/comment/form.inc.html View File

@@ -1,66 +1,70 @@
{# Common template for leaving a comment/updating the comment preview. #}

<form name="comment" action="{{ url_for('comment.preview') }}" method="POST">
<input type="hidden" name="token" value="{{ csrf_token() }}">
<input type="hidden" name="thread" value="{{ thread }}">
<input type="hidden" name="url" value="{{ url }}">
<input type="hidden" name="subject" value="{{ subject }}">
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td align="left" valign="middle">
Your name:
</td>
<td align="left" valign="middle">
{% if session["login"] %}
<strong>{{ session["name"] }}</strong>
{% else %}
<input type="text" class="form-control" size="40" name="name" value="{{ name }}">
{% endif %}
</td>
</tr>
<tr>
<td align="left" valign="middle">
Your Email:
</td>
<td align="left" valign="middle">
<input type="text" class="form-control" size="40" name="contact" value="{{ contact }}" placeholder="(optional; used for Gravatar icons and subscribing)">
</td>
</tr>
<tr>
<td align="left" valign="top">
Message:
</td>
<td align="left" valign="top">
<textarea class="form-control" cols="40" rows="8" name="message" style="width: 100%">{{ message }}</textarea>
<div>
<small>Comments can be formatted with <a href="/markdown" target="_blank">Markdown</a>,
and you can use<br><a href="{{ url_for('emoticons.index') }}" target="_blank">emoticons</a>
in your comment.</small>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top">
<label>
<input type="checkbox" name="subscribe" value="true"{% if subscribe == "true" %} checked{% endif %}>
Notify me of future comments on this page via e-mail
(<a href="{{ url_for('comment.privacy') }}" target="_blank">Privacy Policy</a>)
</label>
</td>
</tr>
</table><p>
{% if commenting_disabled %}
No new comments may be added to this thread.
{% else %}
<form name="comment" action="{{ url_for('comment.preview') }}" method="POST">
<input type="hidden" name="token" value="{{ csrf_token() }}">
<input type="hidden" name="thread" value="{{ thread }}">
<input type="hidden" name="url" value="{{ url }}">
<input type="hidden" name="subject" value="{{ subject }}">
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td align="left" valign="middle">
Your name:
</td>
<td align="left" valign="middle">
{% if session["login"] %}
<strong>{{ session["name"] }}</strong>
{% else %}
<input type="text" class="form-control" size="40" name="name" value="{{ name }}">
{% endif %}
</td>
</tr>
<tr>
<td align="left" valign="middle">
Your Email:
</td>
<td align="left" valign="middle">
<input type="text" class="form-control" size="40" name="contact" value="{{ contact }}" placeholder="(optional; used for Gravatar icons and subscribing)">
</td>
</tr>
<tr>
<td align="left" valign="top">
Message:
</td>
<td align="left" valign="top">
<textarea class="form-control" cols="40" rows="8" name="message" style="width: 100%">{{ message }}</textarea>
<div>
<small>Comments can be formatted with <a href="/markdown" target="_blank">Markdown</a>,
and you can use<br><a href="{{ url_for('emoticons.index') }}" target="_blank">emoticons</a>
in your comment.</small>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="left" valign="top">
<label>
<input type="checkbox" name="subscribe" value="true"{% if subscribe == "true" %} checked{% endif %}>
Notify me of future comments on this page via e-mail
(<a href="{{ url_for('comment.privacy') }}" target="_blank">Privacy Policy</a>)
</label>
</td>
</tr>
</table><p>

<div style="display: none">
If you can see this, don't touch the following fields.<br>
<input type="text" class="form-control" name="website" value="http://"><br>
<input type="text" class="form-control" name="email" value="">
</div>
<div style="display: none">
If you can see this, don't touch the following fields.<br>
<input type="text" class="form-control" name="website" value="http://"><br>
<input type="text" class="form-control" name="email" value="">
</div>

{% if preview %}
<button class="btn btn-default" type="submit" name="action" value="preview">Refresh Preview</button>
<button class="btn btn-primary" type="submit" name="action" value="submit">Submit Comment</button>
{% else %}
<button class="btn btn-primary" type="submit" name="action" value="preview">Leave Comment</button>
{% endif %}
{% if preview %}
<button class="btn btn-default" type="submit" name="action" value="preview">Refresh Preview</button>
<button class="btn btn-primary" type="submit" name="action" value="submit">Submit Comment</button>
{% else %}
<button class="btn btn-primary" type="submit" name="action" value="preview">Leave Comment</button>
{% endif %}

</form>
</form>
{% endif %}

Loading…
Cancel
Save