Mercurial > public > sg101
changeset 704:809d27b385f2
For user uploaded photos (#50), add a simple gallery view.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 15 Sep 2013 15:13:02 -0500 |
parents | d7a0aaabc06c |
children | 7d6b0d831d67 |
files | sg101/templates/bio/view_profile.html sg101/templates/core/django_pagination.html sg101/templates/user_photos/gallery.html sg101/templates/user_photos/photo_detail.html sg101/templates/user_photos/upload_form.html static/icons/pictures.png user_photos/urls.py user_photos/views.py |
diffstat | 8 files changed, 112 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/sg101/templates/bio/view_profile.html Sat Sep 14 18:43:10 2013 -0500 +++ b/sg101/templates/bio/view_profile.html Sun Sep 15 15:13:02 2013 -0500 @@ -26,6 +26,7 @@ <p>{% avatar subject 0 %} <ul> <li><a href="{% url 'forums-my_posts' %}">My forum posts</a></li> + <li><a href="{% url 'user_photos-gallery' username=subject.username %}">My uploaded photos</a></li> <li><a href="{% url 'forums-manage_favorites' %}">My favorite forum topics</a></li> <li><a href="{% url 'forums-manage_subscriptions' %}">My forum topic subscriptions</a></li> </ul> @@ -83,6 +84,8 @@ <a href="{% url 'bio-edit_profile' %}">Edit Profile</a></li> <li><a href="{% url 'bio-change_avatar' %}"><img src="{{ STATIC_URL }}icons/image_edit.png" alt="Change Avatar" /></a> <a href="{% url 'bio-change_avatar' %}">Change Avatar</a></li> + <li><a href="{% url 'user_photos-upload' %}"><img src="{{ STATIC_URL }}icons/picture_add.png" alt="Upload Photo" /></a> + <a href="{% url 'user_photos-upload' %}">Upload Photo</a></li> <li><a href="{% url 'bio-edit_elsewhere' %}"><img src="{{ STATIC_URL }}icons/link_edit.png" alt="Edit Links" /></a> <a href="{% url 'bio-edit_elsewhere' %}">Edit Elsewhere Links</a></li> <li><a href="{% url 'django.contrib.auth.views.password_change' %}"><img src="{{ STATIC_URL }}icons/key.png" alt="Change Password" /></a> @@ -94,6 +97,8 @@ <li><a href="{% url 'messages-compose_to' subject.username %}"><img src="{{ STATIC_URL }}icons/note.png" alt="PM" title="Send Private Message" /></a> <a href="{% url 'messages-compose_to' subject.username %}">Send a private message to {{ subject.username }}</a></li> <li><a href="{% url 'forums-posts_for_user' username=subject.username %}"><img src="{{ STATIC_URL }}icons/comments.png" alt="Forum Posts" title="View forum posts by {{ subject.username }}" /></a> <a href="{% url 'forums-posts_for_user' username=subject.username %}">View forum posts by {{ subject.username }}</a></li> + <li><a href="{% url 'user_photos-gallery' username=subject.username %}"><img src="{{ STATIC_URL }}icons/pictures.png" + alt="View photos" title="View photos uploaded by {{ subject.username }}" /></a> <a href="{% url 'user_photos-gallery' username=subject.username %}">View photos uploaded by {{ subject.username }}</a></li> <li><img src="{{ STATIC_URL }}icons/flag_red.png" alt="Flag" /> <a href="#" class="profile-flag" id="fp-{{ profile.id }}">Report this profile</a></li> </ul>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/core/django_pagination.html Sun Sep 15 15:13:02 2013 -0500 @@ -0,0 +1,15 @@ +<div class="pagination"> + <span class="step-links"> + {% if page_obj.has_previous %} + <a href="?page={{ page_obj.previous_page_number }}">« Previous</a> • + {% endif %} + + <span class="current"> + Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }} + </span> + + {% if page_obj.has_next %} + • <a href="?page={{ page_obj.next_page_number }}">Next »</a> + {% endif %} + </span> +</div>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/user_photos/gallery.html Sun Sep 15 15:13:02 2013 -0500 @@ -0,0 +1,36 @@ +{% extends 'base.html' %} +{% load bio_tags %} +{% block title %}Photo Gallery for {{ gallery_owner.username }}{% endblock %} +{% block content %} + +<h2>Photo Gallery for {{ gallery_owner.username }}</h2> + +{% if user == gallery_owner %} +<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 %} + {% for photo in photos %} + <div style="padding: 1em; display: inline;"> + <a href="{{ photo.get_absolute_url }}"> + <img src="{{ photo.thumb_url }}" alt="thumbnail" + title="{{ photo.upload_date|date }}" /></a> + </div> + {% endfor %} + + {% if page_obj %} + <hr style="margin-top: 1.5em;" /> + {% include 'core/django_pagination.html' %} + {% endif %} +{% else %} + <p>Looks like {{ gallery_owner.username }} has no photos at this time.</p> +{% endif %} + +{% endblock %}
--- a/sg101/templates/user_photos/photo_detail.html Sat Sep 14 18:43:10 2013 -0500 +++ b/sg101/templates/user_photos/photo_detail.html Sun Sep 15 15:13:02 2013 -0500 @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% load bio_tags %} {% block title %}User Photo Details{% endblock %} {% block custom_js %} <script> @@ -21,7 +22,7 @@ <table> <tr> <th>Uploader:</th> - <td>{{ object.user.username }}</td> + <td>{% profile_link object.user.username %}</td> </tr> <tr> <th>Date:</th> @@ -34,6 +35,10 @@ Use the SG101 code on this site. The BB Code will work on many other forums. The direct link is useful for email. </p> +<p> +Click on a code then copy it to your clipboard (e.g. CTRL-C). You can then +paste the code into a forum post or email (e.g. CTRL-V). +</p> <table> <tr> @@ -50,10 +55,19 @@ </tr> </table> +{% if request.user == object.user %} +<ul class="icon-list"> + <li><img src="{{ STATIC_URL }}icons/picture_add.png" alt="Photo" /> + <a href="{% url 'user_photos-upload' %}">Upload another photo</a></li> + <li><img src="{{ STATIC_URL }}icons/pictures.png" alt="Gallery" /> + <a href="{% url 'user_photos-gallery' username=object.user.username %}">See all my photos</a></li> + </ul> +{% else %} <p> -<img src="{{ STATIC_URL }}icons/picture_add.png" alt="Photo" /> -<a href="{% url 'user_photos-upload' %}">Upload another photo</a> +<img src="{{ STATIC_URL }}icons/pictures.png" alt="Gallery" /> +<a href="{% url 'user_photos-gallery' username=object.user.username %}">See all photos from {{ object.user.username }}</a></li> </p> +{% endif %} {% endblock %}
--- a/sg101/templates/user_photos/upload_form.html Sat Sep 14 18:43:10 2013 -0500 +++ b/sg101/templates/user_photos/upload_form.html Sun Sep 15 15:13:02 2013 -0500 @@ -17,6 +17,10 @@ <p><input type="submit" name="submit" value="Upload Photo" /></p> </fieldset> </form> + <p> + <a href="{% url 'user_photos-gallery' username=user.username %}">See all + photos you've uploaded</a>. + </p> {% else %} <p class="error"> We're sorry but uploading is currently disabled. Please try back later.
--- a/user_photos/urls.py Sat Sep 14 18:43:10 2013 -0500 +++ b/user_photos/urls.py Sun Sep 15 15:13:02 2013 -0500 @@ -3,11 +3,15 @@ from django.views.generic import DetailView from user_photos.models import Photo +from user_photos.views import GalleryView -urlpatterns = patterns('user_photos.views', - url(r'^upload/$', 'upload', name='user_photos-upload'), +urlpatterns = patterns('', + url(r'^upload/$', 'user_photos.views.upload', name='user_photos-upload'), url(r'^photo/(?P<pk>\d+)/$', DetailView.as_view(model=Photo), - name='user_photos-detail') + name='user_photos-detail'), + url(r'^gallery/(?P<username>[\w.@+-]{1,30})/$', + GalleryView.as_view(), + name='user_photos-gallery'), )
--- a/user_photos/views.py Sat Sep 14 18:43:10 2013 -0500 +++ b/user_photos/views.py Sun Sep 15 15:13:02 2013 -0500 @@ -1,9 +1,13 @@ """Views for the user_photos application.""" from django.conf import settings +from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, get_object_or_404 +from django.views.generic import ListView +from django.utils.decorators import method_decorator from user_photos.forms import UploadForm +from user_photos.models import Photo @login_required @@ -35,3 +39,26 @@ 'form': form, }, status=200 if uploads_enabled else 503) + + +class GalleryView(ListView): + """A ListView for displaying a user's photos""" + + template_name = 'user_photos/gallery.html' + context_object_name = 'photos' + paginate_by = 50 + allow_empty = True + + def get_queryset(self): + self.gallery_owner = get_object_or_404(get_user_model(), + username=self.kwargs['username']) + return Photo.objects.filter(user=self.gallery_owner).order_by('-upload_date') + + def get_context_data(self, **kwargs): + context = super(GalleryView, self).get_context_data(**kwargs) + context['gallery_owner'] = self.gallery_owner + return context + + @method_decorator(login_required) + def dispatch(self, *args, **kwargs): + return super(GalleryView, self).dispatch(*args, **kwargs)