Пример #1
0
def upload(request, project_slug, dir_name=None):
    """
    Multipe Upload.
    """
    
    from django.forms.formsets import formset_factory
    project = get_object_or_404(Project, slug__iexact=project_slug, members=request.user)
    path = _get_path(dir_name, str(project.pk))
    query = request.GET
    
    # PIL's Error "Suspension not allowed here" work around:
    # s. http://mail.python.org/pipermail/image-sig/1999-August/000816.html
    if STRICT_PIL:
        from PIL import ImageFile
    else:
        try:
            from PIL import ImageFile
        except ImportError:
            import ImageFile
    ImageFile.MAXBLOCK = IMAGE_MAXBLOCK # default is 64k
    
    UploadFormSet = formset_factory(UploadForm, formset=BaseUploadFormSet, extra=5)
    if request.method == 'POST':
        formset = UploadFormSet(data=request.POST, files=request.FILES, path_server=PATH_SERVER, path=path)
        if formset.is_valid():
            for cleaned_data in formset.cleaned_data:
                if cleaned_data:
                    # UPLOAD FILE
                    _handle_file_upload(PATH_SERVER, path, cleaned_data['file'])
            # MESSAGE & REDIRECT
            msg = _('Upload successful.')
            request.user.message_set.create(message=msg)
            # on redirect, sort by date desc to see the uploaded files on top of the list
            # remove filter in order to actually _see_ the uploaded file(s)
            redirect = _redirect_to_path(path)
            if redirect:
                return HttpResponseRedirect(reverse('file-folder-list', kwargs = {'project_slug': project.slug, 'dir_name': redirect}))
            else:
                return HttpResponseRedirect(reverse('file-list', kwargs = {'project_slug': project.slug }))
    else:
        formset = UploadFormSet(path_server=PATH_SERVER, path=path)

    return direct_to_template(request,
                              template='blfile/upload.html',
                              extra_context={'formset': formset,
                                             'dir': dir_name,
                                             'query': query,
                                             'settings_var': _get_settings_var(),
                                             'breadcrumbs': _get_breadcrumbs(query, dir_name, project.slug, _(u'Upload')),
                                             'title': _(u'Select files to upload'),
                                             'root_path': URL_HOME,
                                             'project': project,})
Пример #2
0
def upload(request, project_slug, dir_name=None):
    """
    Multipe Upload.
    """

    from django.forms.formsets import formset_factory
    project = get_object_or_404(Project,
                                slug__iexact=project_slug,
                                members=request.user)
    path = _get_path(dir_name, str(project.pk))
    query = request.GET

    # PIL's Error "Suspension not allowed here" work around:
    # s. http://mail.python.org/pipermail/image-sig/1999-August/000816.html
    if STRICT_PIL:
        from PIL import ImageFile
    else:
        try:
            from PIL import ImageFile
        except ImportError:
            import ImageFile
    ImageFile.MAXBLOCK = IMAGE_MAXBLOCK  # default is 64k

    UploadFormSet = formset_factory(UploadForm,
                                    formset=BaseUploadFormSet,
                                    extra=5)
    if request.method == 'POST':
        formset = UploadFormSet(data=request.POST,
                                files=request.FILES,
                                path_server=PATH_SERVER,
                                path=path)
        if formset.is_valid():
            for cleaned_data in formset.cleaned_data:
                if cleaned_data:
                    # UPLOAD FILE
                    _handle_file_upload(PATH_SERVER, path,
                                        cleaned_data['file'])
            # MESSAGE & REDIRECT
            msg = _('Upload successful.')
            request.user.message_set.create(message=msg)
            # on redirect, sort by date desc to see the uploaded files on top of the list
            # remove filter in order to actually _see_ the uploaded file(s)
            redirect = _redirect_to_path(path)
            if redirect:
                return HttpResponseRedirect(
                    reverse('file-folder-list',
                            kwargs={
                                'project_slug': project.slug,
                                'dir_name': redirect
                            }))
            else:
                return HttpResponseRedirect(
                    reverse('file-list', kwargs={'project_slug':
                                                 project.slug}))
    else:
        formset = UploadFormSet(path_server=PATH_SERVER, path=path)

    return direct_to_template(request,
                              template='blfile/upload.html',
                              extra_context={
                                  'formset':
                                  formset,
                                  'dir':
                                  dir_name,
                                  'query':
                                  query,
                                  'settings_var':
                                  _get_settings_var(),
                                  'breadcrumbs':
                                  _get_breadcrumbs(query, dir_name,
                                                   project.slug, _(u'Upload')),
                                  'title':
                                  _(u'Select files to upload'),
                                  'root_path':
                                  URL_HOME,
                                  'project':
                                  project,
                              })
