Ejemplo n.º 1
0
 def handle_request(self, *args, **kwargs):
     action_text = 'Create'
     action_url = url_for('league_create')
     form = LeagueForm()
     if form.validate_on_submit():
         league = League(form.name.data, current_user)
         membership = Membership(current_user, league, owner=True)
         db.session.add(league)
         db.session.add(membership)
         db.session.commit()
         return redirect(url_for('league', lid=league.id))
     else:
         return render_template('league-edit.html', form=form, action_text=action_text, action_url=action_url,
                                **self.context)
Ejemplo n.º 2
0
 def handle_request(self, lid, *args, **kwargs):
     action_text = 'Save'
     action_url = url_for('league_edit', lid=lid)
     league = League.query.filter_by(id=lid).first()
     if league is None:
         abort(404)
     if not league.editable_by_user(current_user):
         abort(403)
     form = LeagueForm(obj=league)
     if form.validate_on_submit():
         league.name = form.name.data
         db.session.commit()
         return redirect(url_for('league', lid=league.id))
     else:
         return render_template('league-edit.html', form=form, action_url=action_url, action_text=action_text,
                                **self.context)