def filebrowser(request, file_type):
    """ Trigger view for filebrowser """
    template = 'filebrowser.html'
    upload_form = FileUploadForm()
    uploaded_file = None
    upload_tab_active = False
    is_images_dialog = (file_type == 'img')
    is_documents_dialog = (file_type == 'doc')


    files = FileBrowserFile.objects.filter(file_type=file_type)

    if LOCAL_MCE_FILEBROWSER_PERUSER == True and request.user and request.user.id:
        files = files.filter(user_id=request.user.id)

    if request.POST:
        if request.POST['q'] == '':
            upload_form = FileUploadForm(request.POST, request.FILES)
            upload_tab_active = True

            if upload_form.is_valid():
                uploaded_file = upload_form.save(commit=False)
                uploaded_file.file_type = file_type
                if LOCAL_MCE_FILEBROWSER_PERUSER == True and request.user and request.user.id:
                    uploaded_file.user_id = request.user.id
                uploaded_file.save()
        else:
            files = files.filter(uploaded_file__contains=request.POST['q'])

    data = {
        'files': files,
        'upload_form': upload_form,
        'uploaded_file': uploaded_file,
        'upload_tab_active': upload_tab_active,
        'is_images_dialog': is_images_dialog,
        'is_documents_dialog': is_documents_dialog,
        'LOCAL_MCE_FILEBROWSER_JQUERY': LOCAL_MCE_FILEBROWSER_JQUERY,
        'LOCAL_MCE_FILEBROWSER_UPLOADDIR': LOCAL_MCE_FILEBROWSER_UPLOADDIR,
        'LOCAL_MCE_FILEBROWSER_THEMECSS': LOCAL_MCE_FILEBROWSER_THEMECSS
    }

    return render_to_response(template, data, RequestContext(request))
Exemple #2
0
def filebrowser(request, file_type):
    """ Trigger view for filebrowser """
    template = 'filebrowser.html'
    upload_form = FileUploadForm()
    uploaded_file = None
    upload_tab_active = False
    is_images_dialog = (file_type == 'img')
    is_documents_dialog = (file_type == 'doc')
    
    files = FileBrowserFile.objects.filter(file_type=file_type)
    
    if request.POST:
        upload_form = FileUploadForm(request.POST, request.FILES)
        upload_tab_active = True
        
        if upload_form.is_valid():
            uploaded_file = upload_form.save(commit=False)
            uploaded_file.file_type = file_type
            uploaded_file.save()
    
    data = {
        'files': files,
        'upload_form': upload_form,
        'uploaded_file': uploaded_file,
        'upload_tab_active': upload_tab_active,
        'is_images_dialog': is_images_dialog,
        'is_documents_dialog': is_documents_dialog
    }
    
    return render_to_response(template, data, RequestContext(request))
Exemple #3
0
def filebrowser(request, file_type):
    """ Trigger view for filebrowser """
    template = 'filebrowser.html'
    upload_form = FileUploadForm()
    uploaded_file = None
    upload_tab_active = False
    is_images_dialog = (file_type == 'img')
    is_documents_dialog = (file_type == 'doc')
    
    files = FileBrowserFile.objects.filter(file_type=file_type)
    
    if request.POST:
        upload_form = FileUploadForm(request.POST, request.FILES)
        upload_tab_active = True
        
        if upload_form.is_valid():
            uploaded_file = upload_form.save(commit=False)
            uploaded_file.file_type = file_type
            uploaded_file.save()
    
    data = {
        'upload_form': upload_form,
        'uploaded_file': uploaded_file,
        'upload_tab_active': upload_tab_active,
        'is_images_dialog': is_images_dialog,
        'is_documents_dialog': is_documents_dialog
    }
    per_page = getattr(settings, 'FILEBROWSER_PER_PAGE', 20)
    return render_paginate(request, template, files, per_page, data)
Exemple #4
0
def filebrowser(request, file_type):
    """ Trigger view for filebrowser """
    template = 'filebrowser.html'
    upload_form = FileUploadForm()
    uploaded_file = None
    upload_tab_active = False
    is_images_dialog = (file_type == 'img')
    is_documents_dialog = (file_type == 'doc')

    files = FileBrowserFile.objects.filter(file_type=file_type)
    if LOCAL_MCE_FILEBROWSER_PERUSER == True and request.user and request.user.id:
        files = files.filter(user_id=request.user.id)

    if request.POST:
        upload_form = FileUploadForm(request.POST, request.FILES)
        upload_tab_active = True

        if upload_form.is_valid():
            uploaded_file = upload_form.save(commit=False)
            uploaded_file.file_type = file_type
            if LOCAL_MCE_FILEBROWSER_PERUSER == True and request.user and request.user.id:
                uploaded_file.user_id = request.user.id
            uploaded_file.save()

    data = {
        'files': files,
        'upload_form': upload_form,
        'uploaded_file': uploaded_file,
        'upload_tab_active': upload_tab_active,
        'is_images_dialog': is_images_dialog,
        'is_documents_dialog': is_documents_dialog,
        'LOCAL_MCE_FILEBROWSER_JQUERY': LOCAL_MCE_FILEBROWSER_JQUERY,
        'LOCAL_MCE_FILEBROWSER_UPLOADDIR': LOCAL_MCE_FILEBROWSER_UPLOADDIR,
        'LOCAL_MCE_FILEBROWSER_THEMECSS': LOCAL_MCE_FILEBROWSER_THEMECSS
    }

    return render_to_response(template, data, RequestContext(request))
Exemple #5
0
def filebrowser(request, file_type):
    """ Trigger view for filebrowser """
    template = 'filebrowser.html'
    upload_form = FileUploadForm()
    uploaded_file = None
    upload_tab_active = False
    is_images_dialog = (file_type == 'img')
    is_documents_dialog = (file_type == 'doc')

    files = FileBrowserFile.objects.filter(file_type=file_type).filter(user_id=request.user.id).order_by('pk')

    if request.POST:
        upload_form = FileUploadForm(request.POST, request.FILES)
        upload_tab_active = True

        if upload_form.is_valid():
            uploaded_file = upload_form.save(commit=False)
            fname = request.FILES['uploaded_file'].name.rpartition(".")
            filename = "{}.{}".format(slugify(fname[0]), fname[2])
            uploaded_file.file_name = filename
            uploaded_file.file_type = file_type
            uploaded_file.user_id = request.user.id
            uploaded_file.save()

    context = {
        'upload_form': upload_form,
        'uploaded_file': uploaded_file,
        'upload_tab_active': upload_tab_active,
        'is_images_dialog': is_images_dialog,
        'is_documents_dialog': is_documents_dialog,
        'LOCAL_MCE_FILEBROWSER_JQUERY': LOCAL_MCE_FILEBROWSER_JQUERY,
        'LOCAL_MCE_FILEBROWSER_THEMECSS': LOCAL_MCE_FILEBROWSER_THEMECSS,
        'absolute_domain': request.build_absolute_uri('/')[:-1],
    }

    per_page = getattr(settings, 'FILEBROWSER_PER_PAGE', 20)
    return render_paginate(request, template, files, per_page, context)