コード例 #1
0
def host_planit():
    """
    Creates a party.
    """
    form = PartyForm()
    print(request.get_json())
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        party = Party(
            name=form.data['name'],
            details=form.data['details'],
            location=form.data['location'],
            image_url=form.data['image_url'],
            host_id=form.data['host_id'],
            time=form.data['time'],
            starts_at=form.data['starts_at'],
        )
        db.session.add(party)
        db.session.commit()
        return party.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}
コード例 #2
0
def create_party():
    print("WE ARE HITTING THE START OF THE API ROUTE")
    form = PartyForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    party_mems = request.json.get("partyMembers")
    print("THIS IS PARTY_MEMS", party_mems)
    print("THIS IS FORM DATA", form.data)
    if form.validate_on_submit():
        party = Party(
            host_id=current_user.id,
            party_name=form.data['party_name'],
            party_size=form.data['party_size'],
            open_to_request=form.data['open_to_request']
        )
        for member in party_mems:
            new_member = User.query.filter_by(username = member).first()
            if new_member:
                party.party_members.append(new_member)
        db.session.add(party)
        db.session.commit()
        return {"party": party.to_dict()}
    return {"errors": "set errors here"}