示例#1
0
文件: views.py 项目: Zicky/myblog
def modify_post(msg, post):
    modified = False
    if post.title != msg['title']:
        post.title = msg['title']
        modified = True
    if post.content != msg['content']:
        post.content = msg['content']
        if post.content_format != msg['content_format']:
            post.content_format = msg['content_format']
        post.content_html = dump_html(post.content, post.content_format)
        modified = True
    if post.content_format != msg['content_format']:
        post.content_format = msg['content_format']
        post.content_html = dump_html(post.content, post.content_format)
        modified = True
    if msg.has_key("tags"):
        for etag in post.tags.all():
            found = False
            for tag in msg['tags']:
                if tag == etag.tag:
                    found = True
                    break
            if not found:
                post.tags.remove(etag)
                etag.nr_refs -= 1
                if etag.nr_refs == 0:
                    etag.delete()
                else:
                    etag.save()
                modified = True
        for tag in msg['tags']:
            found = False
            for etag in post.tags.all():
                if tag == etag.tag:
                    found = True
                    break
            if not found:
                t = get_tag(tag)
                t.nr_refs += 1
                t.save()
                post.tags.add(t)
                modified = True
    if modified:
        post.modified = datetime.datetime.now()
    return post
示例#2
0
def modify_post(msg, post):
    modified = False
    if post.title != msg['title']:
        post.title = msg['title']
        modified = True
    if post.content != msg['content']:
        post.content = msg['content']
        if post.content_format != msg['content_format']:
            post.content_format = msg['content_format']
        post.content_html = dump_html(post.content, post.content_format)
        modified = True
    if post.content_format != msg['content_format']:
        post.content_format = msg['content_format']
        post.content_html = dump_html(post.content, post.content_format)
        modified = True
    if msg.has_key("tags"):
        for etag in post.tags.all():
            found = False
            for tag in msg['tags']:
                if tag == etag.tag:
                    found = True
                    break
            if not found:
                post.tags.remove(etag)
                etag.nr_refs -= 1
                if etag.nr_refs == 0:
                    etag.delete()
                else:
                    etag.save()
                modified = True
        for tag in msg['tags']:
            found = False
            for etag in post.tags.all():
                if tag == etag.tag:
                    found = True
                    break
            if not found:
                t = get_tag(tag)
                t.nr_refs += 1
                t.save()
                post.tags.add(t)
                modified = True
    if modified:
        post.modified = datetime.datetime.now()
    return post
示例#3
0
 def save(self, *args, **kwargs):
     if len(self.uuid) == 0:
         self.uuid = uuid.uuid4().hex
     if len(self.slug) == 0:
         self.slug = self.uuid
     if len(self.title) == 0 or len(self.content) == 0:
         return
     if len(self.content_html) == 0:
         self.content_html = dump_html(self.content, self.content_format)
     ch = self.content_html
     #self.abstract = ch[ch.find("<p>"):ch.find("</p>")]
     subtitleidx = ch.find("<h3")
     if subtitleidx <= 0:
         subtitleidx = len(ch)
     self.abstract = ch[:subtitleidx]
     super(Post, self).save(*args, **kwargs)
示例#4
0
文件: models.py 项目: Zicky/myblog
 def save(self, *args, **kwargs):
     if len(self.uuid) == 0:
         self.uuid = uuid.uuid4().hex
     if len(self.slug) == 0:
         self.slug = self.uuid
     if len(self.title) == 0 or len(self.content) == 0:
         return
     if len(self.content_html) == 0:
         self.content_html = dump_html(self.content, self.content_format)
     ch = self.content_html
     #self.abstract = ch[ch.find("<p>"):ch.find("</p>")]
     subtitleidx = ch.find("<h3")
     if subtitleidx <= 0:
         subtitleidx = len(ch)
     self.abstract = ch[:subtitleidx]
     super(Post, self).save(*args, **kwargs)
示例#5
0
文件: views.py 项目: Zicky/myblog
def get_post(msg, create=False):
    slug = msg['slug']
    language = ""
    if msg.has_key('language'):
        language = msg['language']
    post = None
    if language:
        post = Post.objects.filter(slug=slug, language=language)
    else:
        post = Post.objects.filter(slug=slug)
    if len(post) > 0:
        return post
    if not create:
        return None
    title = msg['title']
    content = msg['content']
    content_format = msg['content_format']
    language = msg['language']

    content_html = dump_html(content, content_format)
    now = datetime.datetime.now()
    allow_comment = True
    if msg.has_key('allow_comment'):
        allow_comment = bool(msg['allow_comment'])
    post = Post(title=title, \
            author=msg['author'],   \
            slug=slug,  \
            created=now,    \
            modified=now,   \
            content_format=content_format,  \
            content=content,    \
            content_html=content_html,  \
            view_count=0,   \
            language=language,  \
            uuid="",    \
            allow_comment=allow_comment)
    post.save()
    if msg.has_key("tags"):
        for tag in msg['tags']:
            t = get_tag(tag)
            t.nr_refs += 1
            t.save()
            post.tags.add(t)
    return [post]
示例#6
0
def get_post(msg, create=False):
    slug = msg['slug']
    language = ""
    if msg.has_key('language'):
        language = msg['language']
    post = None
    if language:
        post = Post.objects.filter(slug=slug, language=language)
    else:
        post = Post.objects.filter(slug=slug)
    if len(post) > 0:
        return post
    if not create:
        return None
    title = msg['title']
    content = msg['content']
    content_format = msg['content_format']
    language = msg['language']

    content_html = dump_html(content, content_format)
    now = datetime.datetime.now()
    allow_comment = True
    if msg.has_key('allow_comment'):
        allow_comment = bool(msg['allow_comment'])
    post = Post(title=title, \
            author=msg['author'],   \
            slug=slug,  \
            created=now,    \
            modified=now,   \
            content_format=content_format,  \
            content=content,    \
            content_html=content_html,  \
            view_count=0,   \
            language=language,  \
            uuid="",    \
            allow_comment=allow_comment)
    post.save()
    if msg.has_key("tags"):
        for tag in msg['tags']:
            t = get_tag(tag)
            t.nr_refs += 1
            t.save()
            post.tags.add(t)
    return [post]
示例#7
0
 def save(self, *args, **kwargs):
     if self.content == '' or self.content_format == '':
         return
     self.content_html = dump_html(self.content, self.content_format)
     super(Sidebar, self).save(*args, **kwargs)
示例#8
0
文件: models.py 项目: Zicky/myblog
 def save(self, *args, **kwargs):
     if self.content == '' or self.content_format == '':
         return
     self.content_html = dump_html(self.content, self.content_format)
     super(Sidebar, self).save(*args, **kwargs)