<s> from flask import Blueprint , request , g <EOL> from flask import render_template , redirect , url_for , abort <EOL> from . . models import Node , NodeStatus , Topic , fill_topics <EOL> from . . forms import NodeForm <EOL> from . . helpers import force_int <EOL> from . . utils . user import require_staff <EOL> __all__ = [ '<STR_LIT>' ] <EOL> bp = Blueprint ( '<STR_LIT>' , __name__ ) <EOL> @ bp . route ( '<STR_LIT:/>' ) <EOL> def nodes ( ) : <EOL> """<STR_LIT>""" <EOL> nodes = Node . query . order_by ( Node . updated . desc ( ) ) . all ( ) <EOL> return render_template ( '<STR_LIT>' , nodes = nodes ) <EOL> @ bp . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ require_staff <EOL> def create ( ) : <EOL> """<STR_LIT>""" <EOL> form = NodeForm ( ) <EOL> if form . validate_on_submit ( ) : <EOL> node = form . save ( ) <EOL> return redirect ( url_for ( '<STR_LIT>' , urlname = node . urlname ) ) <EOL> return render_template ( '<STR_LIT>' , form = form ) <EOL> @ bp . route ( '<STR_LIT>' ) <EOL> def view ( urlname ) : <EOL> """<STR_LIT>""" <EOL> node = Node . query . filter_by ( urlname = urlname ) . first_or_404 ( ) <EOL> page = force_int ( request . args . get ( '<STR_LIT>' , <NUM_LIT:1> ) , <NUM_LIT:0> ) <EOL> if not page : <EOL> return abort ( <NUM_LIT> ) <EOL> paginator = Topic . query . filter_by ( <EOL> node_id = node . id ) . order_by ( Topic . id . desc ( ) ) . paginate ( page ) <EOL> paginator . items = fill_topics ( paginator . items ) <EOL> status = None <EOL> if g . user : <EOL> status = NodeStatus . query . filter_by ( <EOL> account_id = g . user . id , node_id = node . id <EOL> ) . first ( ) <EOL> return render_template ( <EOL> '<STR_LIT>' , node = node , paginator = paginator , status = status <EOL> ) <EOL> @ bp . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> @ require_staff <EOL> def edit ( urlname ) : <EOL> """<STR_LIT>""" <EOL> node = Node . query . filter_by ( urlname = urlname ) . first_or_404 ( ) <EOL> form = NodeForm ( obj = node ) <EOL> if form . validate_on_submit ( ) : <EOL> form . populate_obj ( node ) <EOL> node . save ( ) <EOL> return redirect ( url_for ( '<STR_LIT>' , urlname = node . urlname ) ) <EOL> return render_template ( '<STR_LIT>' , form = form , node = node ) </s>
