{% load i18n %}

<div class="object-widget-inclusion poll-widget-inclusion" id="poll-widget-oid-{{ object.id }}">
    {% if object.image %}<div class="image"><img src="{{ object.get_modelbase_list_item_thumbnail_LAYER_url }}"/></div>{% endif %}
    <div class="title"><a href="{{ object.get_absolute_url }}">{{ object.title }}</a></div>

    {% if can_vote_on_poll %}
        <form action="{% url poll-widget-vote object.id %}" method="POST" id="poll-widget-form-{{ object.id }}">
            {% csrf_token %}
            {{ form.as_div }}
            <div class="buttons">
                <input type="submit" value="{% trans "Vote" %}" />
                <a href="{{ object.get_absolute_url }}?results=1" onclick="document.getElementById('poll-widget-results-{{ object.id }}').style.display = 'block'; document.getElementById('poll-widget-form-{{ object.id }}').style.display = 'none'; return false;">{% trans "See results" %}</a>                
            </div>
        </form>
    {% endif %}

    <div id="poll-widget-results-{{ object.id }}" {% if can_vote_on_poll %}style="display: none;"{% endif %}>
        <table class="poll-results" cellspacing="0">
        {% for obj in object.polloption_set.all %}
            <tr class="poll-result-{{ forloop.counter }}">
                <td>{{ obj.title }}</td> 
                <td class="bar">
                    <div style="width: {{ obj.percentage }}%;">&nbsp;</div>
                </td>
                <td>
                    {{ obj.percentage|floatformat }}%
                </td>
            </tr>
        {% endfor %}
        </table>
        {% if can_vote_on_poll %}        
        <div class="buttons">
            <a href="{{ object.get_absolute_url }}" onclick="document.getElementById('poll-widget-results-{{ object.id }}').style.display = 'none'; document.getElementById('poll-widget-form-{{ object.id }}').style.display = 'block'; return false;">{% trans "Vote" %}</a>                
        </div>
        {% endif %}
    </div>

    {% if not can_vote_on_poll %}
        {% if reason == 'auth_required' %}
            <a href="{% url login %}">{% trans "You must be signed in to vote" %}</a>
        {% endif %}
    {% endif %}

</div>
