# Path: whyattend/model.py
# def init_db():
#     def __init__(self, wot_id, openid, member_since, name, clan, role, locked=False):
#     def is_recruit(self):
#     def battles_played(self):
#     def battles_reserve(self):
#     def __repr__(self):
#     def to_dict(self):
#     def player_role_value(self):
#     def __init__(self, player, battle, reserve=False):
#     def __init__(self, date, clan, enemy_clan, victory, draw, creator, battle_commander, map_name, map_province,
#                  duration, description='', paid=False):
#     def outcome_str(self):
#     def outcome_repr(self):
#     def has_player(self, player):
#     def has_reserve(self, player):
#     def get_players(self):
#     def get_reserve_players(self):
#     def __str__(self):
#     def __init__(self, title, description, clan, date):
#     def get_players(self):
#     def get_reserves(self):
#     def get_final_battle(self):
#     def get_representative_battle(self):
#     def __init__(self, replay_blob, replay_pickle):
#     def unpickle(self):
#     def get(cls):
# class Player(Base):
# class BattleAttendance(Base):
# class Battle(Base):
# class BattleGroup(Base):
# class Replay(Base):
# class WebappData(Base):


import csv
import datetime
import os
import pickle
import logging
import hashlib
import tarfile
import calendar
import jinja2
    import calendar
    import hashlib
from cStringIO import StringIO
from collections import defaultdict, OrderedDict
from functools import wraps
from datetime import timedelta
from flask import Flask, g, session, render_template, flash, redirect, request, url_for, abort, make_response, jsonify
from flask import Response
from flask_openid import OpenID
from flask_cache import Cache
from sqlalchemy import or_, and_, alias
from sqlalchemy.orm import joinedload, joinedload_all
from werkzeug.utils import secure_filename, Headers
from pytz import timezone
from . import config, replays, wotapi, util, constants, analysis
from .model import Player, Battle, BattleAttendance, Replay, BattleGroup, db_session, WebappData
    from logging.handlers import RotatingFileHandler
    from logging.handlers import RotatingFileHandler
    from sqlalchemy import case, desc, asc, select, func, literal
    from datetime import timedelta
                    return redirect(url_for('battle_details', battle_id=battle.id))

            r = Replay(replay_blob, pickle.dumps(replay))
            r.associated_battle = battle
            r.player_name = replay['first']['playerName']
            db_session.commit()

    return redirect(url_for('battle_details', battle_id=battle.id))


@app.route('/battles/edit/<int:battle_id>', methods=['GET', 'POST'])
@require_login
@require_role(roles=config.CREATE_BATTLE_ROLES)
def edit_battle(battle_id):
    """
        Edit battle form.
    :param battle_id:
    :return:
    """
    battle = Battle.query.get(battle_id) or abort(404)
    if battle.clan != g.player.clan and g.player.name not in config.ADMINS:
        abort(403)

    all_players = Player.query.filter_by(clan=g.player.clan, locked=False).order_by('lower(name)').all()
    sorted_players = sorted(all_players, reverse=True, key=lambda p: p.player_role_value())
    date = battle.date
    map_name = battle.map_name
    province = battle.map_province
    battle_commander = battle.battle_commander
    enemy_clan = battle.enemy_clan

# Path: whyattend/model.py
# def init_db():
#     def __init__(self, wot_id, openid, member_since, name, clan, role, locked=False):
#     def is_recruit(self):
#     def battles_played(self):
#     def battles_reserve(self):
#     def __repr__(self):
#     def to_dict(self):
#     def player_role_value(self):
#     def __init__(self, player, battle, reserve=False):
#     def __init__(self, date, clan, enemy_clan, victory, draw, creator, battle_commander, map_name, map_province,
#                  duration, description='', paid=False):
#     def outcome_str(self):
#     def outcome_repr(self):
#     def has_player(self, player):
#     def has_reserve(self, player):
#     def get_players(self):
#     def get_reserve_players(self):
#     def __str__(self):
#     def __init__(self, title, description, clan, date):
#     def get_players(self):
#     def get_reserves(self):
#     def get_final_battle(self):
#     def get_representative_battle(self):
#     def __init__(self, replay_blob, replay_pickle):
#     def unpickle(self):
#     def get(cls):
# class Player(Base):
# class BattleAttendance(Base):
# class Battle(Base):
# class BattleGroup(Base):
# class Replay(Base):
# class WebappData(Base):


# Path: whyattend/webapp.py
import csv
import datetime
import os
import pickle
import logging
import hashlib
import tarfile
import calendar
import jinja2
    import calendar
    import hashlib
from cStringIO import StringIO
from collections import defaultdict, OrderedDict
from functools import wraps
from datetime import timedelta
from flask import Flask, g, session, render_template, flash, redirect, request, url_for, abort, make_response, jsonify
from flask import Response
from flask_openid import OpenID
from flask_cache import Cache
from sqlalchemy import or_, and_, alias
from sqlalchemy.orm import joinedload, joinedload_all
from werkzeug.utils import secure_filename, Headers
from pytz import timezone
from . import config, replays, wotapi, util, constants, analysis
from .model import Player, Battle, BattleAttendance, Replay, BattleGroup, db_session, WebappData
    from logging.handlers import RotatingFileHandler
    from logging.handlers import RotatingFileHandler
    from sqlalchemy import case, desc, asc, select, func, literal
    from datetime import timedelta

                    return redirect(url_for('battle_details', battle_id=battle.id))

            r = Replay(replay_blob, pickle.dumps(replay))
            r.associated_battle = battle
            r.player_name = replay['first']['playerName']
            db_session.commit()

    return redirect(url_for('battle_details', battle_id=battle.id))


@app.route('/battles/edit/<int:battle_id>', methods=['GET', 'POST'])
@require_login
@require_role(roles=config.CREATE_BATTLE_ROLES)
def edit_battle(battle_id):
    """
        Edit battle form.
    :param battle_id:
    :return:
    """
    battle = Battle.query.get(battle_id) or abort(404)
    if battle.clan != g.player.clan and g.player.name not in config.ADMINS:
        abort(403)

    all_players = Player.query.filter_by(clan=g.player.clan, locked=False).order_by('lower(name)').all()
    sorted_players = sorted(all_players, reverse=True, key=lambda p: p.player_role_value())
    date = battle.date
    map_name = battle.map_name
    province = battle.map_province
    battle_commander = battle.battle_commander
    enemy_clan = battle.enemy_clan

    battle_groups = BattleGroup.query.filter_by(clan=g.player.clan).order_by('date').all()