Skip to content
This repository
Browse code

Fix hunch evidence commenting.

  • Loading branch information...
commit 577ca489fdeed763fb227a203667665d512c0afa 1 parent 9231d85
Adam Mckaig adammck authored
10 hunchworks/models.py
@@ -536,7 +536,7 @@ class Comment(models.Model):
536 536 @models.permalink
537 537 def get_absolute_base_url(self):
538 538 if self.hunch_evidence:
539   - return ("hunch_evidence", [self.hunch_evidence.hunch.pk])
  539 + return ("hunch_evidence", [self.hunch_evidence.hunch.pk, self.hunch_evidence.evidence.pk])
540 540
541 541 elif self.hunch:
542 542 return ("hunch_comments", [self.hunch.pk])
@@ -565,14 +565,8 @@ class Meta:
565 565 unique_together = ("hunch", "evidence")
566 566
567 567 @models.permalink
568   - def get_absolute_base_url(self):
569   - return ("hunch_evidence", [self.hunch.pk])
570   -
571 568 def get_absolute_url(self):
572   - return self.get_absolute_base_url() + "#" + self.anchor()
573   -
574   - def anchor(self):
575   - return "he%d" % self.pk
  569 + return ("hunch_evidence", [self.hunch.pk, self.evidence.pk])
576 570
577 571 def save(self, *args, **kwargs):
578 572 self.support_cache = self.get_support()
8 hunchworks/templates/comments/comment.html
... ... @@ -1,8 +0,0 @@
1   -<div class="comment{% ifequal request.user.get_profile comment.creator %} mine{% endifequal %}" id="c{{ comment.pk }}">
2   - {% include "includes/users/short.html" with object=comment.creator %}
3   -
4   - <div class="bubble">
5   - <div class="arrow"></div>
6   - {{ comment.text }}
7   - </div>
8   -</div>
36 hunchworks/templates/hunches/show/comments.html
@@ -6,39 +6,5 @@
6 6 {% endblock %}
7 7
8 8 {% block secondary_content %}
9   - <section class="comments on-hunch">
10   - <ul>
11   - {% for comment in comments %}
12   - <li>
13   - {% include "comments/comment.html" %}
14   - </li>
15   - {% endfor %}
16   -
17   - <li>
18   - <form action="" method="post" class="comment{% if form.errors %} errors{% endif %}">
19   - {% include "includes/users/short.html" with object=request.user.get_profile %}
20   -
21   - <div class="bubble">
22   - <div class="arrow"></div>
23   - {{ form.non_field_errors }}
24   - {% csrf_token %}
25   -
26   - {% for field in form.hidden_fields %}
27   - {{ field }}
28   - {% endfor %}
29   -
30   - {% for field in form.visible_fields %}
31   - {% include "includes/fields/base.html" %}
32   - {% endfor %}
33   -
34   - <div class="submit-trigger"></div>
35   -
36   - <div class="actions">
37   - <input type="submit" value="&raquo;">
38   - </div>
39   - </div>
40   - </form>
41   - </li>
42   - </ul>
43   - </section>
  9 + {% include "includes/comments/list_with_form.html" with object_list=comments form=form %}
44 10 {% endblock %}
2  hunchworks/templates/hunches/show/evidence.html
@@ -33,4 +33,6 @@
33 33
34 34 {% bookmarks evidence %}
35 35 </article>
  36 +
  37 + {% include "includes/comments/list_with_form.html" with object_list=comments form=form %}
36 38 {% endblock %}
10 hunchworks/templates/comments/form.html → hunchworks/templates/includes/comments/form.html
... ... @@ -1,16 +1,16 @@
1   -<form action="" method="post" class="comment{% if comment_form.errors %} errors{% endif %}">
  1 +<form action="" method="post" class="comment{% if form.errors %} errors{% endif %}">
2 2 {% include "includes/users/short.html" with object=request.user.get_profile %}
3 3
4 4 <div class="bubble">
5 5 <div class="arrow"></div>
6   - {{ comment_form.non_field_errors }}
  6 + {{ form.non_field_errors }}
7 7 {% csrf_token %}
8 8
9   - {% for field in comment_form.hidden_fields %}
  9 + {% for field in form.hidden_fields %}
10 10 {{ field }}
11 11 {% endfor %}
12 12
13   - {% for field in comment_form.visible_fields %}
  13 + {% for field in form.visible_fields %}
14 14 {% include "includes/fields/base.html" %}
15 15 {% endfor %}
16 16
@@ -21,4 +21,4 @@
21 21 <input type="submit" value="&raquo;">
22 22 </div>
23 23 </div>
24   -</form>
  24 +</form>
13 hunchworks/templates/includes/comments/list_with_form.html
... ... @@ -0,0 +1,13 @@
  1 +<section class="object-list comments">
  2 + <ul>
  3 + {% for object in object_list %}
  4 + <li>
  5 + {% include "includes/comments/short.html" %}
  6 + </li>
  7 + {% endfor %}
  8 +
  9 + <li>
  10 + {% include "includes/comments/form.html" with form=form %}
  11 + </li>
  12 + </ul>
  13 +</section>
8 hunchworks/templates/includes/comments/short.html
... ... @@ -0,0 +1,8 @@
  1 +<div class="comment{% ifequal request.user.get_profile object.creator %} mine{% endifequal %}" id="c{{ object.pk }}">
  2 + {% include "includes/users/short.html" with object=object.creator %}
  3 +
  4 + <div class="bubble">
  5 + <div class="arrow"></div>
  6 + {{ object.text }}
  7 + </div>
  8 +</div>
10 hunchworks/views/hunches.py
@@ -149,10 +149,20 @@ def hunch_evidence(req, hunch_id, evidence_id):
149 149 evidence = get_object_or_404(models.Evidence, pk=evidence_id)
150 150 hunch_evidence = models.HunchEvidence.objects.get(hunch=hunch_id, evidence=evidence_id)
151 151
  152 + form = forms.CommentForm(req.POST or None, initial={
  153 + "hunch_evidence": hunch_evidence
  154 + })
  155 +
  156 + if form.is_valid():
  157 + comment = form.save(creator=req.user.get_profile())
  158 + return redirect(comment)
  159 +
152 160 return _render(req, "show/evidence", {
153 161 "hunch": hunch,
154 162 "evidence": evidence,
155 163 "hunch_evidence": hunch_evidence,
  164 + "comments": hunch_evidence.comment_set.all(),
  165 + "form": form
156 166 })
157 167
158 168

0 comments on commit 577ca48

Please sign in to comment.
Something went wrong with that request. Please try again.