django-photos / src / photos / views.py

from photos.models import Photo, Album
from django.contrib.auth.models import User
from django.views.generic.list_detail import object_list, object_detail
from django.shortcuts import get_object_or_404

def album_list(request, user_id=0, username=None, *args, **kwargs):
    qs = Album.objects.filter(display=True)
    user = None
    
    if user_id > 0:
        user = get_object_or_404(User, id=user_id)
        qs = qs.filter(user=user)
    elif username is not None:
        user = get_object_or_404(User, username=username)
        qs = qs.filter(user=user)
    
    if user:
        extra_context = kwargs.get('extra_context', {})
        extra_context.update({'album_user': user})
        kwargs.update({'extra_context': extra_context})
    
    return object_list(request, queryset=qs, *args, **kwargs)

def photo_list(request, user_id=0, username=None, *args, **kwargs):
    qs = Photo.objects.filter(display=True)
    user = None
    
    if user_id > 0:
        user = get_object_or_404(User, id=user_id)
        qs = qs.filter(user=user)
    elif username is not None:
        user = get_object_or_404(User, username=username)
        qs = qs.filter(user=user)
        
    if user:
        extra_context = kwargs.get('extra_context', {})
        extra_context.update({'photo_user': user})
        kwargs.update({'extra_context': extra_context})
    
    return object_list(request, queryset=qs, *args, **kwargs)

def photo_detail(request, object_id, album_id, *args, **kwargs):
    album = get_object_or_404(Album, id=album_id)
    
    extra_context = kwargs.get('extra_context', {})
    extra_context.update({'album': album})
    kwargs.update({'extra_context': extra_context})
        
    return object_detail(request, object_id=object_id, *args, **kwargs)

def store_photo(request):
    print "has perm: photos.add_photo ",
    print request.user.has_perm("photos.add_photo")
    
    print "is ajax: ",
    print request.is_ajax()
    
    print "FILES array: ",
    print request.FILES
        
        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.