Esempio n. 1
0
 def _create_or_edit(self, entry_key, status):
     title, slug, markdown, author, kind_name, reference = self.get_argument('title'), \
         self.get_argument('slug', ''), \
         self.get_argument('content', strip=False), \
         self.get_argument('author', None), \
         self.get_argument('kind_name', None), \
         self.get_argument('reference', None)
     # Check title and markdown is empty.
     if not (title and markdown):
         raise SaveException('标题或者内容为空!')
     if not slug:
         slug = title
     slug = Entry.check_slug(slug, entry_key)
     if slug==None:
         raise SlugException('该 Slug 已经存在!')
     now = get_now()
     if entry_key:
         entry = db.get(entry_key)
         if entry.entry_kind.name != 'blog':
             if not author:
                 raise Exception('作者未知!')
             entry.author = author
         entry.title = title
         entry.slug = slug
         entry.markdown = markdown
         entry.html = Entry.convert(markdown)
         entry.abstract = self._process_abstract(markdown)
         if entry.status == 'draft':
             entry.published = now
         else:
             entry.updated = now
         entry.status = status
     else:
         if kind_name not in KINDS:
             raise Exception('非法类型文章!')
         if kind_name == 'blog':
             author = self.current_user.nickname()
         if not author:
             raise Exception('作者未知!')
         entry = Entry(
             entry_kind = KINDS.get(kind_name),
             author = author or self.current_user.nickname(),
             reference = reference,
             title = title,
             slug = slug,
             markdown = markdown,
             html = Entry.convert(markdown),
             abstract = self._process_abstract(markdown),
             status = status,
             published = now
         )
     entry.put()
     return entry
Esempio n. 2
0
 def post(self):
     markdown = self.get_argument('markdown', '', strip=False)
     self.write(Entry.convert(markdown))
Esempio n. 3
0
 def _process_abstract(self, markdown, char_count=500):
     markdown = markdown[:char_count]
     return Entry.convert('%s ...' % markdown.rstrip())