예제 #1
0
파일: forums.py 프로젝트: APilishenko/forum
class ForumsController(BaseController):
    @render
    def index(self):
        self.forums = Forum.query.all()

    @render
    def show(self):
        self.forum = Forum.query.get_or_404(self.params['forum_id'])

    @admin_required
    @render
    def new(self):
        self.form = getattr(self, 'form', None) or ForumForm()

    @admin_required
    @render
    def edit(self):
        self.forum = Forum.query.get_or_404(self.params['forum_id'])
        self.form = getattr(self, 'form', None) or ForumForm(obj=self.forum)

    @admin_required
    def create(self):
        self.form = ForumForm()
        if self.form.validate_on_submit():
            del self.form
            forum = Forum.create(user_id=self.current_user.id, **self._forum_params())
            return redirect(url_for('forums.show', forum_id=forum.id))
        else:
            return self.new()

    @admin_required
    def update(self):
        self.form = ForumForm()
        if self.form.validate_on_submit():
            del self.form
            forum = Forum.query.get_or_404(self.params['forum_id'])
            forum.update(**self._forum_params())
            return redirect(url_for('forums.show', forum_id=forum.id))
        else:
            return self.edit()

    @admin_required
    def destroy(self):
        forum = Forum.query.get_or_404(self.params['forum_id'])
        forum.delete()
        return redirect(url_for('forums.index'))

    def _forum_params(self):
        return self.permit(self.params, 'position', 'title')
예제 #2
0
파일: forums.py 프로젝트: APilishenko/forum
 def create(self):
     self.form = ForumForm()
     if self.form.validate_on_submit():
         del self.form
         forum = Forum.create(user_id=self.current_user.id, **self._forum_params())
         return redirect(url_for('forums.show', forum_id=forum.id))
     else:
         return self.new()
예제 #3
0
파일: forums.py 프로젝트: APilishenko/forum
 def update(self):
     self.form = ForumForm()
     if self.form.validate_on_submit():
         del self.form
         forum = Forum.query.get_or_404(self.params['forum_id'])
         forum.update(**self._forum_params())
         return redirect(url_for('forums.show', forum_id=forum.id))
     else:
         return self.edit()