Пример #3
0
def list(request, project_slug, dir_name=None):
    """
    Show list of files on a server-directory.
    """
    project = get_object_or_404(Project,
                                slug__iexact=project_slug,
                                members=request.user)
    path = _get_path(dir_name, str(project.pk))
    query = request.GET

    # INITIAL VARIABLES
    results_var = {
        'results_total': 0,
        'results_current': 0,
        'delete_total': 0,
        'thumbs_total': 0,
        'generator_total': 0,
        'select_total': 0
    }
    counter = {}
    for k, v in EXTENSIONS.iteritems():
        counter[k] = 0

    try:
        dir_list = os.listdir(os.path.join(PATH_SERVER, path))
    except OSError:
        raise Http404

    files = []
    for file in dir_list:

        # EXCLUDE FILES MATCHING THUMB_PREFIX OR ANY OF THE EXCLUDE PATTERNS
        filtered = file.startswith('.')
        for re_prefix in filter_re:
            if re_prefix.search(file):
                filtered = True
        if filtered:
            continue

        # only increment results_total if file is not filtered
        results_var['results_total'] += 1

        # CREATE FILEOBJECT
        fileobject = FileObject(file, path, request.GET.get('type', ''))

        # COUNTER/RESULTS
        if fileobject.filetype:
            counter[fileobject.filetype] += 1
        if fileobject.filetype == 'Image':
            results_var['thumbs_total'] += 1
        if fileobject.filetype != 'Folder':
            results_var['delete_total'] += 1
        elif fileobject.filetype == 'Folder' and fileobject.folder_is_empty():
            results_var['delete_total'] += 1

        # FILTER / SEARCH
        append = False
        if fileobject.filetype == request.GET.get(
                'filter_type', fileobject.filetype) and _get_filterdate(
                    request.GET.get('filter_date', ''), fileobject.date):
            append = True
        if request.GET.get('q') and not re.compile(
                request.GET.get('q').lower(), re.M).search(file.lower()):
            append = False

        # APPEND FILE_LIST
        if append:
            files.append(fileobject)
            results_var['results_current'] += 1

    # SORTING
    files = _sort_by_attr(files, request.GET.get('o', 'date'))
    if request.GET.get('ot') == "desc":
        files.reverse()

    return direct_to_template(request,
                              template='blfile/list.html',
                              extra_context={
                                  'dir':
                                  dir_name,
                                  'files':
                                  files,
                                  'results_var':
                                  results_var,
                                  'query':
                                  query,
                                  'counter':
                                  counter,
                                  'settings_var':
                                  _get_settings_var(),
                                  'breadcrumbs':
                                  _get_breadcrumbs(query, dir_name,
                                                   project.slug, ''),
                                  'title':
                                  _(u'FileBrowser'),
                                  'root_path':
                                  URL_HOME,
                                  'project':
                                  project,
                              })
Пример #4
0
                        [_('Error creating directory.')])
    else:
        form = MakeDirForm(PATH_SERVER, path)

    return direct_to_template(request,
                              template='blfile/makedir.html',
                              extra_context={
                                  'form':
                                  form,
                                  'query':
                                  query,
                                  'settings_var':
                                  _get_settings_var(),
                                  'breadcrumbs':
                                  _get_breadcrumbs(query, dir_name,
                                                   project.slug,
                                                   _(u'New Folder')),
                                  'title':
                                  _(u'New Folder'),
                                  'root_path':
                                  URL_HOME,
                                  'project':
                                  project,
                              })


