Exemplo n.º 1
0
def add_product_photos():
    if "image" not in request.files:
        return {"errors": "image required"}, 400
    image = request.files["image"]

    if not allowed_file(image.filename):
        return {"errors": "file type not permitted"}, 400

    image.filename = get_unique_filename(image.filename)

    upload = upload_file_to_s3(image)

    if "url" not in upload:
        # if the dictionary doesn't have a url key
        # it means that there was an error when we tried to upload
        # so we send back that error message
        return upload, 400

    url = upload["url"]
    form = PhotoForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        photo = Photo(post_id=form.data["post_id"], media_url=url)
        db.session.add(photo)
        db.session.commit()
        return photo.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}, 401
Exemplo n.º 2
0
def update_profile_photo():
    if "image" not in request.files:
        return {"errors": "image required"}, 400

    image = request.files["image"]

    if not allowed_file(image.filename):
        return {"errors": "file type not permitted"}, 400

    image.filename = get_unique_filename(image.filename)

    upload = upload_file_to_s3(image)

    if "url" not in upload:
        # if the dictionary doesn't have a url key
        # it means that there was an error when we tried to upload
        # so we send back that error message
        return upload, 400

    url = upload["url"]
    # flask_login allows us to get the current user from the request
    currUser = User.query.get(current_user.id)
    currUser.profile_photo = url
    db.session.commit()
    return currUser.to_dict()
Exemplo n.º 3
0
def sign_up():
    """
    Creates a new user and logs them in
    """
    form = SignUpForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        if ('image' in request.files):
            image = request.files['image']
            image.filename = get_unique_filename(image.filename)
            upload = upload_file_to_s3(image)
            url = upload['url']
        else:
            url = 'https://github.com/Drewthurm21/LookingForGroup/blob/main/images/main_logo.PNG?raw=true'

        user = User(username=form.data['username'],
                    email=form.data['email'],
                    password=form.data['password'],
                    image_url=url)
        db.session.add(user)
        db.session.commit()

        print('------------->', user)
        login_user(user)
        return user.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}, 401
Exemplo n.º 4
0
def post_event():
    """
    Posts a new event to the website
    """
    form = EventForm()
    url = 'https://github.com/Drewthurm21/LookingForGroup/blob/main/images/main_logo.PNG?raw=true'

    if ('image' in request.files):
        image = request.files['image']
        image.filename = get_unique_filename(image.filename)
        upload = upload_file_to_s3(image)
        url = upload['url']

    event = Event(title=form.data['title'],
                  description=form.data['description'],
                  image_url=url,
                  category_id=form.data['category_id'],
                  price=form.data['price'],
                  host_id=current_user.id,
                  date=request.form['date'],
                  server_id=form.data['server_id'],
                  channel_id=form.data['channel_id'],
                  tickets=form.data['tickets'])
    db.session.add(event)
    db.session.commit()
    return event.to_dict()
Exemplo n.º 5
0
def sign_up():
    """
    Creates a new user and logs them in
    """
    form = SignUpForm()
    form['csrf_token'].data = request.cookies['csrf_token']

    if form.validate_on_submit():

        if "image" not in request.files:
            url = 'https://myplanits.s3-us-west-1.amazonaws.com/Screen+Shot+2021-03-08+at+4.58.09+PM.png'
        else:
            image = request.files["image"]
            if not allowed_file(image.filename):
                return {"errors": "file type not permitted"}, 400
            image.filename = get_unique_filename(image.filename)
            upload = upload_file_to_s3(image)
            if "url" not in upload:
                upload['url'] = ''
            url = upload['url']
        # url = {'url': ''}
        # if request.files:
        # url = upload_file_to_s3(request.files['image'])
        user = User(first_name=form.data['first_name'],
                    last_name=form.data['last_name'],
                    image_url=url,
                    email=form.data['email'],
                    password=form.data['password'])
        db.session.add(user)
        db.session.commit()
        login_user(user)
        return user.to_dict()
    return {'errors': validation_errors_to_error_messages(form.errors)}
Exemplo n.º 6
0
def pic():

    if "image" not in request.files:
        url = ''
    else:
        image = request.files["image"]
        if not allowed_file(image.filename):
            return {"errors": "file type not permitted"}, 400
        image.filename = get_unique_filename(image.filename)
        upload = upload_file_to_s3(image)
        if "url" not in upload:
            upload['url'] = ''
        url = upload['url']
        print('hit.........', url)

    return {'url': url}
Exemplo n.º 7
0
def pic(id):
    user = User.query.get(id)

    if "image" not in request.files:
        url = ''
    else:
        image = request.files["image"]
        if not allowed_file(image.filename):
            return {"errors": "file type not permitted"}, 400
        image.filename = get_unique_filename(image.filename)
        upload = upload_file_to_s3(image)
        if "url" not in upload:
            upload['url'] = ''
        url = upload['url']

    user.image_url = url
    db.session.commit()
    return user.to_dict()