def __init__(self): import cf perm_active = [] if cf.require_activation: perm_active = perm.edit ent_table.__init__(self, attributes = [ ('party', string(label.party, perm.all + ['delete'], '', 20)), ('username', string(label.username, perm.all + ['delete'], '', 10)), ('tourney', string(label.tourney, perm.all + ['delete', 'list'], '', 32)), # Editing the team must not be allowed, because the 'active' status # would remain unchanged. Also, the user may be leader of the # current team, which would not allow him to be a member of a # different team. The only legal way is to delete the entry # altogether and rejoin the other team. ('team', string(label.team, perm.submit, '', 32)), ('active', bool(label.active, perm_active, 0)) ], primary_keys = [ 'party', 'username', 'tourney' ], relations = [ relation( table = 'gamer', keys = { 'party': 'party', 'username': '******' }, # Users can only subscribe themselves. cond = { 'submit': "gamer.username = $userid", 'delete': "gamer.username = $userid OR " \ "$users.rank > 0" } ), relation( table = 'team', keys = { 'party': 'party', 'tourney': 'tourney', 'team': 'name' }, # Only the team leader can change member settings. # # NB: The 'team.name = team_members.team' condition can # not be handled as a join condition because 'team' is # not a primary key of 'team_members'. cond = { 'edit': "team.name = team_members.team AND " \ "team.leader = $userid" } ), relation( table = 'tourney', alias = 'tn', keys = { 'party': 'party', 'tourney': 'name' }, # Make sure tournament is in preparation phase. cond = { 'submit': "tn.phase = 1", 'edit': "tn.phase = 1", 'delete': "tn.phase = 1" } ), relation( table = 'users', keys = { 'username': '******' }, # Make sure user has paid. cond = { 'submit': "gamer.paid = TRUE OR users.rank > 0" } ), relation( table = 'team', alias = 'lt', keys = { 'party': 'party', 'tourney': 'tourney', 'username': '******' }, # Make sure user is not a leader of another team # already. cond = { 'submit': "lt.leader IS NULL OR team.name = lt.name" }, outer_join = "LEFT" ) ], item_txt = { 'edit': { 'en': 'Teammember Settings', 'de': 'Teammitglieder Einstellungen' }, 'submit': { 'en': 'Join Team', 'de': 'Team beitreten' }, 'view': { 'en': 'Teammembers', 'de': 'Teammitglieder' }, 'list': { 'en': 'Teammembers', 'de': 'Teammitglieder' } } )
def __init__(self): opt_bracket = [ { 'en': 'Winner' }, { 'en': 'Loser' } ] opt_status = [ { 'en': 'pending', 'de': 'l"auft' }, { 'en': 'Team 1 wins', 'de': 'Team 1 gewinnt' }, { 'en': 'Team 2 wins', 'de': 'Team 2 gewinnt' } ] from users import rank_check ent_table.__init__(self, attributes = [ ('party', string(label.party, perm.all, '', 20)), ('tourney', string(label.tourney, perm.all, '', 32)), ('round', attr_int(label.round, perm.edit)), ('stage', attr_int(label.stage, perm.edit)), ('bracket', choice(label.bracket, opt_bracket, perm.edit)), ('id', attr_int(label.id, perm.edit)), ('team1', string(label.team1, perm.view, '', 32)), ('team2', string(label.team2, perm.view, '', 32)), ('status', choice(label.status, opt_status, perm.edit)) ], primary_keys = [ 'party', 'tourney', 'round', 'stage', 'bracket', 'id' ], relations = [ relation( table = 'double_elimination', alias = 't1', keys = { 'party': 'party', 'tourney': 'tourney', 'round': 'round', 'stage': 'stage', 'bracket': 'bracket', 'id': 'id' }, # TODO: Is there a neater way to do this and can we get rid of the # nested SELECT? cond = { 'edit': "(t1.bracket = 1 AND (2*t1.round + t1.stage) = " \ "(SELECT MAX(2*t2.round + t2.stage) " \ "FROM double_elimination AS t2 " \ "WHERE t1.party = t2.party AND t1.tourney = t2.tourney " \ "AND t1.bracket = t2.bracket)) OR " \ "(t1.bracket = 0 AND (2*t1.round + t1.stage) = " \ "(SELECT MAX(2*t2.round + t2.stage) " \ "FROM double_elimination AS t2 " \ "WHERE t1.party = t2.party AND t1.tourney = t2.tourney " \ "AND t1.bracket = t2.bracket))" } ), relation( table = 'team', alias = 'tm1', keys = { 'party': 'party', 'tourney': 'tourney', 'team1': 'name' } ), relation( table = 'team', alias = 'tm2', keys = { 'party': 'party', 'tourney': 'tourney', 'team2': 'name' } ) ], perm = { 'edit': rank_check(self, 2), 'view': True }, item_txt = { 'edit': { 'en': 'Enter game results', 'de': 'Spielergebnisse eintragen' }, 'submit': { 'en': 'Add game', 'de': 'Spiel hinzuf"ugen' }, 'list': { 'en': 'Game results', 'de': 'Spielergebnisse' } } )