示例#1
0
def create_club():
    '''register new club'''
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(only=("name","email","website")).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if Club.exists(name=data.get("name")):
        return jsonify(error="duplicate-club-name"), 422

    # create the new club
    club = Club(**data)
    club.owner_id = current_user.id

    db.session.add(club)
    db.session.flush()

    # assign the user to the new club
    current_user.club = club

    # create the "user joined club" event
    create_club_join_event(club.id, current_user)

    db.session.commit()

    return jsonify(id=club.id)
示例#2
0
def create_club():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(only=("name",)).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if Club.exists(name=data.get("name")):
        return jsonify(error="duplicate-club-name"), 422

    # create the new club
    club = Club(**data)
    club.owner_id = current_user.id
    db.session.add(club)
    db.session.flush()

    # assign the user to the new club
    current_user.club = club

    # create the "user joined club" event
    create_club_join_event(club.id, current_user)

    db.session.commit()

    return jsonify(id=club.id)
示例#3
0
文件: user.py 项目: imclab/skylines
def create_club_post(form):
    club = Club(name=form.name.data)
    club.owner_id = g.current_user.id
    db.session.add(club)

    g.user.club = club

    db.session.commit()

    return redirect(url_for('.index'))
示例#4
0
def club_create_post(form):
    club = Club(name=form.name.data)
    club.owner_id = g.current_user.id
    db.session.add(club)

    db.session.flush()

    g.user.club = club

    create_club_join_event(club.id, g.user)

    db.session.commit()

    return redirect(url_for('.club', user=g.user_id))
示例#5
0
def club_create_post(form):
    club = Club(name=form.name.data)
    club.owner_id = g.current_user.id
    db.session.add(club)

    db.session.flush()

    g.user.club = club

    create_club_join_event(club.id, g.user)

    db.session.commit()

    return redirect(url_for('.club', user=g.user_id))
示例#6
0
    def create_club(self, name, **kw):
        if not self.user.is_writable(request.identity):
            raise HTTPForbidden

        current_user = request.identity['user']

        club = Club(name=name)
        club.owner_id = current_user.id
        DBSession.add(club)

        self.user.club = club

        DBSession.flush()

        redirect('.')
示例#7
0
def index():
    if g.current_user:
        club = g.current_user.club
    else:
        club = Club.get(1)

    return render_template('widgets/index.jinja', club=club)
示例#8
0
def update(club_id):
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    club = get_requested_record(Club, club_id)
    if not club.is_writable(current_user):
        return jsonify(error="forbidden"), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if "name" in data:
        name = data.get("name")

        if name != club.name and Club.exists(name=name):
            return jsonify(error="duplicate-club-name"), 422

        club.name = name

    if "website" in data:
        club.website = data.get("website")

    db.session.commit()

    return jsonify()
示例#9
0
def index():
    if g.current_user:
        club = g.current_user.club
    else:
        club = Club.get(1)

    return render_template('widgets/index.jinja', club=club)
示例#10
0
def test_create(db_session, client, test_user):
    res = client.put("/clubs", headers=auth_for(test_user), json={"name": "LV Aachen"})
    assert res.status_code == 200

    club = Club.get(res.json["id"])
    assert club
    assert club.owner_id == test_user.id
示例#11
0
def read(club_id):
    club = Club.get(club_id)
    if club is None:
        raise NotFound()

    result = club_schema.dump(club)
    return jsonify(result.data)
示例#12
0
def update(club_id):
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    club = get_requested_record(Club, club_id)
    if not club.is_writable(current_user):
        return jsonify(error='forbidden'), 403

    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    if 'name' in data:
        name = data.get('name')

        if name != club.name and Club.exists(name=name):
            return jsonify(error='duplicate-club-name'), 422

        club.name = name

    if 'website' in data:
        club.website = data.get('website')

    db.session.commit()

    return jsonify()
示例#13
0
def _list():
    clubs = Club.query().order_by(func.lower(Club.name))

    name_filter = request.args.get("name")
    if name_filter:
        clubs = clubs.filter_by(name=name_filter)

    return jsonify(clubs=ClubSchema(only=("id", "name")).dump(clubs, many=True).data)