@login_required
def upload(request, project_slug, dir_name=None):
    """
    Multipe Upload.
    """
Пример #5
0
def list(request, project_slug, dir_name=None):
    """
    Show list of files on a server-directory.
    """
    project = get_object_or_404(Project, slug__iexact=project_slug, members=request.user)
    path = _get_path(dir_name, str(project.pk))
    query = request.GET
    
    # INITIAL VARIABLES
    results_var = {'results_total': 0, 'results_current': 0, 'delete_total': 0, 'thumbs_total': 0, 'generator_total': 0, 'select_total': 0 }
    counter = {}
    for k,v in EXTENSIONS.iteritems():
        counter[k] = 0
        
    try:
        dir_list = os.listdir(os.path.join(PATH_SERVER, path))
    except OSError:
        raise Http404
    
    files = []
    for file in dir_list:

        # EXCLUDE FILES MATCHING THUMB_PREFIX OR ANY OF THE EXCLUDE PATTERNS
        filtered = file.startswith('.')
        for re_prefix in filter_re:
            if re_prefix.search(file):
                filtered = True
        if filtered:
            continue
        
        # only increment results_total if file is not filtered
        results_var['results_total'] += 1
        
        # CREATE FILEOBJECT
        fileobject = FileObject(file, path, request.GET.get('type', ''))
        
        # COUNTER/RESULTS
        if fileobject.filetype:
            counter[fileobject.filetype] += 1
        if fileobject.filetype == 'Image':
            results_var['thumbs_total'] += 1
        if fileobject.filetype != 'Folder':
            results_var['delete_total'] += 1
        elif fileobject.filetype == 'Folder' and fileobject.folder_is_empty():
            results_var['delete_total'] += 1
        
        # FILTER / SEARCH
        append = False
        if fileobject.filetype == request.GET.get('filter_type', fileobject.filetype) and _get_filterdate(request.GET.get('filter_date', ''), fileobject.date):
            append = True
        if request.GET.get('q') and not re.compile(request.GET.get('q').lower(), re.M).search(file.lower()):
            append = False
        
        # APPEND FILE_LIST
        if append:
            files.append(fileobject)
            results_var['results_current'] += 1
    
    # SORTING
    files = _sort_by_attr(files, request.GET.get('o', 'date'))
    if request.GET.get('ot') == "desc":
        files.reverse()

    return direct_to_template(request,
                              template='blfile/list.html',
                              extra_context={'dir': dir_name,
                                             'files': files,
                                             'results_var': results_var,
                                             'query': query,
                                             'counter': counter,
                                             'settings_var': _get_settings_var(),
                                             'breadcrumbs': _get_breadcrumbs(query, dir_name, project.slug, ''),
                                             'title': _(u'FileBrowser'),
                                             'root_path': URL_HOME,
                                             'project': project,})
Пример #6
0
                else:
                    return HttpResponseRedirect(reverse('file-list', kwargs = {'project_slug': project.slug }))
            except OSError, (errno, strerror):
                if errno == 13:
                    form.errors['dir_name'] = forms.util.ErrorList([_('Permission denied.')])
                else:
                    form.errors['dir_name'] = forms.util.ErrorList([_('Error creating directory.')])
    else:
        form = MakeDirForm(PATH_SERVER, path)

    return direct_to_template(request,
                              template='blfile/makedir.html',
                              extra_context={'form': form,
                                             'query': query,
                                             'settings_var': _get_settings_var(),
                                             'breadcrumbs': _get_breadcrumbs(query, dir_name, project.slug, _(u'New Folder')),
                                             'title': _(u'New Folder'),
                                             'root_path': URL_HOME,
                                             'project': project,})

@login_required
def upload(request, project_slug, dir_name=None):
    """
    Multipe Upload.
    """
    
    from django.forms.formsets import formset_factory
    project = get_object_or_404(Project, slug__iexact=project_slug, members=request.user)
    path = _get_path(dir_name, str(project.pk))
    query = request.GET