def gallery(request, media_type='image'):
 if (media_type == 'image'):
  media_qs = Image.objects.filter(locale=request.LANGUAGE_CODE)
 elif (media_type == 'video'):
  media_qs = Video.objects.filter(locale=request.LANGUAGE_CODE)
 else:
  raise Http404
 media = paginate(request, media_qs, per_page=ITEMS_PER_PAGE)
 drafts = _get_drafts(request.user)
 image = (drafts['image'][0] if drafts['image'] else None)
 image_form = _init_media_form(ImageForm, request, image)
 if (request.method == 'POST'):
  image_form.is_valid()
 return render(request, 'gallery/gallery.html', {'media': media, 'media_type': media_type, 'image_form': image_form, 'submitted': (request.method == 'POST')})

def gallery ( request , media_type = 'image' ) : if ( media_type == 'image' ) : media_qs = Image . objects . filter ( locale = request . LANGUAGE_CODE ) elif ( media_type == 'video' ) : media_qs = Video . objects . filter ( locale = request . LANGUAGE_CODE ) else : raise Http404 media = paginate ( request , media_qs , per_page = ITEMS_PER_PAGE ) drafts = _get_drafts ( request . user ) image = ( drafts [ 'image' ] [ 0 ] if drafts [ 'image' ] else None ) image_form = _init_media_form ( ImageForm , request , image ) if ( request . method == 'POST' ) : image_form . is_valid ( ) return render ( request , 'gallery/gallery.html' , { 'media' : media , 'media_type' : media_type , 'image_form' : image_form , 'submitted' : ( request . method == 'POST' ) } )
the media gallery .