예제 #1
0
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            upload = request.FILES['upload']
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            full_filename = os.path.join(file_dir, upload.name)

            if os.path.isfile(full_filename) and not overwrite:
                messages.add_message(request, messages.ERROR, ('File %s already exists in that folder.' % (upload.name)))
                return HttpResponseRedirect('/theme-editor/editor')
            else:
                handle_uploaded_file(upload, file_dir)
                messages.add_message(request, messages.SUCCESS, ('Successfully uploaded %s.' % (upload.name)))

                EventLog.objects.log()

                return HttpResponseRedirect('/theme-editor/editor/')

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)

    else:
        form = UploadForm()

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #2
0
파일: views.py 프로젝트: BIGGANI/tendenci
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            upload = request.FILES['upload']
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            full_filename = os.path.join(file_dir, upload.name)

            if os.path.isfile(full_filename) and not overwrite:
                msg_string = 'File %s already exists in that folder.' % (upload.name)
                messages.add_message(request, messages.ERROR, _(msg_string))
                return HttpResponse('invalid', content_type="text/plain")
            else:
                handle_uploaded_file(upload, file_dir)
                msg_string = 'Successfully uploaded %s.' % (upload.name)
                messages.add_message(request, messages.SUCCESS, _(msg_string))

                EventLog.objects.log()
                # returning a response of "ok" (flash likes this)
                # response is for flash, not humans
                return HttpResponse('valid', content_type="text/plain")

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)
            return HttpResponse('invalid', content_type="text/plain")
    else:
        form = UploadForm()

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #3
0
파일: views.py 프로젝트: guyt101z/tendenci
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            upload = request.FILES['upload']
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            full_filename = os.path.join(file_dir, upload.name)

            if os.path.isfile(full_filename) and not overwrite:
                messages.add_message(request, messages.ERROR, ('File %s already exists in that folder.' % (upload.name)))
                return HttpResponseRedirect('/theme-editor/editor')
            else:
                handle_uploaded_file(upload, file_dir)
                messages.add_message(request, messages.SUCCESS, ('Successfully uploaded %s.' % (upload.name)))

                EventLog.objects.log()

                return HttpResponseRedirect('/theme-editor/editor/')

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)

    else:
        form = UploadForm()

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #4
0
파일: views.py 프로젝트: rob-hills/tendenci
def upload_file(request):

    selected_theme = request.GET.get("theme_edit", get_theme())
    if not is_valid_theme(selected_theme):
        raise Http404(_('Specified theme does not exist'))
    if is_theme_read_only(selected_theme):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']

            def callback(file_path, uuid, selected_theme=selected_theme, file_dir=file_dir, overwrite=overwrite):
                theme_root = get_theme_root(selected_theme)
                file_name = os.path.basename(file_path)
                full_filename = os.path.join(file_dir, file_name)
                if (not is_valid_path(theme_root, file_dir) or
                    not is_valid_path(theme_root, full_filename)):
                    raise Http403
                if os.path.isfile(os.path.join(theme_root, full_filename)) and not overwrite:
                    msg_string = 'File %s already exists in that folder.' % (file_name)
                    raise uploader.CallbackError(msg_string)
                copy_file_to_theme(file_path, selected_theme, file_dir, file_name)
                EventLog.objects.log()
            return uploader.post(request, callback)

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)
            return HttpResponse('invalid', content_type="text/plain")

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #5
0
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            def callback(file_path, uuid, file_dir=file_dir, overwrite=overwrite):
                file_name = os.path.basename(file_path)
                full_filename = os.path.join(file_dir, file_name)
                if os.path.isfile(full_filename) and not overwrite:
                    msg_string = 'File %s already exists in that folder.' % (file_name)
                    raise uploader.CallbackError(msg_string)
                else:
                    handle_uploaded_file(file_path, file_dir)
                    EventLog.objects.log()
            return uploader.post(request, callback)

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)
            return HttpResponse('invalid', content_type="text/plain")

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #6
0
파일: views.py 프로젝트: kaisatec/tendenci
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            upload = request.FILES['upload']
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            full_filename = os.path.join(file_dir, upload.name)

            if os.path.isfile(full_filename) and not overwrite:
                msg_string = 'File %s already exists in that folder.' % (upload.name)
                messages.add_message(request, messages.ERROR, _(msg_string))
                return HttpResponse('invalid', mimetype="text/plain")
            else:
                handle_uploaded_file(upload, file_dir)
                msg_string = 'Successfully uploaded %s.' % (upload.name)
                messages.add_message(request, messages.SUCCESS, _(msg_string))

                EventLog.objects.log()
                # returning a response of "ok" (flash likes this)
                # response is for flash, not humans
                return HttpResponse('valid', mimetype="text/plain")

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)
            return HttpResponse('invalid', mimetype="text/plain")
    else:
        form = UploadForm()

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #7
0
파일: views.py 프로젝트: goetzk/tendenci
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)

        if form.is_valid():
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']

            def callback(file_path, uuid, file_dir=file_dir, overwrite=overwrite):
                file_name = os.path.basename(file_path)
                full_filename = os.path.join(file_dir, file_name)
                if os.path.isfile(full_filename) and not overwrite:
                    msg_string = 'File %s already exists in that folder.' % (file_name)
                    raise uploader.CallbackError(msg_string)
                else:
                    handle_uploaded_file(file_path, file_dir)
                    EventLog.objects.log()
            return uploader.post(request, callback)

        else:  # not valid
            messages.add_message(request, messages.ERROR, form.errors)
            return HttpResponse('invalid', content_type="text/plain")

    return HttpResponseRedirect('/theme-editor/editor/')
