Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix hunch evidence commenting.

  • Loading branch information...
commit 577ca489fdeed763fb227a203667665d512c0afa 1 parent 9231d85
Adam Mckaig adammck authored
10 hunchworks/models.py
View
@@ -536,7 +536,7 @@ class Comment(models.Model):
@models.permalink
def get_absolute_base_url(self):
if self.hunch_evidence:
- return ("hunch_evidence", [self.hunch_evidence.hunch.pk])
+ return ("hunch_evidence", [self.hunch_evidence.hunch.pk, self.hunch_evidence.evidence.pk])
elif self.hunch:
return ("hunch_comments", [self.hunch.pk])
@@ -565,14 +565,8 @@ class Meta:
unique_together = ("hunch", "evidence")
@models.permalink
- def get_absolute_base_url(self):
- return ("hunch_evidence", [self.hunch.pk])
-
def get_absolute_url(self):
- return self.get_absolute_base_url() + "#" + self.anchor()
-
- def anchor(self):
- return "he%d" % self.pk
+ return ("hunch_evidence", [self.hunch.pk, self.evidence.pk])
def save(self, *args, **kwargs):
self.support_cache = self.get_support()
8 hunchworks/templates/comments/comment.html
View
@@ -1,8 +0,0 @@
-<div class="comment{% ifequal request.user.get_profile comment.creator %} mine{% endifequal %}" id="c{{ comment.pk }}">
- {% include "includes/users/short.html" with object=comment.creator %}
-
- <div class="bubble">
- <div class="arrow"></div>
- {{ comment.text }}
- </div>
-</div>
36 hunchworks/templates/hunches/show/comments.html
View
@@ -6,39 +6,5 @@
{% endblock %}
{% block secondary_content %}
- <section class="comments on-hunch">
- <ul>
- {% for comment in comments %}
- <li>
- {% include "comments/comment.html" %}
- </li>
- {% endfor %}
-
- <li>
- <form action="" method="post" class="comment{% if form.errors %} errors{% endif %}">
- {% include "includes/users/short.html" with object=request.user.get_profile %}
-
- <div class="bubble">
- <div class="arrow"></div>
- {{ form.non_field_errors }}
- {% csrf_token %}
-
- {% for field in form.hidden_fields %}
- {{ field }}
- {% endfor %}
-
- {% for field in form.visible_fields %}
- {% include "includes/fields/base.html" %}
- {% endfor %}
-
- <div class="submit-trigger"></div>
-
- <div class="actions">
- <input type="submit" value="&raquo;">
- </div>
- </div>
- </form>
- </li>
- </ul>
- </section>
+ {% include "includes/comments/list_with_form.html" with object_list=comments form=form %}
{% endblock %}
2  hunchworks/templates/hunches/show/evidence.html
View
@@ -33,4 +33,6 @@
{% bookmarks evidence %}
</article>
+
+ {% include "includes/comments/list_with_form.html" with object_list=comments form=form %}
{% endblock %}
10 hunchworks/templates/comments/form.html → hunchworks/templates/includes/comments/form.html
View
@@ -1,16 +1,16 @@
-<form action="" method="post" class="comment{% if comment_form.errors %} errors{% endif %}">
+<form action="" method="post" class="comment{% if form.errors %} errors{% endif %}">
{% include "includes/users/short.html" with object=request.user.get_profile %}
<div class="bubble">
<div class="arrow"></div>
- {{ comment_form.non_field_errors }}
+ {{ form.non_field_errors }}
{% csrf_token %}
- {% for field in comment_form.hidden_fields %}
+ {% for field in form.hidden_fields %}
{{ field }}
{% endfor %}
- {% for field in comment_form.visible_fields %}
+ {% for field in form.visible_fields %}
{% include "includes/fields/base.html" %}
{% endfor %}
@@ -21,4 +21,4 @@
<input type="submit" value="&raquo;">
</div>
</div>
-</form>
+</form>
13 hunchworks/templates/includes/comments/list_with_form.html
View
@@ -0,0 +1,13 @@
+<section class="object-list comments">
+ <ul>
+ {% for object in object_list %}
+ <li>
+ {% include "includes/comments/short.html" %}
+ </li>
+ {% endfor %}
+
+ <li>
+ {% include "includes/comments/form.html" with form=form %}
+ </li>
+ </ul>
+</section>
8 hunchworks/templates/includes/comments/short.html
View
@@ -0,0 +1,8 @@
+<div class="comment{% ifequal request.user.get_profile object.creator %} mine{% endifequal %}" id="c{{ object.pk }}">
+ {% include "includes/users/short.html" with object=object.creator %}
+
+ <div class="bubble">
+ <div class="arrow"></div>
+ {{ object.text }}
+ </div>
+</div>
10 hunchworks/views/hunches.py
View
@@ -149,10 +149,20 @@ def hunch_evidence(req, hunch_id, evidence_id):
evidence = get_object_or_404(models.Evidence, pk=evidence_id)
hunch_evidence = models.HunchEvidence.objects.get(hunch=hunch_id, evidence=evidence_id)
+ form = forms.CommentForm(req.POST or None, initial={
+ "hunch_evidence": hunch_evidence
+ })
+
+ if form.is_valid():
+ comment = form.save(creator=req.user.get_profile())
+ return redirect(comment)
+
return _render(req, "show/evidence", {
"hunch": hunch,
"evidence": evidence,
"hunch_evidence": hunch_evidence,
+ "comments": hunch_evidence.comment_set.all(),
+ "form": form
})
Please sign in to comment.
Something went wrong with that request. Please try again.