Exemplo n.º 1
0
 def post(self):
     form = PostAddForm(self)
     form.parent.query = self.db.query(Post).filter(
         Post.status == 'enabled').filter(Post.type == 'page').order_by(
             Post.title)
     if form.validate():
         title = form.title.data
         datetime_now = GetDatetimeFromDatenow(form.date.data)
         content = form.content.data
         parent = form.parent.data.id if form.parent.data else 0
         new_tags = []
         try:
             new_tags = self.request.arguments['new_tags'][0].split(',')
         except:
             pass
         post_categorys = self.request.arguments['post_category[]']
         post = Post(title=title,
                     content=content,
                     parent=parent,
                     author=self.current_user.id,
                     status='enabled',
                     authorname=self.current_user.displayname,
                     type='post',
                     date=datetime_now,
                     comment_count=0)
         self.db.add(post)
         self.db.commit()
         self.bind_tags(new_tags, post.id)
         self.bind_category(post_categorys, post.id)
         return self.redirect('/admin/post/list')
     return self.render("admin/post_add.html",
                        form=form,
                        setting=self.options)
Exemplo n.º 2
0
 def post(self, pid):
     form = PostAddForm(self)
     current = self.db.query(Post).get(pid)
     current_terms = self.db.query(Term).join(Term_Relationship,Term.id==Term_Relationship.term_id).filter(Term_Relationship.post_id==pid).distinct().all()
     current_tags = [term.name for term in current_terms if term.taxonomy=='post_tag']
     current_tags_str = ",".join(current_tags)
     current_categorys = [str(term.id) for term in current_terms if term.taxonomy=='category']
     current_categorys_str = ",".join(current_categorys)
     form.parent.query = self.db.query(Post).filter(Post.status=='enabled').filter(Post.type=='page').order_by(Post.title)
     if form.validate():
         title = form.title.data
         content = form.content.data
         parent = form.parent.data.id if form.parent.data else 0
         new_tags =[]
         try:
             new_tags = self.request.arguments['new_tags'][0].split(',')
         except:
             pass
         post_categorys = self.request.arguments['post_category[]']
         # update the tags and categorys relationship
         self.bindHander_tags(new_tags, current.id, current_tags)
         self.bindHander_categorys(post_categorys, current.id, current_categorys)
         # update the current Post
         current.title = title
         current.content = content
         current.parent = parent
         current.author = self.current_user.id
         if current.date.date() != form.date.data:
             current.date = GetDatetimeFromDatenow(form.date.data,current.date)
         self.db.commit()
         return self.redirect('/admin/post/list')
     return self.render('admin/post_edit.html', form=form, current=current, current_tags=current_tags_str, current_categorys=current_categorys_str, setting=self.options)
Exemplo n.º 3
0
 def post(self):
     form = PostAddForm(self)
     form.parent.query = self.db.query(Post).filter(Post.status=='enabled').filter(Post.type=='page').order_by(Post.title)
     if form.validate():
         title = form.title.data
         datetime_now = GetDatetimeFromDatenow(form.date.data)
         content = form.content.data
         parent = form.parent.data.id if form.parent.data else 0
         new_tags =[]
         try:
             new_tags = self.request.arguments['new_tags'][0].split(',')
         except:
             pass
         post_categorys = self.request.arguments['post_category[]']
         post = Post(title=title, content=content, parent=parent, 
                     author=self.current_user.id, status='enabled', 
                     authorname=self.current_user.displayname,
                     type='post', date=datetime_now,
                     comment_count=0)
         self.db.add(post)
         self.db.commit()
         self.bind_tags(new_tags, post.id)
         self.bind_category(post_categorys, post.id)
         return self.redirect('/admin/post/list')
     return self.render("admin/post_add.html", form=form, setting=self.options)
Exemplo n.º 4
0
 def post(self, pid):
     form = PostAddForm(self)
     current = self.db.query(Post).get(pid)
     current_terms = self.db.query(Term).join(
         Term_Relationship, Term.id == Term_Relationship.term_id).filter(
             Term_Relationship.post_id == pid).distinct().all()
     current_tags = [
         term.name for term in current_terms if term.taxonomy == 'post_tag'
     ]
     current_tags_str = ",".join(current_tags)
     current_categorys = [
         str(term.id) for term in current_terms
         if term.taxonomy == 'category'
     ]
     current_categorys_str = ",".join(current_categorys)
     form.parent.query = self.db.query(Post).filter(
         Post.status == 'enabled').filter(Post.type == 'page').order_by(
             Post.title)
     if form.validate():
         title = form.title.data
         content = form.content.data
         parent = form.parent.data.id if form.parent.data else 0
         new_tags = []
         try:
             new_tags = self.request.arguments['new_tags'][0].split(',')
         except:
             pass
         post_categorys = self.request.arguments['post_category[]']
         # update the tags and categorys relationship
         self.bindHander_tags(new_tags, current.id, current_tags)
         self.bindHander_categorys(post_categorys, current.id,
                                   current_categorys)
         # update the current Post
         current.title = title
         current.content = content
         current.parent = parent
         current.author = self.current_user.id
         if current.date.date() != form.date.data:
             current.date = GetDatetimeFromDatenow(form.date.data,
                                                   current.date)
         self.db.commit()
         return self.redirect('/admin/post/list')
     return self.render('admin/post_edit.html',
                        form=form,
                        current=current,
                        current_tags=current_tags_str,
                        current_categorys=current_categorys_str,
                        setting=self.options)
Exemplo n.º 5
0
 def get(self, pid):
     form = PostAddForm(self)
     current = self.db.query(Post).get(pid)
     current_terms = self.db.query(Term).join(
         Term_Relationship, Term.id == Term_Relationship.term_id).filter(
             Term_Relationship.post_id == pid).distinct().all()
     current_tags = [
         term.name for term in current_terms if term.taxonomy == 'post_tag'
     ]
     current_tags_str = ",".join(current_tags)
     current_categorys = [
         str(term.id) for term in current_terms
         if term.taxonomy == 'category'
     ]
     current_categorys_str = ",".join(current_categorys)
     form.title.process_data(current.title)
     form.content.process_data(current.content)
     form.date.process_data(current.date.date())
     form.parent.process_data(self.db.query(Post).get(current.parent))
     form.parent.query = self.db.query(Post).filter(
         Post.status == 'enabled').filter(Post.type == 'page').order_by(
             Post.title)
     return self.render('admin/post_edit.html',
                        form=form,
                        current=current,
                        current_tags=current_tags_str,
                        current_categorys=current_categorys_str,
                        setting=self.options)
Exemplo n.º 6
0
 def get(self):
     form = PostAddForm(self)
     form.date.process_data(datetime.date.today())
     form.parent.query = self.db.query(Post).filter(
         Post.status == 'enabled').filter(Post.type == 'page').order_by(
             Post.title)
     return self.render('admin/post_add.html',
                        form=form,
                        setting=self.options)