{% load url from future %}
{% load i18n %}
{% load agon_ratings_tags %}
{% load base_tags %}
{% load geonode_auth %}

{% overall_rating map "map" as map_rating %}
{% num_ratings map as num_votes %}

{% has_obj_perm user map "maps.view_map" as can_view_map %}

{% if can_view_map %}
<article>
  <div class="content">
    <div class="item-header">
      <a href="{% url "map_detail" map.id %}"><img class="thumb" src="{{ map.get_thumbnail_url }}" /></a>
      <h3><i class="icon-map-marker"></i> <a href="{% url "map_detail" map.id %}">{{ map.title }}</a></h3>
    </div>
    <div class="details">
      <div class="meta">
        <p>Map {% trans "from" %} <a href="{% url "profile_detail" map.owner.username %}" rel="author">{{ map.owner }}</a>, {{ map.last_modified|timesince }} {% trans 'ago' %}</p>
        <p class="abstract">{{ map.abstract }}</p>
        <ul class="nav stats">
          <li><a href="{% url "map_detail" map.id %}"><strong>{{ map.popular_count }}</strong> {% trans "view" %}{{ map.popular_count|pluralize }}</a></li>
          <li><a href="{% url "map_detail" map.id %}#rate"><strong><span class="avg_rating" data-rating="{{ map_rating }}"> <span class="overall_rating"></span></span></strong>{% trans "Average rating" %} ({{num_votes}} {% trans "votes" %})</a></li>
        </ul>
      </div> <!-- /.meta -->
      <div class="tools">
        <p>
          <a href="{% url "map_download" map.id %}" class="btn btn-mini">{% trans "Download" %}</a>
          <a href="{% url "map_view" map.id %}" class="btn btn-mini">{% trans "View" %}</a>
        </p>
      </div> 
    </div> <!-- /.details --> 
  </div> <!-- /.content -->
</article>
{%  else %}
<article>
    <div class="content">
        <div class="item-header">
            <img class="thumb" src="{{  STATIC_URL }}/geonode/img/missing_thumb.png" />
            <h3><i class="icon-map-marker"></i> {{ map.title }}</h3>
        </div>
        <div class="details">
            <div class="meta">
                <p>Map {% trans "from" %} <a href="{% url "profile_detail" map.owner.username %}" rel="author">{{ map.owner }}</a>, {{ map.last_modified|timesince }} {% trans 'ago' %}</p>
                <p class="abstract">{%  trans "You do not have permission to view this map" %}</p>
                <ul class="nav stats">
                    <li><a><strong>{{ map.popular_count }}</strong> {% trans "view" %}{{ map.popular_count|pluralize }}</a></li>
                    <li><a><strong><span class="avg_rating" data-rating="{{ map_rating }}"> <span class="overall_rating"></span></span></strong>{% trans "Average rating" %} ({{num_votes}} {% trans "votes" %})</a></li>
                </ul>
            </div> <!-- /.meta -->
            <div class="tools">
            </div>
        </div> <!-- /.details -->
    </div> <!-- /.content -->
</article>
{%  endif %}