示例#14
0
def _listClubsByName():
    clubs = Club.query().order_by(func.lower(Club.name))

    name_filter = request.args.get("name")
    if name_filter:
        clubs = clubs.filter_by(name=name_filter)

    return jsonify(clubs=ClubSchema(only=("id", "name")).dump(clubs, many=True).data)
示例#15
0
文件: clubs.py 项目: tbille/skylines
def list():
    clubs = Club.query().order_by(func.lower(Club.name))

    name_filter = request.args.get('name')
    if name_filter:
        clubs = clubs.filter_by(name=name_filter)

    return jsonify(clubs=ClubSchema(only=('id', 'name')).dump(clubs, many=True).data)
示例#16
0
def test_create(db_session, client, test_user):
    res = client.put('/clubs', headers=auth_for(test_user), json={
        'name': 'LV Aachen',
    })
    assert res.status_code == 200

    club = Club.get(res.json['id'])
    assert club
    assert club.owner_id == test_user.id
示例#17
0
def index():
    if 'application/json' not in request.headers.get('Accept', ''):
        return render_template('ember-page.jinja', active_page='settings')

    clubs = Club.query().order_by(func.lower(Club.name))

    name_filter = request.args.get('name')
    if name_filter:
        clubs = clubs.filter_by(name=name_filter)

    return jsonify(clubs=ClubSchema(only=('id', 'name')).dump(clubs, many=True).data)
示例#18
0
def index():
    if 'application/json' not in request.headers.get('Accept', ''):
        return render_template('ember-page.jinja', active_page='settings')

    clubs = Club.query().order_by(func.lower(Club.name))

    name_filter = request.args.get('name')
    if name_filter:
        clubs = clubs.filter_by(name=name_filter)

    return jsonify(clubs=ClubSchema(only=('id',
                                          'name')).dump(clubs, many=True).data)
示例#19
0
def test_update_without_authentication(db_session, client):
    sfn = clubs.sfn()
    add_fixtures(db_session, sfn)

    res = client.post(
        "/clubs/{id}".format(id=sfn.id),
        json={"name": "foobar", "website": "https://foobar.de"},
    )
    assert res.status_code == 401

    club = Club.get(sfn.id)
    assert club.name == "Sportflug Niederberg"
    assert club.website == None
示例#20
0
def test_update_without_authentication(db_session, client):
    sfn = clubs.sfn()
    add_fixtures(db_session, sfn)

    res = client.post('/clubs/{id}'.format(id=sfn.id), json={
        'name': 'foobar',
        'website': 'https://foobar.de',
    })
    assert res.status_code == 401

    club = Club.get(sfn.id)
    assert club.name == 'Sportflug Niederberg'
    assert club.website == None
示例#21
0
def test_update_without_authentication(db_session, client):
    sfn = clubs.sfn()
    add_fixtures(db_session, sfn)

    res = client.post('/clubs/{id}'.format(id=sfn.id),
                      json={
                          'name': 'foobar',
                          'website': 'https://foobar.de',
                      })
    assert res.status_code == 401

    club = Club.get(sfn.id)
    assert club.name == 'Sportflug Niederberg'
    assert club.website == None
示例#22
0
def fixtures(db_session):
    owner = User(first_name=u'John', last_name=u'Doe', password='******')
    db_session.add(owner)

    created_at = datetime(2016, 01, 15, 12, 34, 56)

    data = {
        'john':
        owner,
        'lva':
        Club(name=u'LV Aachen',
             website=u'http://www.lv-aachen.de',
             owner=owner,
             time_created=created_at),
        'sfn':
        Club(name=u'Sportflug Niederberg', time_created=created_at),
    }

    for v in data.itervalues():
        db_session.add(v)

    db_session.commit()
    return data
示例#23
0
def test_update(db_session, client, test_user):
    sfn = clubs.sfn()
    test_user.club = sfn
    add_fixtures(db_session, sfn)

    res = client.post('/clubs/{id}'.format(id=sfn.id), headers=auth_for(test_user), json={
        'name': 'foobar',
        'website': 'https://foobar.de',
    })
    assert res.status_code == 200

    club = Club.get(sfn.id)
    assert club.name == 'foobar'
    assert club.website == 'https://foobar.de'
