示例#1
0
def edit_listing(listing, request):
    if not listing:
        raise FormError()
    address = request.form.get('address')
    lat = request.form.get('latitude')
    lon = request.form.get('longitude')
    if not all([address, lat, lon]):
        raise FormError()
    space_type = get_space_type(request.form.get('space_type'))
    if not space_type:
        raise FormError()
    rate_type = get_rate_type(request.form.get('rate_type'))
    if not rate_type:
        raise FormError()
    price = request.form.get('price')
    description = request.form.get('description')
    name = request.form.get('name')
    if not all([space_type, price, name]):
        raise FieldError("All required fields must be filled in")
    try:
        price = float(price)
    except ValueError:
        raise FieldError("Price must be a number")
    ada_accessible = request.form.get('ada_accessible')
    if ada_accessible == "no":
        ada_accessible = False
    else:
        ada_accessible = True
    listing.contact_phone = request.form.get('contact_phone')
    listing.contact_email = request.form.get('contact_email')
    listing.name = name
    listing.space_type = space_type
    listing.rate_type = rate_type
    listing.price = price
    listing.description = description
    listing.ada_accessible = ada_accessible
    db.session.add(listing)
    db.session.commit()
示例#2
0
def submit_step2(token):
    # Look up token
    token = SubmissionToken.query.filter(SubmissionToken.key == token).first()
    # Check for a real token and that they havent already submitted
    print request.form
    if not token or token.listing:
        return redirect('/submit')
    address = request.form.get('address')
    lat = request.form.get('latitude')
    lon = request.form.get('longitude')
    if not all([address, lat, lon]):
        return redirect('/submit')
    space_type = get_space_type(request.form.get('space_type'))
    if not space_type:
        return redirect('/submit')
    rate_type = get_rate_type(request.form.get('rate_type'))
    if not rate_type:
        return redirect('/submit')
    price = request.form.get('price')
    description = request.form.get('description')
    name = request.form.get('name')
    listing_types = ListingType.query.all()
    rate_types = RateType.query.all()
    expires_in_days = request.form.get('expires_in_days')
    ada_accessible = request.form.get('ada_accessible')
    if ada_accessible == "no":
        ada_accessible = False
    else:
        ada_accessible = True
    contact_phone = request.form.get('contact_phone')
    contact_email = request.form.get('contact_email')
    listing={
        "address": address,
        "latitude": lat,
        "longitude": lon,
        "name": name,
        "price": price,
        "space_type": space_type,
        "description": description,
        "contact_email": contact_email,
        "contact_phone": contact_phone,
        "ada_accessible": ada_accessible
    }
    if not all([space_type, price, name, description, contact_phone]):
        return render_template('submit2.html',
                               types=listing_types,
                               rate_types=rate_types,
                               token=token,
                               listing=listing,
                               error="All required fields must be filled in")
    try:
        try:
            if price.startswith('$'):
                price = price[1:]
            price = float(price)
        except:
            raise Exception("Price must be a number")
        try:
            expires_in_days = int(expires_in_days)
        except:
            raise Exception("Expiration must be a number of days")
    except Exception, e:
        return render_template('submit2.html',
                               types=listing_types,
                               rate_types=rate_types,
                               token=token,
                               listing=listing,
                               error=str(e))