vote.html 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {# Template for up/down vote arrows.
  2. # This template expects these inputs
  3. #
  4. # - target: ('post', 'comment')
  5. # - item: either a "post" object or a "comment"
  6. # - user: reference to logged in user
  7. #}
  8. {% macro vote (target, item, user) %}
  9. <span class="vote {{ 'upvoted' if item.user_vote == 1 else '' }} {{ 'downvoted' if item.user_vote == -1 else '' }}">
  10. {% if user %}
  11. <form action="{{ url ('vote') }}" target="vote_sink" method="post">
  12. <input type="hidden" name="target" value="{{ target }}" />
  13. <input type="hidden" name="{{ target }}" value="{{ item.hashId }}" />
  14. <input type="hidden" name="updown" value="up" />
  15. <button title="upvote" class="">
  16. <img src="{{ url ('static', filename='images/upvote.png') }}" />
  17. </button>
  18. </form>
  19. {# Show number of votes #}
  20. <span class="count">{{ item.vote }}</span>
  21. <form action="{{ url ('vote') }}" target="vote_sink" method="post">
  22. <input type="hidden" name="target" value="{{ target }}" />
  23. <input type="hidden" name="{{ target }}" value="{{ item.hashId }}" />
  24. <input type="hidden" name="updown" value="down" />
  25. <button title="downvote" class="">
  26. <img src="{{ url ('static', filename='images/downvote.png') }}" />
  27. </button>
  28. </form>
  29. {% else %}
  30. {{ item.vote ~ ' vote' ~ ('s' if item.vote != 1) }}
  31. {% endif %}
  32. </span>
  33. {% endmacro %}