示例#24
0
def test_update(db_session, client, test_user):
    sfn = clubs.sfn()
    test_user.club = sfn
    add_fixtures(db_session, sfn)

    res = client.post(
        "/clubs/{id}".format(id=sfn.id),
        headers=auth_for(test_user),
        json={"name": "foobar", "website": "https://foobar.de"},
    )
    assert res.status_code == 200

    club = Club.get(sfn.id)
    assert club.name == "foobar"
    assert club.website == "https://foobar.de"
示例#25
0
def fixtures(db_session):
    data = {
        'john':
        User(first_name=u'John', last_name=u'Doe', password='******'),
        'jane':
        User(first_name=u'Jane', last_name=u'Doe', password='******'),
        'lva':
        Club(name=u'LV Aachen', website='https://www.lv-aachen.de'),
        'sfn':
        Club(name=u'Sportflug Niederberg'),
        'edka':
        Airport(name=u'Aachen-Merzbrück',
                country_code='DE',
                icao='EDKA',
                frequency='122.875'),
        'mbg':
        Airport(name=u'Meiersberg', country_code='DE'),
    }

    for v in data.itervalues():
        db_session.add(v)

    db_session.commit()
    return data
示例#26
0
def test_update_without_authentication(db_session, client):
    sfn = clubs.sfn()
    add_fixtures(db_session, sfn)

    res = client.post(
        "/clubs/{id}".format(id=sfn.id),
        json={
            "name": "foobar",
            "website": "https://foobar.de"
        },
    )
    assert res.status_code == 401

    club = Club.get(sfn.id)
    assert club.name == "Sportflug Niederberg"
    assert club.website == None
示例#27
0
def test_update(db_session, client, test_user):
    sfn = clubs.sfn()
    test_user.club = sfn
    add_fixtures(db_session, sfn)

    res = client.post('/clubs/{id}'.format(id=sfn.id),
                      headers=auth_for(test_user),
                      json={
                          'name': 'foobar',
                          'website': 'https://foobar.de',
                      })
    assert res.status_code == 200

    club = Club.get(sfn.id)
    assert club.name == 'foobar'
    assert club.website == 'https://foobar.de'
示例#28
0
def test_update(db_session, client, test_user):
    sfn = clubs.sfn()
    test_user.club = sfn
    add_fixtures(db_session, sfn)

    res = client.post(
        "/clubs/{id}".format(id=sfn.id),
        headers=auth_for(test_user),
        json={
            "name": "foobar",
            "website": "https://foobar.de"
        },
    )
    assert res.status_code == 200

    club = Club.get(sfn.id)
    assert club.name == "foobar"
    assert club.website == "https://foobar.de"
示例#29
0
def flights_js():
    flights = Flight.query() \
                    .filter(Flight.is_rankable())

    # Filter by user
    user_id = request.values.get('user', type=int)
    if user_id:
        user = User.get(user_id)
        if not user:
            abort(404)

        flights = flights.filter(
            or_(Flight.pilot == user, Flight.co_pilot == user))

    # Filter by club
    club_id = request.values.get('club', type=int)
    if club_id:
        club = Club.get(club_id)
        if not club:
            abort(404)

        flights = flights.filter(Flight.club == club)

    # Order by date and distance
    flights = flights.order_by(Flight.date_local.desc(),
                               Flight.olc_classic_distance)

    # Limit number of flights
    limit = request.values.get('limit', type=int, default=5)
    if not 0 < limit <= 30:
        raise BadRequest('The `limit` parameter must be between 1 and 30.')

    flights = flights.limit(limit)

    # Produce JS response
    callback = request.values.get('callback', 'onFlightsLoaded')
    return wrap(callback,
                render_template('widgets/flights.jinja', flights=flights))
