Esempio n. 1
0
 def post(self):
     slug_flag = self.get_argument('slug', False)
     if slug_flag:
         slug = self.get_argument('customslug', '')
     else:
         slug = helpers.get_slug(self.get_argument('title'),
             stop_words=options.slug_stop_words)
     html_content, plain_content = helpers.get_html_and_plain(
         self.get_argument('content'), self.get_argument('text_type'))
     post = {
         'title': self.get_argument('title'),
         'slug': slug,
         'date': datetime.datetime.now(),
         'tags': helpers.remove_duplicates(self.get_argument('tags')),
         'text_type': self.get_argument('text_type'),
         'content': self.get_argument('content'),
         'html_content': html_content,
         'plain_content': plain_content,
         'status': self.get_argument('status'),
         'text_type': self.get_argument('text_type'),
         'author': self.current_user['name'],
         'email': self.current_user['email'],
         'votes': 0,
         'views': 0
     }
     existing_post = self.db.posts.find_one({'slug': slug}, {'_id': 1})
     if existing_post:
         self.render('newpost.html', message=('There are already an '
             'existing post with this title or slug.'), post={}, new=True)
         return
     self.db.posts.insert(post)
     if post['status'] == 'published':
         self.redirect('/post/%s' % post['slug'])
     else:
         self.redirect('/')
 def post(self, slug):
     form = forms.PostForm(self.request.arguments,
         locale_code=self.locale.code, status_choices=opts.STATUSES,
         text_type_choices=opts.get_allowed_text_types())
     if form.validate():
         if form.data['custom_slug']:
             slug = form.data['slug']
         else:
             slug = helpers.get_slug(form.data['title'],
                 stop_words=options.slug_stop_words)
         html_content, plain_content = helpers.get_html_and_plain(
             form.data['content'], form.data['text_type'])
         post = form.data
         post.update({
             'slug': slug,
             'tags': helpers.remove_duplicates(form.data['tags']),
             'html_content': html_content,
             'plain_content': plain_content,
         })
         self.db.posts.update({'slug': slug}, {'$set': post})
         if post['status'] == 'published':
             self.redirect('/post/%s' % slug)
         else:
             self.redirect('/')
     else:
         self.render('editpost.html', message=form.errors, form=form)
Esempio n. 3
0
File: blog.py Progetto: iselu/selene
 def post(self):
     slug_flag = self.get_argument('slug', False)
     if slug_flag:
         slug = self.get_argument('customslug', '')
     else:
         slug = helpers.get_slug(self.get_argument('title'),
                                 stop_words=options.slug_stop_words)
     html_content, plain_content = helpers.get_html_and_plain(
         self.get_argument('content'), self.get_argument('text_type'))
     post = {
         'title': self.get_argument('title'),
         'slug': slug,
         'date': datetime.datetime.now(),
         'tags': helpers.remove_duplicates(self.get_argument('tags')),
         'text_type': self.get_argument('text_type'),
         'content': self.get_argument('content'),
         'html_content': html_content,
         'plain_content': plain_content,
         'status': self.get_argument('status'),
         'text_type': self.get_argument('text_type'),
         'author': self.current_user['name'],
         'email': self.current_user['email'],
         'votes': 0,
         'views': 0
     }
     existing_post = yield Op(self.db.posts.find_one, {'slug': slug},
                              {'_id': 1})
     if existing_post:
         self.render('newpost.html',
                     message=('There are already an '
                              'existing post with this title or slug.'),
                     post={},
                     new=True)
         return
     yield Op(self.db.posts.insert, post)
     if post['status'] == 'published':
         self.redirect('/post/%s' % post['slug'])
     else:
         self.render('newpost.html',
                     message=self.form.errors,
                     form=self.form)
Esempio n. 4
0
 def post(self, slug):
     slug_flag = self.get_argument('slug', False)
     if slug_flag:
         new_slug = self.get_argument('customslug', '')
     else:
         new_slug = helpers.get_slug(self.get_argument('title'),
             stop_words=options.slug_stop_words)
     html_content, plain_content = helpers.get_html_and_plain(
         self.get_argument('content'), self.get_argument('text_type'))
     new_post = {
         'title': self.get_argument('title'),
         'slug': new_slug,
         'tags': helpers.remove_duplicates(self.get_argument('tags')),
         'content': self.get_argument('content'),
         'html_content': html_content,
         'plain_content': plain_content,
         'status': self.get_argument('status'),
         'text_type': self.get_argument('text_type')
     }
     yield Op(self.db.posts.update, {'slug': slug}, {'$set': new_post})
     if new_post['status'] == 'published':
         self.redirect('/post/%s' % new_slug)
     else:
         self.render('editpost.html', message=form.errors, form=form)
Esempio n. 5
0
File: blog.py Progetto: iselu/selene
 def post(self, slug):
     slug_flag = self.get_argument('slug', False)
     if slug_flag:
         new_slug = self.get_argument('customslug', '')
     else:
         new_slug = helpers.get_slug(self.get_argument('title'),
                                     stop_words=options.slug_stop_words)
     html_content, plain_content = helpers.get_html_and_plain(
         self.get_argument('content'), self.get_argument('text_type'))
     new_post = {
         'title': self.get_argument('title'),
         'slug': new_slug,
         'tags': helpers.remove_duplicates(self.get_argument('tags')),
         'content': self.get_argument('content'),
         'html_content': html_content,
         'plain_content': plain_content,
         'status': self.get_argument('status'),
         'text_type': self.get_argument('text_type')
     }
     yield Op(self.db.posts.update, {'slug': slug}, {'$set': new_post})
     if new_post['status'] == 'published':
         self.redirect('/post/%s' % new_slug)
     else:
         self.render('editpost.html', message=form.errors, form=form)
 def post(self):
     form = forms.PostForm(self.request.arguments,
         locale_code=self.locale.code, status_choices=opts.STATUSES,
         text_type_choices=opts.get_allowed_text_types())
     if form.validate():
         if form.data['custom_slug']:
             slug = form.data['slug']
         else:
             slug = helpers.get_slug(form.data['title'],
                 stop_words=options.slug_stop_words)
         if self.db.posts.find_one({'slug': slug}, {'_id': 1}) or \
             slug.strip() == '':
             self.render('newpost.html',
                 message=constants.POST_IS_ALREADY_REGISTERED, form=form)
         else:
             html_content, plain_content = helpers.get_html_and_plain(
                 form.data['content'], form.data['text_type'])
             post = form.data
             post.update({
                 'slug': slug,
                 'date': datetime.datetime.now(),
                 'tags': helpers.remove_duplicates(form.data['tags']),
                 'html_content': html_content,
                 'plain_content': plain_content,
                 'author': self.current_user['full_name'],
                 'email': self.current_user['email'],
                 'votes': 0,
                 'views': 0
             })
             self.db.posts.insert(post)
             if post['status'] == 'published':
                 self.redirect('/post/%s' % post['slug'])
             else:
                 self.redirect('/')
     else:
         self.render('newpost.html', message=form.errors, form=form)