Esempio n. 1
0
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')
Esempio n. 2
0
 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()
Esempio n. 3
0
 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()