示例#30
0
def flights_js():
    flights = Flight.query() \
                    .filter(Flight.is_rankable())

    # Filter by user
    user_id = request.values.get('user', type=int)
    if user_id:
        user = User.get(user_id)
        if not user:
            abort(404)

        flights = flights.filter(or_(
            Flight.pilot == user,
            Flight.co_pilot == user
        ))

    # Filter by club
    club_id = request.values.get('club', type=int)
    if club_id:
        club = Club.get(club_id)
        if not club:
            abort(404)

        flights = flights.filter(Flight.club == club)

    # Order by date and distance
    flights = flights.order_by(Flight.date_local.desc(), Flight.olc_classic_distance)

    # Limit number of flights
    limit = request.values.get('limit', type=int, default=5)
    if not 0 < limit <= 30:
        raise BadRequest('The `limit` parameter must be between 1 and 30.')

    flights = flights.limit(limit)

    # Produce JS response
    callback = request.values.get('callback', 'onFlightsLoaded')
    return wrap(callback, render_template('widgets/flights.jinja', flights=flights))
示例#31
0
def update(club_id):
    '''For editing club?'''
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    club = get_requested_record(Club, club_id)
    if not club.is_writable(current_user):
        return jsonify(error="forbidden"), 403

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if "name" in data:
        name = data.get("name")

        if name != club.name and Club.exists(name=name):
            return jsonify(error="duplicate-club-name"), 422

        club.name = name

    if "website" in data:
        club.website = data.get("website")

    if "email_address" in data:
        club.email_address = data.get("email_address")

    db.session.commit()

    return jsonify()
示例#32
0
        current_user.tracking_delay = data.get('tracking_delay')

    if 'password' in data:
        if 'currentPassword' not in data:
            return jsonify(error='current-password-missing'), 422

        if not current_user.validate_password(data['currentPassword']):
            return jsonify(error='wrong-password'), 403

        current_user.password = data['password']
        current_user.recover_key = None

    if 'club_id' in data and data['club_id'] != current_user.club_id:
        club_id = data['club_id']

        if club_id is not None and not Club.exists(id=club_id):
            return jsonify(error='unknown-club'), 422

        current_user.club_id = club_id

        create_club_join_event(club_id, current_user)

        # assign the user's new club to all of his flights that have
        # no club yet
        flights = Flight.query().join(IGCFile)
        flights = flights.filter(and_(Flight.club_id == None,
                                      or_(Flight.pilot_id == current_user.id,
                                          IGCFile.owner_id == current_user.id)))
        for flight in flights:
            flight.club_id = club_id
示例#33
0
        g.user.tracking_delay = data.get('tracking_delay')

    if 'password' in data:
        if 'currentPassword' not in data:
            return jsonify(error='current-password-missing'), 422

        if not g.user.validate_password(data['currentPassword']):
            return jsonify(error='wrong-password'), 403

        g.user.password = data['password']
        g.user.recover_key = None

    if 'club_id' in data and data['club_id'] != g.user.club_id:
        club_id = data['club_id']

        if club_id is not None and not Club.exists(id=club_id):
            return jsonify(error='unknown-club'), 422

        g.user.club_id = club_id

        create_club_join_event(club_id, g.user)

        # assign the user's new club to all of his flights that have
        # no club yet
        flights = Flight.query().join(IGCFile)
        flights = flights.filter(and_(Flight.club_id == None,
                                      or_(Flight.pilot_id == g.user.id,
                                          IGCFile.owner_id == g.user.id)))
        for flight in flights:
            flight.club_id = club_id
示例#34
0
        current_user.tracking_delay = data.get('tracking_delay')

    if 'password' in data:
        if 'currentPassword' not in data:
            return jsonify(error='current-password-missing'), 422

        if not current_user.validate_password(data['currentPassword']):
            return jsonify(error='wrong-password'), 403

        current_user.password = data['password']
        current_user.recover_key = None

    if 'club_id' in data and data['club_id'] != current_user.club_id:
        club_id = data['club_id']

        if club_id is not None and not Club.exists(id=club_id):
            return jsonify(error='unknown-club'), 422

        current_user.club_id = club_id

        create_club_join_event(club_id, current_user)

        # assign the user's new club to all of his flights that have
        # no club yet
        flights = Flight.query().join(IGCFile)
        flights = flights.filter(
            and_(
                Flight.club_id == None,
                or_(Flight.pilot_id == current_user.id,
                    IGCFile.owner_id == current_user.id)))
        for flight in flights:
