コード例 #1
0
ファイル: fileadmin.py プロジェクト: JiangJie/flask-admin
    def upload(self, path=None):
        """
            Upload view method

            :param path:
                Optional directory path. If not provided, will use the base directory
        """
        # Get path and verify if it is valid
        base_path, directory, path = self._normalize_path(path)

        if not self.can_upload:
            flash(gettext('File uploading is disabled.'), 'error')
            return redirect(self._get_dir_url('.index', path))

        form = UploadForm(self)
        if form.validate_on_submit():
            filename = op.join(directory,
                               secure_filename(form.upload.data.filename))

            if op.exists(filename):
                flash(gettext('File "%(name)s" already exists.', name=form.upload.data.filename),
                      'error')
            else:
                try:
                    self.save_file(filename, form.upload.data)
                    return redirect(self._get_dir_url('.index', path))
                except Exception, ex:
                    flash(gettext('Failed to save file: %(error)s', error=ex))
コード例 #2
0
ファイル: fileadmin.py プロジェクト: JiangJie/flask-admin
    def rename(self):
        """
            Rename view method
        """
        path = request.args.get('path')

        if not path:
            return redirect(url_for('.index'))

        base_path, full_path, path = self._normalize_path(path)

        return_url = self._get_dir_url('.index', op.dirname(path))

        if not self.can_rename:
            flash(gettext('Renaming is disabled.'))
            return redirect(return_url)

        if not op.exists(full_path):
            flash(gettext('Path does not exist.'))
            return redirect(return_url)

        form = NameForm(request.form, name=op.basename(path))
        if form.validate_on_submit():
            try:
                dir_base = op.dirname(full_path)
                filename = secure_filename(form.name.data)

                os.rename(full_path, op.join(dir_base, filename))
                flash(gettext('Successfully renamed "%(src)s" to "%(dst)s"',
                      src=op.basename(path),
                      dst=filename))
            except Exception, ex:
                flash(gettext('Failed to rename: %(error)s', error=ex), 'error')

            return redirect(return_url)
コード例 #3
0
    def upload(self, path=None):
        """
            Upload view method

            :param path:
                Optional directory path. If not provided, will use the base directory
        """
        # Get path and verify if it is valid
        base_path, directory, path = self._normalize_path(path)

        if not self.can_upload:
            flash(gettext('File uploading is disabled.'), 'error')
            return redirect(self._get_dir_url('.index', path))

        form = UploadForm(self)
        if form.validate_on_submit():
            filename = op.join(directory,
                               secure_filename(form.upload.data.filename))

            if op.exists(filename):
                flash(
                    gettext('File "%(name)s" already exists.',
                            name=form.upload.data.filename), 'error')
            else:
                try:
                    self.save_file(filename, form.upload.data)
                    return redirect(self._get_dir_url('.index', path))
                except Exception, ex:
                    flash(gettext('Failed to save file: %(error)s', error=ex))
コード例 #4
0
    def mkdir(self, path=None):
        """
            Directory creation view method

            :param path:
                Optional directory path. If not provided, will use the base directory
        """
        # Get path and verify if it is valid
        base_path, directory, path = self._normalize_path(path)

        dir_url = self._get_dir_url('.index', path)

        if not self.can_mkdir:
            flash(gettext('Directory creation is disabled.'), 'error')
            return redirect(dir_url)

        form = NameForm(request.form)

        if form.validate_on_submit():
            try:
                os.mkdir(op.join(directory, form.name.data))
                return redirect(dir_url)
            except Exception, ex:
                flash(gettext('Failed to create directory: %(error)s', ex),
                      'error')
