Exemplo n.º 1
0
    def commit(self):
        s = Session()
        session['messages'] = []
        paths = []

        message = request.params.get("message", "Web commit")
        db_files = s.query(Upload).filter(Upload.status == u"Moderated").all()
        for db_file in db_files:

            destination = get_path(None, db_file.destination)
            if destination == "Invalid path":
                session['messages'] += ["Invalid destination for the file %s" % db_file.name]
                session.save()
                return redirect_to(url_for(controller="moderation"))

            currentpath = os.path.join(get_path("moderation"), db_file.new_name)
            #os.sep is to fix a bug
            shutil.move(currentpath, destination+os.sep)

            oldpath = os.path.join(destination, db_file.new_name)
            path = os.path.join(destination, db_file.name)
            os.rename(oldpath, path)

            #TODO error handling
            path = os.path.join(db_file.destination, db_file.name)
            add(path, Session())
            paths += [path]
            session['messages'] += ["%s is commit" % db_file.name]
            session.save()
            s.delete(db_file)
            s.commit()

        commit(paths, message, session['user'], Session())

        return redirect_to(url_for(controller="moderation"))
Exemplo n.º 2
0
    def createdir(self):
        c.session = Session()
        media_dir = config['app_conf']['media_dir']

        path = unicode(request.params.get('path', None))
        if path is None:
            abort(404)

        check_dir = c.session.query(Dir).get(path)
        if check_dir is None:
            abort(404)

        create_dir = request.params.get('createdir', None)
        if create_dir is None:
            return redirect_to(
                url_for(controller="dir") + "?path=" + str(create_dir))

        #Can start with a single .  max len = 32
        #No space because I'm experimenting problems with the add function
        p = re.compile("^[A-Za-z0-9_.][A-Za-z0-9_]{0,31}$")
        if not p.match(create_dir):
            session['messages'] = ['Invalid subdirectory name']
            session.save()
            return redirect_to(
                url_for(controller="dir", action="create") + "?path=" +
                str(check_dir.path))

        if not check_dir.path == ".":
            create_dir = os.path.join(check_dir.path, create_dir)

        if c.session.query(Dir).get(create_dir) is None:
            message = "Dir : \'%s\' created" % create_dir
            os.mkdir(os.path.join(media_dir, create_dir))
            add(create_dir, Session())
            commit([create_dir], message, session['user'], Session())
            #Error handeling
        else:
            session['messages'] = ['Subdirectory already exist']
            session.save()
            return redirect_to(str('/dir/create?path=' + check_dir.path))

        return redirect_to(
            url_for(controller="dir") + "?path=" + str(create_dir))
Exemplo n.º 3
0
    def createdir(self):
        c.session = Session()
        media_dir = config['app_conf']['media_dir']

        path = unicode(request.params.get('path', None))
        if path is None:
            abort(404)

        check_dir = c.session.query(Dir).get(path)
        if check_dir is None:
            abort(404)

        create_dir = request.params.get('createdir', None)
        if create_dir is None:
            return redirect_to(url_for(controller="dir") + "?path=" + str(create_dir))

        #Can start with a single .  max len = 32
        #No space because I'm experimenting problems with the add function
        p = re.compile("^[A-Za-z0-9_.][A-Za-z0-9_]{0,31}$")
        if not p.match(create_dir):
            session['messages'] = ['Invalid subdirectory name']
            session.save()
            return redirect_to(url_for(controller="dir", action="create") + "?path=" + str(check_dir.path))

        if not check_dir.path == ".":
            create_dir =  os.path.join(check_dir.path, create_dir)

        if c.session.query(Dir).get(create_dir) is None:
            message = "Dir : \'%s\' created" % create_dir
            os.mkdir( os.path.join(media_dir, create_dir))
            add(create_dir, Session())
            commit([create_dir], message, session['user'], Session())
            #Error handeling
        else:
            session['messages'] = ['Subdirectory already exist']
            session.save()
            return redirect_to(str('/dir/create?path=' + check_dir.path))

        return redirect_to(url_for(controller="dir") + "?path=" + str(create_dir))
Exemplo n.º 4
0
    def commit(self):
        s = Session()
        session['messages'] = []
        paths = []

        message = request.params.get("message", "Web commit")
        db_files = s.query(Upload).filter(Upload.status == u"Moderated").all()
        for db_file in db_files:

            destination = get_path(None, db_file.destination)
            if destination == "Invalid path":
                session['messages'] += [
                    "Invalid destination for the file %s" % db_file.name
                ]
                session.save()
                return redirect_to(url_for(controller="moderation"))

            currentpath = os.path.join(get_path("moderation"),
                                       db_file.new_name)
            #os.sep is to fix a bug
            shutil.move(currentpath, destination + os.sep)

            oldpath = os.path.join(destination, db_file.new_name)
            path = os.path.join(destination, db_file.name)
            os.rename(oldpath, path)

            #TODO error handling
            path = os.path.join(db_file.destination, db_file.name)
            add(path, Session())
            paths += [path]
            session['messages'] += ["%s is commit" % db_file.name]
            session.save()
            s.delete(db_file)
            s.commit()

        commit(paths, message, session['user'], Session())

        return redirect_to(url_for(controller="moderation"))