Exemplo n.º 1
0
def ls(request, path=None):
    """ Render file list """
    path = toString(path)
    dirlist = []
    filelist = []
    for f in os.listdir(path):
        f = toString(f)
        file = File(f, "%s/%s" % (path, f))
        if os.path.isdir(os.path.join(path, f)):
            file.isdir = 1
            file.size = "Dir"
            dirlist.append(file)
        else:
            file.isdir = 0
            file.size = os.path.getsize(os.path.join(path, f))
            filelist.append(file)
        dirlist.sort()
        filelist.sort()
            
    buffer = listBuffer(request)
    for item in buffer:
        item.append(os.path.basename(item[0]))
    
    anonymous = False
    if request.user.username == 'Anonymous':
        anonymous = True
    return render_to_response('list.html',
           {"pwd": path,
            "dirlist": dirlist,
            "filelist": filelist,
            "buffer": buffer,
            "anonymous": anonymous,
            },
            context_instance=RequestContext(request))
Exemplo n.º 2
0
 def wrapper(request, *args, **kw):
     path = None
     if "path" in kw:
         path = kw["path"]
     if path is None and len(args)>0:
         path = args[0]
     if path is None:
         if canNone:
             path = request.user.fileman_Setting.home
             kw["path"] = path
         else:
             return raise_error(request,
                 [_(u"Path does not set.")])
     if request.user.fileman_Setting.home is None or request.user.fileman_Setting.root is None:
         return raise_error(request,
             [_(u"Root or home directory is not set.")])
     root = request.user.fileman_Setting.root
     path = toUnicode(path)
     if not path.startswith(root):
         return raise_error(request,
             [_(u"No access")])
     if not os.path.exists(toString(path)):
         return raise_error(request,
             [_(u"Path does not exist.")])
     return fn(request, *args, **kw)
Exemplo n.º 3
0
def preview(request, path=None, size=(176, 176)):
    from PIL import Image
    path = toString(path)
    im = Image.open(path)
    im.thumbnail(size, Image.ANTIALIAS)
    response = HttpResponse(mimetype="image/png")
    im.save(response, "PNG")
    return response
Exemplo n.º 4
0
def createDir(request, path=None):
    if path is None:
        return HttpResponse(_(u"Path does not set."))
    try:
        path = toString(path)
        os.mkdir(path)
    except Exception, msg:
        return raise_error(request, [str(msg)])
Exemplo n.º 5
0
def download(request, path=None, filename=None, mimetype=None):
    path = toString(path)
    if filename is None: filename = os.path.basename(path)
    if mimetype is None:
        mimetype, encoding = mimetypes.guess_type(filename)
    filename, ext = os.path.splitext(filename)
    response = HttpResponse(FileWrapper(file(path)), mimetype=mimetype)
    response['Content-Disposition'] = "attachment; filename=%s%s" % (slugify(filename), ext)
    response['Content-Length'] = os.path.getsize(path)
    return response
Exemplo n.º 6
0
def getUrl(request, path=None):
    path = toString(path)
    for alias in Alias.objects.all():
        if path.startswith(alias.path):
            url = path.replace(alias.path, alias.url)
            if request.is_ajax():
                return json({"status": "success", "url": url})
            return HttpResponse(url)
    if request.is_ajax():
        return json({"status": "error"})
    return HttpResponse(_(u"No access."))
Exemplo n.º 7
0
def rename(request, path=None, newName=None):
    if path is None:
        return raise_error(request,
                [_(u"Input error")])
    if newName is None:
        if request.GET.has_key('newname'):
            newName = request.GET['newname']
        else:
            return raise_error(request,
                    [_(u"Input error")])
    path = toString(path)
    newName = toString(newName)
    dest = os.path.join(os.path.dirname(path), newName)
    fmoper.move(path, dest)
    createHistory(request.user, "rename", path, dest)
    if request.GET.has_key('next'):
        next = request.GET['next']
    else:
        next = ''
    if request.is_ajax():
        return json({"status": "success", "path": dest})
    return HttpResponseRedirect('/fm/list/%s' % next)
Exemplo n.º 8
0
def view(request, path=None):
    """ Render single file """
    path = toString(path)
    name, ext = os.path.splitext(os.path.basename(path))
    back = os.path.dirname(path)
    if ext in TEXT_EXT:
        f = open(path, 'r')
        data = f.readlines()
        f.close()
        return render_to_response('view_text.html',
           {"pwd": path,
            "data": file(path, "rb").read(),
            "back": back,
            },
            context_instance=RequestContext(request))
    elif ext in PICTURE_EXT:
        return render_to_response('view_picture.html',
           {"pwd": path,
            "back": back,
            },
            context_instance=RequestContext(request))
    else:
        return download(request, path)
Exemplo n.º 9
0
def destraction(request, path):
    path = toString(path)
    try:
        fmoper.remove(path)
    except Exception, msg:
            return raise_error(request, [str(msg)])
Exemplo n.º 10
0
def delete(request, path, inside=False):
    path = toString(path)
    try:
        fmoper.move(path, "%s/%s" % (BASKET_FOLDER, os.path.basename(path)))
    except Exception, msg:
        return raise_error(request, [str(msg)])