示例#35
0
def sfn(**kwargs):
    return Club(name=u"Sportflug Niederberg",
                time_created=datetime(2017, 1, 1, 12, 34,
                                      56)).apply_kwargs(kwargs)
示例#36
0
def lva(**kwargs):
    return Club(
        name=u"LV Aachen",
        website=u"http://www.lv-aachen.de",
        time_created=datetime(2015, 12, 24, 12, 34, 56),
    ).apply_kwargs(kwargs)
示例#37
0
def update():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = CurrentUserSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    if 'email_address' in data:
        email = data.get('email_address')

        if email != current_user.email_address and User.exists(
                email_address=email):
            return jsonify(error='email-exists-already'), 422

        current_user.email_address = email

    if 'first_name' in data:
        current_user.first_name = data.get('first_name')

    if 'last_name' in data:
        current_user.last_name = data.get('last_name')

    if 'distance_unit' in data:
        current_user.distance_unit = data.get('distance_unit')

    if 'speed_unit' in data:
        current_user.speed_unit = data.get('speed_unit')

    if 'lift_unit' in data:
        current_user.lift_unit = data.get('lift_unit')

    if 'altitude_unit' in data:
        current_user.altitude_unit = data.get('altitude_unit')

    if 'tracking_callsign' in data:
        current_user.tracking_callsign = data.get('tracking_callsign')

    if 'tracking_delay' in data:
        current_user.tracking_delay = data.get('tracking_delay')

    if 'password' in data:
        if 'currentPassword' not in data:
            return jsonify(error='current-password-missing'), 422

        if not current_user.validate_password(data['currentPassword']):
            return jsonify(error='wrong-password'), 403

        current_user.password = data['password']
        current_user.recover_key = None

    if 'club_id' in data and data['club_id'] != current_user.club_id:
        club_id = data['club_id']

        if club_id is not None and not Club.exists(id=club_id):
            return jsonify(error='unknown-club'), 422

        current_user.club_id = club_id

        create_club_join_event(club_id, current_user)

        # assign the user's new club to all of his flights that have
        # no club yet
        flights = Flight.query().join(IGCFile)
        flights = flights.filter(
            and_(
                Flight.club_id == None,
                or_(Flight.pilot_id == current_user.id,
                    IGCFile.owner_id == current_user.id)))
        for flight in flights:
            flight.club_id = club_id

    db.session.commit()

    return jsonify()
示例#38
0
@club_blueprint.route('/edit')
def edit():
    return render_template('ember-page.jinja', active_page='settings')


@club_blueprint.route('/', methods=['POST'])
def edit_post():
    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = ClubSchema(partial=True).load(json).data
    except ValidationError, e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    if 'name' in data:
        name = data.get('name')

        if name != g.club.name and Club.exists(name=name):
            return jsonify(error='duplicate-club-name'), 422

        g.club.name = name

    if 'website' in data:
        g.club.website = data.get('website')

    db.session.commit()

    return jsonify()
示例#39
0
文件: clubs.py 项目: tbille/skylines
@oauth.required()
def create_club():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = ClubSchema(only=('name',)).load(json).data
    except ValidationError, e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    if Club.exists(name=data.get('name')):
        return jsonify(error='duplicate-club-name'), 422

    # create the new club
    club = Club(**data)
    club.owner_id = current_user.id
    db.session.add(club)
    db.session.flush()

    # assign the user to the new club
    current_user.club = club

    # create the "user joined club" event
    create_club_join_event(club.id, current_user)

    db.session.commit()
