예제 #1
0
def index():
    if current_user.is_authenticated:
        images = Image.select(Image, User).join(User).where(
            Image.user_id != current_user.id).order_by(Image.created_at.desc())
        return render_template('users/index.html', images=images)
    else:
        images = Image.select().order_by(Image.created_at.desc())
        return render_template('users/index.html', images=images)
예제 #2
0
def create(username):
    file = request.files["user_file"]
    user = User.get_or_none(User.id == current_user.id)
    image = Image(image_path=file.filename, user_id=user.id)
    upload_file_to_s3(file)
    image.save()
    flash(u'Image saved successfully!', 'success')
    return redirect(url_for('users.show', username=username))
예제 #3
0
def show(username):
    user = User.get(User.username == username)
    image_list = Image.select().where(Image.user_id == user.id)
    return render_template("users/profile.html",
                           username=username,
                           user=user,
                           image_list=image_list)
예제 #4
0
def create(img_id):

    nonce = request.form.get('payment_method_nonce')

    amount = request.form.get('amount')

    result = gateway.transaction.sale({
        "amount": amount,
        "payment_method_nonce": nonce,
        "options": {
            "submit_for_settlement": True
        }
    })

    if result.is_success:
        donation = Donations(amount=amount, image=img_id, user=current_user.id)
        image = Image.get_or_none(Image.id == img_id)
        user = User.get_or_none(User.id == image.user_id)
        donation.save()
        if not donation.save():
            flash(u'Data not saved in database!', 'warning')
            return redirect(url_for('donations.new'))
        #mailgun
        # send_simple_message(amount = amount, sender = current_user.name, reciever = user.name)
        flash(u'Donation is made', 'success')
        return redirect(url_for('users.index'))

    else:
        flash(
            u'Donation not successfully made, please check the amount of your donation',
            'warning')
        return redirect(url_for('users.index'))
예제 #5
0
def create(id):
    if "user_file" not in request.files:
        flash("No file was chosen! :O", 'warning')
        return redirect(url_for('users.show', username=current_user.username))
    file = request.files.get('user_file')
    file_name = secure_filename(file.filename)
    if file_name != '':
        caption = request.form.get('caption')
        error = str(upload_file_to_s3(file, S3_BUCKET))
        new_image = Image(source=S3_LOCATION + file_name,
                          user_id=current_user.id,
                          caption=caption)

        if new_image.save():
            return redirect(
                url_for('users.show', username=current_user.username))
        else:
            return render_template('users/profile.html', error=error)
    else:
        flash('File has no name!', 'warning')
        return redirect(url_for('users.show', username=current_user.username))
예제 #6
0
def new(image_id):
    if not current_user.is_authenticated:
        flash(u'Need to be logged in to donate.', 'warning')
        return redirect(request.referrer)
    current_user_images = Image.select(
        Image.id).where(Image.user_id == current_user.id)
    for cui_id in current_user_images:
        if image_id == str(cui_id):
            flash(
                'Sorry you cannot donate to yourself. You already own that money :)',
                'danger')
            return redirect(url_for('users.index'))

    client_token = gateway.client_token.generate({})
    return render_template('donations/new.html',
                           image_id=image_id,
                           client_token=client_token)
예제 #7
0
def new(img_id):
    client_token = gateway.client_token.generate()
    image = Image.get_or_none(Image.id == img_id)
    return render_template('/donations/new.html',
                           image=image,
                           client_token=client_token)
예제 #8
0
def index():
    images = Image.select().order_by(Image.created_at.desc())
    return render_template('/users/index.html',images = images)