コード例 #1
0
def upload(request, dir_name=None):
    """
    Multipe Upload.
    """
    
    from django.forms.formsets import formset_factory
    
    path = _get_path(request, dir_name)
    query = _get_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'])
                    if _get_file_type(cleaned_data['file'].name) == "Image":
                        # MAKE THUMBNAIL
                        _make_image_thumbnail(PATH_SERVER, path, cleaned_data['file'].name)
                        # IMAGE GENERATOR
                        if FORCE_GENERATOR or (cleaned_data['use_image_generator'] and (IMAGE_GENERATOR_LANDSCAPE != "" or IMAGE_GENERATOR_PORTRAIT != "")):
                            _image_generator(PATH_SERVER, path, cleaned_data['file'].name)
                        # GENERATE CROPPED/RECTANGULAR IMAGE
                        if FORCE_GENERATOR or (cleaned_data['use_image_generator'] and IMAGE_CROP_GENERATOR != ""):
                            _image_crop_generator(PATH_SERVER, path, cleaned_data['file'].name)
            # 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
            redirect_url = URL_ADMIN + path + "?&ot=desc&o=3&" + query['pop']
            return HttpResponseRedirect(redirect_url)
    else:
        formset = UploadFormSet(path_server=PATH_SERVER, path=path)
    
    return render_to_response('filebrowser/upload.html', {
        'formset': formset,
        'dir': dir_name,
        'query': _get_query(request.GET),
        'settings_var': _get_settings_var(request.META['HTTP_HOST'], path),
        'breadcrumbs': _get_breadcrumbs(_get_query(request.GET), dir_name, _(u'Upload')),
        'title': _(u'Select files to upload'),
        'root_path': URL_HOME,
    }, context_instance=Context(request))
コード例 #2
0
def upload(request, dir_name=None):
    """
    Multipe Upload.
    """
    
    from django.forms.formsets import formset_factory
    
    path = _get_path(dir_name)
    query = _get_query(request.GET)
    
    # PIL's Error "Suspension not allowed here" work around:
    # s. http://mail.python.org/pipermail/image-sig/1999-August/000816.html
    import ImageFile
    ImageFile.MAXBLOCK = 1000000 # 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'])
                    if _get_file_type(cleaned_data['file'].name) == "Image":
                        # MAKE THUMBNAIL
                        _make_image_thumbnail(PATH_SERVER, path, cleaned_data['file'].name)
                        # IMAGE GENERATOR
                        if cleaned_data['use_image_generator'] and (IMAGE_GENERATOR_LANDSCAPE != "" or IMAGE_GENERATOR_PORTRAIT != ""):
                            _image_generator(PATH_SERVER, path, cleaned_data['file'].name)
                        # GENERATE CROPPED/RECTANGULAR IMAGE
                        if cleaned_data['use_image_generator'] and IMAGE_CROP_GENERATOR != "":
                            _image_crop_generator(PATH_SERVER, path, cleaned_data['file'].name)
            # 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
            redirect_url = URL_ADMIN + path + "?&ot=desc&o=3&" + query['pop']
            return HttpResponseRedirect(redirect_url)
    else:
        formset = UploadFormSet(path_server=PATH_SERVER, path=path)
    
    return render_to_response('filebrowser/upload.html', {
        'formset': formset,
        'dir': dir_name,
        'query': _get_query(request.GET),
        'settings_var': _get_settings_var(request.META['HTTP_HOST'], path),
        'breadcrumbs': _get_breadcrumbs(_get_query(request.GET), dir_name, 'Multiple Upload'),
        'title': _('Select files to upload'),
    }, context_instance=Context(request))
コード例 #3
0
def generateimages(request, dir_name=None, file_name=None):
    """
    Generate Image Versions for existing singe Image or a whole Directory.
        This is useful if someone uploads images via FTP, not using the
        upload functionality of the FileBrowser.
    """

    path = _get_path(dir_name)
    query = request.GET

    if file_name:
        # GENERATE IMAGES
        if IMAGE_GENERATOR_LANDSCAPE != "" or IMAGE_GENERATOR_PORTRAIT != "":
            _image_generator(PATH_SERVER, path, file_name)
        # GENERATE CROPPED/RECTANGULAR IMAGE
        if IMAGE_CROP_GENERATOR != "":
            _image_crop_generator(PATH_SERVER, path, file_name)
    else:
        # GENERATE IMAGES FOR WHOLE DIRECTORY
        dir_path = os.path.join(PATH_SERVER, path)
        dir_list = os.listdir(dir_path)
        for file in dir_list:
            if os.path.isfile(
                    os.path.join(PATH_SERVER, path,
                                 file)) and _get_file_type(file) == "Image":
                # GENERATE IMAGES
                if IMAGE_GENERATOR_LANDSCAPE != "" or IMAGE_GENERATOR_PORTRAIT != "":
                    _image_generator(PATH_SERVER, path, file)
                # GENERATE CROPPED/RECTANGULAR IMAGE
                if IMAGE_CROP_GENERATOR != "":
                    _image_crop_generator(PATH_SERVER, path, file)

    # MESSAGE & REDIRECT
    msg = _('Successfully generated Images.')
    request.user.message_set.create(message=msg)
    return HttpResponseRedirect(URL_ADMIN + path + query_helper(query, "", ""))

    return render_to_response(
        'filebrowser/index.html', {
            'dir': dir_name,
            'query': query,
            'settings_var': _get_settings_var(),
            'breadcrumbs': _get_breadcrumbs(query, dir_name, ''),
            'root_path': URL_HOME,
        },
        context_instance=Context(request))
