view sg101/templates/user_photos/gallery.html @ 718:bf5340705d0c

Completed view to delete user photos. Still need to modify the admin to delete not just the model instance but the S3 bucket keys.
author Brian Neal <bgneal@gmail.com>
date Wed, 18 Sep 2013 21:34:05 -0500
parents 846cf9a06a04
children 02ae9a4a846a
line wrap: on
line source
{% extends 'base.html' %}
{% load bio_tags %}
{% block title %}Photo Gallery for {{ gallery_owner.username }}{% endblock %}
{% block custom_css %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/user_photos.css" />
{% endblock %}
{% block custom_js %}
{% if user == gallery_owner %}
<script>
function confirmPhotoDelete(submit)
{
   var n = $("#photo-delete input[type='checkbox']:checked").length;
   if (n == 0)
   {
      alert("Please select some photos to delete.");
      return false;
   }

   var msg = [
      "Are you sure you want to delete these photos?\n",
      "This will cause broken images in any posts you pasted them in. ",
      "To fix this you can edit the posts."
   ].join("");
   var result = confirm(msg);
   if (result)
   {
      submit.disabled = true;
      submit.value = "Please wait...";
   }
   return result;
}
</script>
{% endif %}
{% endblock %}
{% block content %}

<h2>Photo Gallery for {{ gallery_owner.username }}</h2>

{% if user == gallery_owner %}
{% if messages %}
   <ul class="user-messages">
    {% for message in messages %}
       <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
{% endif %}
<p>
You have uploaded {{ paginator.count }} photo{{ paginator.count|pluralize }}.
Would you like to <a href="{% url 'user_photos-upload' %}">upload a photo</a>?
</p>
{% else %}
<p>
{% profile_link gallery_owner.username %} has uploaded {{ paginator.count }} photo{{ paginator.count|pluralize }}.
</p>
{% endif %}

{% if photos %}
   {% if user == gallery_owner %}
      <form id="photo-delete" action="{% url 'user_photos-delete' %}" method="post"
         onsubmit="return confirmPhotoDelete(submit);" >{% csrf_token %}
      {% for photo in photos %}
         <div class="user_photo owner_photo">
            <a href="{{ photo.get_absolute_url }}">
               <img src="{{ photo.thumb_url }}" alt="thumbnail" 
                  title="{{ photo.upload_date|date }}" /></a>
            <br />
            <div class="centered">
            <input type="checkbox" name="photo_id" value="{{ photo.id }}"></input>
            </div>
         </div>
      {% endfor %}
      <br />
      <input type="submit" name="submit" value="Delete Checked Photos" />
      </form>
   {% else %}
      {% for photo in photos %}
         <div class="user_photo">
            <a href="{{ photo.get_absolute_url }}">
               <img src="{{ photo.thumb_url }}" alt="thumbnail" 
                  title="{{ photo.upload_date|date }}" /></a>
         </div>
      {% endfor %}
   {% endif %}

   {% if page_obj %}
      <hr class="footer_divider" />
      {% include 'core/django_pagination.html' %}
   {% endif %}
{% endif %}

{% endblock %}