Esempio n. 1
0
def show_photo(request, photo_id):
    photo_resp = {}
    try:
        photo = Photo.objects.get(pk=photo_id)
    except Photo.DoesNotExist:
        return HttpResponseRedirect('/photo/')
    photo_resp['url'] = photo.url()
    photo_resp['img'] = photo.img()
    photo_resp['desc'] = photo.desc
    # Get the ids of previous and next photos.
    photo_list = Photo.objects.filter(album__pk=photo.album.id)
    if photo_list.count() == 1:
        photo_resp['prev'] = -1
        photo_resp['next'] = -1
    elif photo_list[0].id == int(photo_id):
        photo_resp['prev'] = -1
        photo_resp['next'] = wrap_photo_url(photo_list[1].id)
    elif photo_list[photo_list.count()-1].id == int(photo_id):
        photo_resp['prev'] = wrap_photo_url(photo_list[photo_list.count()-2].id)
        photo_resp['next'] = -1
    else:
        for i in range(photo_list.count()):
            if photo_list[i].id == int(photo_id):
                photo_resp['prev'] == wrap_photo_url(photo_list[i-1].id)
                photo_resp['next'] == wrap_photo_url(photo_list[i+1].id)
                break
    comment = Comment.objects.filter(photo__pk=photo_id)
    return render_to_response('photo_view.html',
                              {'photo': photo_resp,
                               'album': photo.album,
                               'comment_list': comment},
                              context_instance=RequestContext(request));
Esempio n. 2
0
def show_photo_page(request, photo, form):
    photo_resp = {}
    photo_resp['url'] = photo.url()
    photo_resp['img'] = photo.img()
    photo_resp['desc'] = photo.desc
    # Get the ids of previous and next photos.
    photo_list = Photo.objects.filter(album__pk=photo.album.id)
    if photo_list.count() == 1:
        photo_resp['prev'] = -1
        photo_resp['next'] = -1
    elif photo_list[0].id == photo.id:
        photo_resp['prev'] = -1
        photo_resp['next'] = wrap_photo_url(photo_list[1].id)
    elif photo_list[photo_list.count()-1].id == photo.id:
        photo_resp['prev'] = wrap_photo_url(photo_list[photo_list.count()-2].id)
        photo_resp['next'] = -1
    else:
        for i in range(photo_list.count()):
            if photo_list[i].id == photo.id:
                photo_resp['prev'] == wrap_photo_url(photo_list[i-1].id)
                photo_resp['next'] == wrap_photo_url(photo_list[i+1].id)
                break
    comment = Comment.objects.filter(photo__pk=photo.id)
    return render_to_response('photo_view.html',
                              {'photo': photo_resp,
                               'album': photo.album,
                               'comment_list': comment,
                               'form': form },
                              context_instance=RequestContext(request));
Esempio n. 3
0
 def url(self):
     return wrap_photo_url(self.id)