@ -71,6 +71,17 @@ class OptionalIntField(wtforms.IntegerField):
except ValueError :
raise wtforms . ValidationError ( ' Nejedná se o číslo. ' )
def user_link ( user ) :
b = html . Builder ( )
with b . line ( ) :
if user is None :
b ( " - " )
else :
if g . org :
b . a ( href = app . url_for ( web_org_user . __name__ , user_id = user . id ) ) ( user . username )
else :
b ( user . username )
return b . root_tag
@ -169,10 +180,120 @@ def web_index():
b ( f " Váš token je: { g . user . token } " )
return b . print_file ( )
@app . route ( " /game/<int:game_id> " , methods = [ ' GET ' ] )
def web_game ( game_id ) :
ses = db . get_session ( )
game = ses . query ( db . Game ) . filter_by ( game_id = game_id ) . one_or_none ( )
teams = ses . query ( db . Team ) . filter_by ( game_id = game_id ) . order_by ( db . Team . team_id ) . all ( )
if game is None :
raise werkzeug . exceptions . NotFound ( )
b = BasePage ( )
with b . p ( ) . table ( _class = " data full " ) :
with b . thead ( ) :
b . line ( ) . th ( ) ( " Id " )
b . line ( ) . th ( ) ( " User " )
if g . org :
b . line ( ) . th ( ) ( " Akce " )
for team in teams :
with b . tr ( ) :
b . line ( ) . td ( ) ( team . team_id )
b . line ( ) . td ( ) ( user_link ( team . user ) , " : " , team . name )
if g . org :
with b . td ( ) :
with b . div ( _class = " btn-group " , role = " group " ) :
b . a ( _class = " btn btn-xs btn-primary " , href = app . url_for ( web_org_game_userchange . __name__ , game_id = game . game_id , team_id = team . team_id ) ) ( " Změnit uživatele " )
#b.a(_class="btn btn-xs btn-primary", href=app.url_for(web_game.__name__, game_id=g.game_id))("Detail")
return b . print_file ( )
@app . route ( " /org/games " )
def web_org_games ( ) :
games = db . get_session ( ) . query ( db . Game ) . order_by ( db . Game . game_id ) . all ( )
b = BasePage ( )
with b . p ( ) . table ( _class = " data full " ) :
with b . thead ( ) :
b . line ( ) . th ( ) ( " Id " )
b . line ( ) . th ( ) ( " Kolo " )
b . line ( ) . th ( ) ( " Akce " )
for g in games :
with b . tr ( ) :
b . line ( ) . td ( ) ( g . game_id )
with b . line ( ) . td ( ) :
if g . working_on_next_state :
b . b ( ) ( g . current_round , " ++ " )
else :
b ( g . current_round )
with b . td ( ) :
b . a ( _class = " btn btn-xs btn-primary " , href = app . url_for ( web_game . __name__ , game_id = g . game_id ) ) ( " Detail " )
return b . print_file ( )
class GameUserchangeForm ( FlaskForm ) :
name = StringField ( " Jméno hry z pohledu týmu " )
set_no_user = SubmitField ( " Bez uživatele " )
submit_no_change = wtforms . SubmitField ( " Bez změny " , render_kw = { " style " : " display: none " } )
@app . route ( " /org/game/<int:game_id>/team/<int:team_id>/change_user " , methods = [ ' GET ' , ' POST ' ] )
def web_org_game_userchange ( game_id , team_id ) :
ses = db . get_session ( )
game = ses . query ( db . Game ) . filter_by ( game_id = game_id ) . one_or_none ( )
team_to_edit = ses . query ( db . Team ) . filter_by ( game_id = game_id , team_id = team_id ) . one_or_none ( )
teams = ses . query ( db . Team ) . filter_by ( game_id = game_id ) . order_by ( db . Team . team_id ) . all ( )
users = db . get_session ( ) . query ( db . User ) . order_by ( db . User . id ) . all ( )
if game is None or team_to_edit is None :
raise werkzeug . exceptions . NotFound ( )
teams_by_user = { u . id : [ ] for u in users }
for t in teams :
if t . user_id is not None :
teams_by_user [ t . user_id ] . append ( t )
form = GameUserchangeForm ( obj = team_to_edit )
if form . validate_on_submit ( ) :
team_to_edit . name = form . name . data
if " submit_no_change " not in request . form :
team_to_edit . user_id = None
for u in users :
if f " set_user_ { u . id } " in request . form :
team_to_edit . user_id = u . id
try :
ses . commit ( )
except exc . IntegrityError :
flash ( " Duplicitní přiřazení " , ' danger ' )
ses . rollback ( )
else :
flash ( " Uživatel změněn " , ' success ' )
return redirect ( app . url_for ( web_game . __name__ , game_id = game_id ) )
b = BasePage ( )
with b . form ( action = " " , method = " POST " , _class = " form form-horizontal " , role = " form " ) :
b ( form . csrf_token )
b ( form . submit_no_change )
with b . div ( _class = " form-row " ) :
b ( jinja_mac . form_field ( form . name , size = 8 ) )
with b . p ( ) . table ( _class = " data full " ) :
with b . thead ( ) :
b . line ( ) . th ( ) ( " Username " )
b . line ( ) . th ( ) ( " Přiřazení " )
b . line ( ) . th ( ) ( " Akce " )
for u in users :
with b . tr ( ) :
b . line ( ) . td ( user_link ( u ) )
with b . td ( ) :
if len ( teams_by_user [ u . id ] ) :
with b . ul ( ) :
for t in teams_by_user [ u . id ] :
b . li ( f " { t . team_id } -> { t . name } " )
b . line ( ) . td ( ) . input ( _class = " btn btn-danger " if u . id == team_to_edit . user_id else " btn btn-primary " , _id = " set_participation_state " , name = f " set_user_ { u . id } " , type = " submit " , value = " Nastavit stav účasti " )
b ( jinja_mac . form_field ( form . set_no_user ) )
return b . print_file ( )
@app . route ( " /org/users " )
def web_users ( ) :
users = db . get_session ( ) . query ( db . User ) . all ( )
def web_org_ users ( ) :
users = db . get_session ( ) . query ( db . User ) . order_by ( db . User . id ) . all ( )
b = BasePage ( )
with b . p ( ) . table ( _class = " data full " ) :
with b . thead ( ) :
@ -181,9 +302,10 @@ def web_users():
b . line ( ) . th ( ) ( " Akce " )
for u in users :
with b . tr ( ) :
b . line ( ) . th ( ) ( u . username )
b . line ( ) . th ( )
with b . th ( ) :
b . line ( ) . td ( ) ( u . username )
b . line ( ) . td ( )
with b . td ( ) :
with b . div ( _class = " btn-group " , role = " group " ) :
b . a ( _class = " btn btn-xs btn-primary " , href = app . url_for ( web_org_user . __name__ , user_id = u . id ) ) ( " Detail " )
return b . print_file ( )