コード例 #5
0
ファイル: fileadmin.py プロジェクト: AFCP/forumhorizonchine
    def mkdir(self, path=None):
        """
            Directory creation view method

            :param path:
                Optional directory path. If not provided, will use the base directory
        """
        # Get path and verify if it is valid
        base_path, directory, path = self._normalize_path(path)

        dir_url = self._get_dir_url('.index', path)

        if not self.can_mkdir:
            flash(gettext('Directory creation is disabled.'), 'error')
            return redirect(dir_url)

        form = NameForm(request.form)

        if form.validate_on_submit():
            try:
                os.mkdir(op.join(directory, form.name.data))
                self.on_mkdir(directory, form.name.data)
                return redirect(dir_url)
            except Exception, ex:
                flash(gettext('Failed to create directory: %(error)s', ex), 'error')
コード例 #6
0
ファイル: fladmin.py プロジェクト: cwoebker/fladmin
def upload(path=None):
    """
Upload view method

`path`
Optional directory path. If not provided, will use base directory
"""
    # Get path and verify if it is valid
    base_path, directory, path = _normalize_path(path)

    if not settings['upload']:
        flash('File uploading is disabled.', 'error')
        return redirect(_get_dir_url('.files', path))

    form = UploadForm()
    if form.validate_on_submit():
        filename = op.join(directory, secure_filename(form.upload.data.filename))

        if op.exists(filename):
            flash('File "%s" already exists.' % form.upload.data.filename, 'error')
        else:
            try:
                save_file(filename, form.upload.data)
                return redirect(_get_dir_url('.files', path))
            except Exception, ex:
                flash('Failed to save file: %s' % ex, 'error')
コード例 #7
0
ファイル: MyView.py プロジェクト: zhangshy/myofficial
 def login_view(self):
     form = LoginForm()
     if form.validate_on_submit():
         if 'verification' in session and session[
                 'verification'] == form.verification.data:
             user = form.get_user()
             if check_password_hash(user.password, form.password.data):
                 login.login_user(user)
                 identity_changed.send(current_app._get_current_object(),
                                       identity=Identity(user.id))
             else:
                 print('form in:%s' % form.password.data)
                 flash(u'密码错误')
         else:
             print('verification error:%s' % (form.verification.data))
             flash(u'验证码错误')
     if login.current_user.is_authenticated():
         return redirect(url_for('.index'))
     self._template_args['form'] = form
     return super(MyAdminIndexView, self).index()
コード例 #8
0
    def rename(self):
        """
            Rename view method
        """
        path = request.args.get('path')

        if not path:
            return redirect(url_for('.index'))

        base_path, full_path, path = self._normalize_path(path)

        return_url = self._get_dir_url('.index', op.dirname(path))

        if not self.can_rename:
            flash(gettext('Renaming is disabled.'))
            return redirect(return_url)

        if not op.exists(full_path):
            flash(gettext('Path does not exist.'))
            return redirect(return_url)

        form = NameForm(request.form, name=op.basename(path))
        if form.validate_on_submit():
            try:
                dir_base = op.dirname(full_path)
                filename = secure_filename(form.name.data)

                os.rename(full_path, op.join(dir_base, filename))
                self.on_rename(full_path, dir_base, filename)
                flash(
                    gettext('Successfully renamed "%(src)s" to "%(dst)s"',
                            src=op.basename(path),
                            dst=filename))
            except Exception, ex:
                flash(gettext('Failed to rename: %(error)s', error=ex),
                      'error')

            return redirect(return_url)
コード例 #9
0
ファイル: fladmin.py プロジェクト: cwoebker/fladmin
def mkdir(path=None):
    """
Directory creation view method

`path`
Optional directory path. If not provided, will use base directory
"""
    # Get path and verify if it is valid
    base_path, directory, path = _normalize_path(path)

    dir_url = _get_dir_url('.index', path)

    if not settings['mkdir']:
        flash('Directory creation is disabled.', 'error')
        return redirect(dir_url)

    form = NameForm(request.form)

    if form.validate_on_submit():
        try:
            os.mkdir(op.join(directory, form.name.data))
            return redirect(dir_url)
        except Exception, ex:
            flash('Failed to create directory: %s' % ex, 'error')