예제 #1
0
def filedelete(filename):
    try:
        functions.delete_filename(filename)
        return json({'success':True, 'message':'Delete success.'})
    except Exception as e:
        log.exception(e)
        return json({'success':False, 'message':'Delete file error'})
예제 #2
0
파일: views.py 프로젝트: qq40660/forum2
 def remove_topic(self, forum_id, topic_id):
     from sqlalchemy.sql import select
     
     Forum = get_model('forum')
     forum = Forum.get(int(forum_id))
     Topic = get_model('forumtopic')
     topic = Topic.get(int(topic_id))
     Post = get_model('forumpost')
     post = Post.get((Post.c.topic==int(topic_id)) & (Post.c.floor==1))
     FA = get_model('forumattachment')
     
     if not topic:
         error("主题不存在")
         
     is_manager = post.topic.forum.managers.has(request.user)
     if is_manager:
         query = FA.filter(FA.c.slug==Post.c.slug).filter(Post.c.topic==int(topic_id))
         #删除相应附件
         for a in query:
             functions.delete_filename(a.file_name)
         #删除FA记录
         FA.filter(FA.c.slug.in_(select([Post.c.slug], Post.c.topic==int(topic_id)))).remove()
         #删除所有POST
         post_query = Post.filter(Post.c.topic==int(topic_id))
         post_count = post_query.count()
         post_query.remove()
         Topic.get(int(topic_id)).delete()
         Forum.filter(Forum.c.id==int(forum_id)).update(num_posts=Forum.c.num_posts-post_count, num_topics=Forum.c.num_topics-1)
         flash('删除成功!')
         return redirect(url_for(ForumView.forum_index, id=forum_id))
     else:
         flash('你无权限删除主题!')
         return redirect(url_for(ForumView.topic_view, forum_id=forum_id, topic_id=topic_id))
예제 #3
0
    def deleteimage(self, id):
        """
        删除图片
        :param id:图片id
        """
        from uliweb.utils.image import fix_filename

        File = get_model('tutorials_albums')
        obj = File.get(int(id))
        if obj:
            thumbnail_filename = fix_filename(obj.filename, '.thumbnail')
            functions.delete_filename(thumbnail_filename)
            functions.delete_filename(obj.filename)
            obj.delete()
            return json({'success':True, 'message':'删除成功'})
        else:
            return json({'success':False, 'message':'图片没找到'})
예제 #4
0
    def deleteimage(self, id):
        """
        删除图片
        :param id:图片id
        """
        from uliweb.utils.image import fix_filename

        File = get_model('tutorials_albums')
        obj = File.get(int(id))
        if obj:
            thumbnail_filename = fix_filename(obj.filename, '.thumbnail')
            functions.delete_filename(thumbnail_filename)
            functions.delete_filename(obj.filename)
            obj.delete()
            return json({'success': True, 'message': '删除成功'})
        else:
            return json({'success': False, 'message': '图片没找到'})
예제 #5
0
    def remove_topic(self, forum_id, topic_id):
        from sqlalchemy.sql import select

        Forum = get_model('forum')
        forum = Forum.get(int(forum_id))
        Topic = get_model('forumtopic')
        topic = Topic.get(int(topic_id))
        Post = get_model('forumpost')
        post = Post.get((Post.c.topic == int(topic_id)) & (Post.c.floor == 1))
        FA = get_model('forumattachment')

        if not topic:
            error("主题已经不存在的")

        is_manager = post.topic.forum.managers.has(request.user)
        if is_manager:
            query = FA.filter(FA.c.slug == Post.c.slug).filter(
                Post.c.topic == int(topic_id))
            #删除相应附件
            for a in query:
                functions.delete_filename(a.file_name)
            #删除FA记录
            FA.filter(
                FA.c.slug.in_(
                    select([Post.c.slug],
                           Post.c.topic == int(topic_id)))).remove()
            #删除所有POST
            post_query = Post.filter(Post.c.topic == int(topic_id))
            post_count = post_query.count()
            post_query.remove()
            Topic.get(int(topic_id)).delete()
            Forum.filter(Forum.c.id == int(forum_id)).update(
                num_posts=Forum.c.num_posts - post_count,
                num_topics=Forum.c.num_topics - 1)
            flash('删除成功!')
            return redirect(url_for(ForumView.forum_index, id=forum_id))
        else:
            flash('你无权限删除主题!')
            return redirect(
                url_for(ForumView.topic_view,
                        forum_id=forum_id,
                        topic_id=topic_id))
예제 #6
0
def deletefile():
    filename = request.GET.get('filename')
    if filename:
        functions.delete_filename(filename)
    return redirect(url_for(index))
예제 #7
0
def deletefile():
    filename = request.GET.get('filename')
    if filename:
        functions.delete_filename(filename)
    return redirect(url_for(index))
예제 #8
0
파일: models.py 프로젝트: limodou/plugs
 def delete_files(cls, obj):
     for row in cls.content_object.filter(obj):
         try:
             functions.delete_filename(row.filepath)
         except:
             log.exception("Can't delete file %s" % row.filepath)