예제 #8
0
파일: views.py 프로젝트: eloyz/tendenci
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            upload = request.FILES['upload']
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            full_filename = os.path.join(file_dir, upload.name)

            if os.path.isfile(full_filename) and not overwrite:
                messages.add_message(
                    request, messages.ERROR,
                    ('File %s already exists in that folder.' % (upload.name)))
                return HttpResponseRedirect('/theme-editor/editor')
            else:
                handle_uploaded_file(upload, file_dir)
                response = {"success": True}
                messages.add_message(request, messages.SUCCESS,
                                     ('Successfully uploaded %s.' %
                                      (upload.name)))

                log_defaults = {
                    'event_id':
                    1110100,
                    'event_data':
                    '%s uploaded by %s' % (full_filename, request.user),
                    'description':
                    'theme file upload',
                    'user':
                    request.user,
                    'request':
                    request,
                    'source':
                    'theme_editor',
                }
                EventLog.objects.log(**log_defaults)

                return HttpResponseRedirect('/theme-editor/editor/')
    else:
        form = UploadForm()

    return render_to_response(context_instance=RequestContext(request))
예제 #9
0
def upload_file(request):

    if not has_perm(request.user, 'theme_editor.add_themefileversion'):
        raise Http403

    if request.method == 'POST':
        form = UploadForm(request.POST, request.FILES)
        if form.is_valid():
            upload = request.FILES['upload']
            file_dir = form.cleaned_data['file_dir']
            overwrite = form.cleaned_data['overwrite']
            full_filename = os.path.join(file_dir, upload.name)

            if os.path.isfile(full_filename) and not overwrite:
                messages.add_message(request, messages.ERROR, ('File %s already exists in that folder.' % (upload.name)))
                return HttpResponseRedirect('/theme-editor/editor')
            else:
                handle_uploaded_file(upload, file_dir)
                response = {
                    "success": True
                }
                messages.add_message(request, messages.SUCCESS, ('Successfully uploaded %s.' % (upload.name)))

                log_defaults = {
                    'event_id': 1110100,
                    'event_data': '%s uploaded by %s' % (full_filename, request.user),
                    'description': 'theme file upload',
                    'user': request.user,
                    'request': request,
                    'source': 'theme_editor',
                }
                EventLog.objects.log(**log_defaults)

                return HttpResponseRedirect('/theme-editor/editor/')
    else:
        form = UploadForm()

    return render_to_response(context_instance=RequestContext(request))