Beispiel #1
0
 def create_category(name, diary = None):
     '''
     创建分类
     '''
     category = Category.get_item('name', name)
     if category != None:
         return None
     else:
         if diary:
             category = Category(name = name, create_time = utils.cn_now(), diaries = 1, diary_list = [diary.get_id()])
         else:
             category = Category(name = name, create_time = utils.cn_now(), diaries = 0, diary_list = [])
         category.save()
         return category
Beispiel #2
0
 def create_message(author, content, content_rendered):
     '''
     创建留言
     '''
     guestmessage = GuestMessage(author = author, create_time = utils.cn_now(), content = content, content_rendered = content_rendered)
     guestmessage.save()
     author = User.get_item('ID', guestmessage.author.get_id())
     author.message_list.append(guestmessage.get_id())
     author.save()
     return guestmessage
Beispiel #3
0
 def create_tag(name, diary):
     '''
     创建标签
     '''
     tag = Tag.get_item('name', name)
     if tag != None:
         return None
     else:
         tag = Tag(name = name, create_time = utils.cn_now(), diaries = 1, diary_list = [diary.get_id()])
         tag.save()
Beispiel #4
0
 def create_comment(author, content, content_rendered, posted, diary):
     '''
     添加评论
     '''
     comment = Comment(author = author, create_time = utils.cn_now(), content = content, content_rendered = content_rendered, posted = posted, diary = diary)
     comment.save()
     author = User.get_item('ID', comment.author.get_id())
     author.comment_list.append(comment.get_id())
     author.save()
     diary.comment_list.append(comment.get_id())
     diary.comments += 1
     diary.save()
     return comment
Beispiel #5
0
 def create_user(name, password, email, permission = 0, homepage = None):
     '''
     创建用户
     '''
     u = User.get_item('name', name)
     if u != None:
         return None
     create_time = utils.cn_now()            # 获取中国当前时间
     password_hashed = User.hash_password(password, create_time)
     u = User(name = name, password = password_hashed, email = email, create_time = create_time, permission = int(permission))
     u.homepage = homepage
     u.save()
     return u
Beispiel #6
0
    def create_diary(title, author, content, content_rendered, render_type, category, url, tags = [], posted = False, other_content = ''):
        '''
        创建日志
        '''
        diary = Diary.get_item('url', url)
        if diary != None:
            return None
        create_time = utils.cn_now()
        if not url:
            # 如果未指定URL,使用Title作为URL
            url = title
        diary = Diary(
            title = title,
            author = author,
            year = create_time.year,
            month = create_time.month,
            day = create_time.day,
            content = content,
            content_rendered = content_rendered,
            create_time = create_time,
            render_type = 'markdown',
            creads = 0,
            comments = 0,
            comment_list = [],
            url = url,
            category = category,
            tags = tags,
            posted = posted,
            other_content = other_content
            )
        diary.save()
        old_category = Category.get_item('name', category)
        if old_category != None:
            # 如果该日志分类为已存在分类,则将当前日志添加到该分类中去
            old_category.add_diary(diary)
        else:
            # 否则添加新分类
            Category.create_category(category, diary)

        # 标签做同上处理
        for tag in tags:
            old_tag = Tag.get_item('name', tag)
            if old_tag != None:
                old_tag.add_diary(diary)
            else:
                Tag.create_tag(tag, diary)
        return diary