예제 #1
0
def create_purchase(id):
    nonce_from_the_client = request.form["this-input"]
    amount = request.form.get('this-amount')
    gateway.transaction.sale({
        "amount": amount,
        "payment_method_nonce": nonce_from_the_client,
        "options": {
            "submit_for_settlement": True
        }
    })
    Donation(amount=amount, image_id=id, donor_id=current_user.id).save()
    pic = Pictures.get_by_id(id)
    user = User.get_or_none(User.id == pic.user_id)
    username = user.username
    message = Mail(
        from_email='*****@*****.**',
        to_emails=user.email,
        subject='Donation Notification',
        html_content='@' + current_user.username + ' donated ' + amount +
        f'$ to the following image below!<br><img src="{ pic.post_image }" />')
    try:
        sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
        response = sg.send(message)
        print(response.status_code)
        print(response.body)
        print(response.headers)
    except Exception as e:
        print(str(e))
    return redirect(url_for('users.show', username=username))
예제 #2
0
def me():
    current_user_id = get_jwt_identity()
    images_arr = []
    for image in Pictures.select().where(Pictures.user_id == current_user_id):
        images_arr.append(image.post_image)

    return jsonify(images_arr)
예제 #3
0
def pagefor(picture):

    pic = Pictures.get_or_none(Pictures.picture == picture+'.png')
    user = User.get_or_none(User.id == pic.user_id)

    if pic:
        return render_template('posts/post.html', pictures=pic, user=user)
    else:
        return 'No such post available'
def show(username):
    pictures = Pictures.select()
    user = User.get_or_none(User.username == username)
    if user:
        return render_template('accounts/profile.html',
                               user=user,
                               pictures=pictures)
    else:
        return render_template('accounts/search_error.html')
예제 #5
0
def show(username):
    pictures = Pictures.select()
    user = User.get_or_none(User.username == username)
    if user:
        return render_template('users/userpage.html',
                               user=user,
                               pictures=pictures)
    else:
        flash(
            'User not found. Please be aware that username is case sensitive.')
        return render_template('users/search-error.html')
예제 #6
0
def create():
    picture = request.files.get('picture')
    try:
        s3.upload_fileobj(
            picture,
            os.environ.get("BUCKET-NAME"),
            picture.filename,
            ExtraArgs={
                "ACL": 'public-read',
                "ContentType": picture.content_type
            }
        )
        Pictures(picture=picture.filename,user=current_user.id).save()
    except:
        flash('Upload unsuccessful')
        
    return redirect(url_for('users.show', username=current_user.username))
def create():
    picture = request.files.get('picture')
    caption = request.form.get('caption')
    randomString = uuid.uuid4().hex
    randomString = randomString[0:11]
    picture.filename = randomString + '.png'
    try:
        s3.upload_fileobj(picture,
                          os.environ.get("S3_BUCKET"),
                          picture.filename,
                          ExtraArgs={
                              "ACL": 'public-read',
                              "ContentType": picture.content_type
                          })
        Pictures(picture=picture.filename,
                 user=current_user.id,
                 caption=caption).save()
    except:
        flash('Upload unsuccessful')

    return redirect(url_for('show', username=current_user.username))
예제 #8
0
def index(id):
    images_arr = []
    for image in Pictures.select().where(Pictures.user_id == id):
        images_arr.append(image.post_image)

    return jsonify(images_arr)