コード例 #4
0
def generateimages(request, dir_name=None, file_name=None):
    """
    Generate Image Versions for existing singe Image or a whole Directory.
        This is useful if someone uploads images via FTP, not using the
        upload functionality of the FileBrowser.
    """
    
    path = _get_path(request, dir_name)
    query = _get_query(request.GET)
    
    if file_name:
        # GENERATE IMAGES
        if IMAGE_GENERATOR_LANDSCAPE != "" or IMAGE_GENERATOR_PORTRAIT != "":
            _image_generator(PATH_SERVER, path, file_name)
        # GENERATE CROPPED/RECTANGULAR IMAGE
        if IMAGE_CROP_GENERATOR != "":
            _image_crop_generator(PATH_SERVER, path, file_name)
    else:
        # GENERATE IMAGES FOR WHOLE DIRECTORY
        dir_path = os.path.join(PATH_SERVER, path)
        dir_list = os.listdir(dir_path)
        for file in dir_list:
            if os.path.isfile(os.path.join(PATH_SERVER, path, file)) and not re.compile(THUMB_PREFIX, re.M).search(file) and _get_file_type(file) == "Image":
                # GENERATE IMAGES
                if IMAGE_GENERATOR_LANDSCAPE != "" or IMAGE_GENERATOR_PORTRAIT != "":
                    _image_generator(PATH_SERVER, path, file)
                # GENERATE CROPPED/RECTANGULAR IMAGE
                if IMAGE_CROP_GENERATOR != "":
                    _image_crop_generator(PATH_SERVER, path, file)
    
    # MESSAGE & REDIRECT
    msg = _('Successfully generated Images.')
    request.user.message_set.create(message=msg)
    return HttpResponseRedirect(URL_ADMIN + path + query['query_str_total'])
    
    return render_to_response('filebrowser/index.html', {
        'dir': dir_name,
        'query': query,
        'settings_var': _get_settings_var(request.META['HTTP_HOST'], path),
        'breadcrumbs': _get_breadcrumbs(_get_query(request.GET), dir_name, ''),
        'root_path': URL_HOME,
    }, context_instance=Context(request))
コード例 #5
0
def upload(request, dir_name=None):
    """
    Multipe Upload.
    """

    from django.forms.formsets import formset_factory

    path = _get_path(dir_name)
    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'])
                    if _get_file_type(cleaned_data['file'].name) == "Image":
                        # IMAGE GENERATOR
                        if FORCE_GENERATOR or (
                                cleaned_data['use_image_generator'] and
                            (IMAGE_GENERATOR_LANDSCAPE != ""
                             or IMAGE_GENERATOR_PORTRAIT != "")):
                            _image_generator(PATH_SERVER, path,
                                             cleaned_data['file'].name)
                        # GENERATE CROPPED/RECTANGULAR IMAGE
                        if FORCE_GENERATOR or (
                                cleaned_data['use_image_generator']
                                and IMAGE_CROP_GENERATOR != ""):
                            _image_crop_generator(PATH_SERVER, path,
                                                  cleaned_data['file'].name)
            # 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)
            return HttpResponseRedirect(URL_ADMIN + path + query_helper(
                query, "ot=desc,o=date", "ot,o,filter_type,filter_data"))
    else:
        formset = UploadFormSet(path_server=PATH_SERVER, path=path)

    return render_to_response(
        'filebrowser/upload.html', {
            'formset': formset,
            'dir': dir_name,
            'query': query,
            'settings_var': _get_settings_var(),
            'breadcrumbs': _get_breadcrumbs(query, dir_name, _(u'Upload')),
            'title': _(u'Select files to upload'),
            'root_path': URL_HOME,
        },
        context_instance=Context(request))