示例#40
0
def update():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error="invalid-token"), 401

    json = request.get_json()
    if json is None:
        return jsonify(error="invalid-request"), 400

    try:
        data = CurrentUserSchema(partial=True).load(json).data
    except ValidationError as e:
        return jsonify(error="validation-failed", fields=e.messages), 422

    if "email_address" in data:
        email = data.get("email_address")

        if email != current_user.email_address and User.exists(
                email_address=email):
            return jsonify(error="email-exists-already"), 422

        current_user.email_address = email

    if "first_name" in data:
        current_user.first_name = data.get("first_name")

    if "last_name" in data:
        current_user.last_name = data.get("last_name")

    if "distance_unit" in data:
        current_user.distance_unit = data.get("distance_unit")

    if "speed_unit" in data:
        current_user.speed_unit = data.get("speed_unit")

    if "lift_unit" in data:
        current_user.lift_unit = data.get("lift_unit")

    if "altitude_unit" in data:
        current_user.altitude_unit = data.get("altitude_unit")

    if "tracking_callsign" in data:
        current_user.tracking_callsign = data.get("tracking_callsign")

    if "tracking_delay" in data:
        current_user.tracking_delay = data.get("tracking_delay")

    if "password" in data:
        if "currentPassword" not in data:
            return jsonify(error="current-password-missing"), 422

        if not current_user.validate_password(data["currentPassword"]):
            return jsonify(error="wrong-password"), 403

        current_user.password = data["password"]
        current_user.recover_key = None

    if "club_id" in data and data["club_id"] != current_user.club_id:
        club_id = data["club_id"]

        if club_id is not None and not Club.exists(id=club_id):
            return jsonify(error="unknown-club"), 422

        current_user.club_id = club_id

        create_club_join_event(club_id, current_user)

        # assign the user's new club to all of his flights that have
        # no club yet
        flights = Flight.query().join(IGCFile)
        flights = flights.filter(
            and_(
                Flight.club_id == None,
                or_(
                    Flight.pilot_id == current_user.id,
                    IGCFile.owner_id == current_user.id,
                ),
            ))
        for flight in flights:
            flight.club_id = club_id

    db.session.commit()

    return jsonify()
示例#41
0
文件: club.py 项目: mkscala/skylines
    def validate_name(form, field):
        if field.data == field.object_data:
            return

        if Club.exists(name=field.data):
            raise ValidationError(l_("A club with this name exists already."))
示例#42
0
文件: club.py 项目: mkscala/skylines
    def process(self, *args, **kwargs):
        users = Club.query().order_by(Club.name)
        self.choices = [(0, "[" + l_("No club") + "]")]
        self.choices.extend([(user.id, user) for user in users])

        super(ClubsSelectField, self).process(*args, **kwargs)
示例#43
0
    def process(self, *args, **kwargs):
        users = Club.query().order_by(Club.name)
        self.choices = [(0, '[' + l_('No club') + ']')]
        self.choices.extend([(user.id, user) for user in users])

        super(ClubsSelectField, self).process(*args, **kwargs)
示例#44
0
    def validate_name(form, field):
        if field.data == field.object_data:
            return

        if Club.exists(name=field.data):
            raise ValidationError(l_('A club with this name exists already.'))
示例#45
0
def index():
    clubs = Club.query().order_by(func.lower(Club.name))
    return render_template('clubs/list.jinja',
                           active_page='settings',
                           clubs=clubs)
示例#46
0
def index():
    clubs = Club.query().order_by(func.lower(Club.name))
    return render_template(
        'clubs/list.jinja', active_page='settings', clubs=clubs)
示例#47
0
@oauth.required()
def create_club():
    current_user = User.get(request.user_id)
    if not current_user:
        return jsonify(error='invalid-token'), 401

    json = request.get_json()
    if json is None:
        return jsonify(error='invalid-request'), 400

    try:
        data = ClubSchema(only=('name',)).load(json).data
    except ValidationError, e:
        return jsonify(error='validation-failed', fields=e.messages), 422

    if Club.exists(name=data.get('name')):
        return jsonify(error='duplicate-club-name'), 422

    # create the new club
    club = Club(**data)
    club.owner_id = current_user.id
    db.session.add(club)
    db.session.flush()

    # assign the user to the new club
    current_user.club = club

    # create the "user joined club" event
    create_club_join_event(club.id, current_user)

    db.session.commit()