# Path: image_filer/utils/files.py
# def generic_handle_file(file, original_filename):
#     """
#     Handels a file, regardless if a package or a single file and returns 
#     a list of files. can recursively unpack packages.
#     """
#     #print "entering generic_handle_file(file=%s, original_filename=%s)" % (file, original_filename)
#     files = []
#     filetype = os.path.splitext(original_filename)[1].lower()
#     #print filetype
#     if filetype=='.zip':
#         unpacked_files = unzip(file)
#         for ufile, ufilename in unpacked_files:
#             files += generic_handle_file(ufile, ufilename)
#     else:
#         files.append( (file,original_filename) )
#     #print "result of generic_handle_file: ", files
#     return files


import os
import filters
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.sessions.models import Session
from django.conf import settings
from django.db.models import Q
from django.core.exceptions import PermissionDenied
from models import Folder, Image, Clipboard, ClipboardItem
from models import tools
from models import FolderRoot, UnfiledImages, ImagesWithMissingData
from django.contrib.auth.models import User
from django import forms
from django.contrib import admin
from image_filer.utils.files import generic_handle_file
            'permissions': permissions,
            'permstest': _userperms(folder, request),
            'current_url': request.path,
            'title': u'Directory listing for %s' % folder.name,
            'search_string': ' '.join(search_terms),
            'show_result_count': show_result_count,
            'limit_search_to_folder': limit_search_to_folder,
            'is_popup': popup_status(request),
            'select_folder': selectfolder_status(request),
            'root_path': "/%s" % admin.site.root_path, # needed in the admin/base.html template for logout links and stuff 
        }, context_instance=RequestContext(request))

@login_required
def edit_folder(request, folder_id):
    # TODO: implement edit_folder view
    folder=None
    return render_to_response('image_filer/folder_edit.html', {
            'folder':folder,
            'is_popup': request.REQUEST.has_key('_popup') or request.REQUEST.has_key('pop'),
        }, context_instance=RequestContext(request))

@login_required
def edit_image(request, folder_id):
    # TODO: implement edit_image view
    folder=None
    return render_to_response('image_filer/image_edit.html', {
            'folder':folder,
            'is_popup': request.REQUEST.has_key('_popup') or request.REQUEST.has_key('pop'),
        }, context_instance=RequestContext(request))


# Path: image_filer/utils/files.py
# def generic_handle_file(file, original_filename):
#     """
#     Handels a file, regardless if a package or a single file and returns 
#     a list of files. can recursively unpack packages.
#     """
#     #print "entering generic_handle_file(file=%s, original_filename=%s)" % (file, original_filename)
#     files = []
#     filetype = os.path.splitext(original_filename)[1].lower()
#     #print filetype
#     if filetype=='.zip':
#         unpacked_files = unzip(file)
#         for ufile, ufilename in unpacked_files:
#             files += generic_handle_file(ufile, ufilename)
#     else:
#         files.append( (file,original_filename) )
#     #print "result of generic_handle_file: ", files
#     return files


# Path: image_filer/views.py
import os
import filters
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden, HttpResponseBadRequest
from django.contrib.sessions.models import Session
from django.conf import settings
from django.db.models import Q
from django.core.exceptions import PermissionDenied
from models import Folder, Image, Clipboard, ClipboardItem
from models import tools
from models import FolderRoot, UnfiledImages, ImagesWithMissingData
from django.contrib.auth.models import User
from django import forms
from django.contrib import admin
from image_filer.utils.files import generic_handle_file

            'permissions': permissions,
            'permstest': _userperms(folder, request),
            'current_url': request.path,
            'title': u'Directory listing for %s' % folder.name,
            'search_string': ' '.join(search_terms),
            'show_result_count': show_result_count,
            'limit_search_to_folder': limit_search_to_folder,
            'is_popup': popup_status(request),
            'select_folder': selectfolder_status(request),
            'root_path': "/%s" % admin.site.root_path, # needed in the admin/base.html template for logout links and stuff 
        }, context_instance=RequestContext(request))

@login_required
def edit_folder(request, folder_id):
    # TODO: implement edit_folder view
    folder=None
    return render_to_response('image_filer/folder_edit.html', {
            'folder':folder,
            'is_popup': request.REQUEST.has_key('_popup') or request.REQUEST.has_key('pop'),
        }, context_instance=RequestContext(request))

@login_required
def edit_image(request, folder_id):
    # TODO: implement edit_image view
    folder=None
    return render_to_response('image_filer/image_edit.html', {
            'folder':folder,
            'is_popup': request.REQUEST.has_key('_popup') or request.REQUEST.has_key('pop'),
        }, context_instance=RequestContext(request))


@login_required