Exemple #1
0
 def clean_dir_name(self):
     if self.cleaned_data['dir_name']:
         # only letters, numbers, underscores, spaces and hyphens are allowed.
         if not alnum_name_re.search(self.cleaned_data['dir_name']):
             raise forms.ValidationError(_(u'Only letters, numbers, underscores, spaces and hyphens are allowed.'))
         # Folder must not already exist.
         if os.path.isdir(os.path.join(self.path, convert_filename(self.cleaned_data['dir_name']))):
             raise forms.ValidationError(_(u'The Folder already exists.'))
     return convert_filename(self.cleaned_data['dir_name'])
Exemple #2
0
def _upload_file(request):
    """
    Upload file to the server.
    """

    from django.core.files.move import file_move_safe

    if request.method == 'POST':
        folder = request.POST.get('folder')
        fb_uploadurl_re = re.compile(r'^.*(%s)' % reverse("fb_upload"))
        folder = fb_uploadurl_re.sub('', folder)
        abs_path = os.path.join(MEDIA_ROOT, DIRECTORY, folder)
        if request.FILES:
            filedata = request.FILES['Filedata']
            filedata.name = convert_filename(filedata.name)
            # PRE UPLOAD SIGNAL
            filebrowser_pre_upload.send(sender=request, path=request.POST.get('folder'), file=filedata)
            # HANDLE UPLOAD
            uploadedfile = handle_file_upload(abs_path, filedata)
            # MOVE UPLOADED FILE
            # if file already exists
            if os.path.isfile(smart_str(os.path.join(MEDIA_ROOT, DIRECTORY, folder, filedata.name))):
                old_file = smart_str(os.path.join(abs_path, filedata.name))
                new_file = smart_str(os.path.join(abs_path, uploadedfile))
                file_move_safe(new_file, old_file)
            # POST UPLOAD SIGNAL
            filebrowser_post_upload.send(sender=request, path=request.POST.get('folder'), file=FileObject(smart_str(os.path.join(DIRECTORY, folder, filedata.name))))
    return HttpResponse('True')
Exemple #3
0
def _check_file(request):
    """
    Check if file already exists on the server.
    """

    from django.utils import simplejson

    folder = request.POST.get('folder')
    fb_uploadurl_re = re.compile(r'^.*(%s)' % reverse("fb_upload"))
    folder = fb_uploadurl_re.sub('', folder)

    fileArray = {}
    if request.method == 'POST':
        for k,v in request.POST.items():
            if k != "folder":
                v = convert_filename(v)
                if os.path.isfile(smart_str(os.path.join(MEDIA_ROOT, DIRECTORY, folder, v))):
                    fileArray[k] = v

    return HttpResponse(simplejson.dumps(fileArray))