Exemple #1
0
def photo_create(post_id):
    form = PhotoForm()
    form.post_id.data = post_id

    if form.validate_on_submit():
        files = request.files.getlist('file')

        for file in files:
            photo = Photo()
            photo.upload(file, post_id)

        return redirect(url_for('house.article_show', id=post_id))

    return render_template('photo_create.html', form=form)
Exemple #2
0
def photo_upload():
    photoform = PhotoForm()

    if request.method == 'POST' and photoform.validate_on_submit():

        photo = photoform.photo.data  # we could also use request.files['photo']
        description = photoform.description.data

        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        return render_template('display_photo.html',
                               filename=filename,
                               description=description)

    flash_errors(photoform)
    return render_template('photo_upload.html', form=photoform)
Exemple #3
0
def specificRecord(theId):
  # Get the record.
  aRow = db.session.query(ServiceRecord, Vehicle).filter_by(id=theId).join(Vehicle).first()
  aRecord = {
    "id": aRow[0].id,
    "year": aRow[1].year,
    "make": aRow[1].make,
    "model": aRow[1].model,
    "date": aRow[0].date,
    "miles": aRow[0].miles,
    "description": aRow[0].description
  }

  # Get the filepaths for the photos.
  import os
  aPostfix = "vehicles/receipts/{}".format(theId)
  aList = [url_for("static", filename=aPostfix + os.sep + x) for x in os.listdir("app/static/" + aPostfix)]

  # Create the form.
  aForm = PhotoForm()

  # Check to see if the form is valid as well as a post request.
  if aForm.validate_on_submit():
    filename = secure_filename(aForm.upload.data.filename)
    aSavePath = 'app/static/vehicles/receipts/{}/'.format(theId) + filename
    aForm.upload.data.save(aSavePath)

    # Convert the photo to nice web stuff.
    from pgmagick import Image, InterlaceType
    aImg = Image(aSavePath)
    aImg.quality(80)
    aImg.scale("80%")
    aImg.interlaceType(InterlaceType.PlaneInterlace)
    aImg.write(aSavePath)

    flash("File uploaded", "success")

    aForm = PhotoForm()

  return render_template(
    "vehicles/record.html",
    theRecord=aRecord,
    theFiles=aList,
    theForm=aForm
  )
Exemple #4
0
def photos(username):
    if request.method == "GET":
        return render_template("photos.html", profile_user=User.get_user(username), photo_form=PhotoForm())

    else:
        if not (g.user and g.user.username == username):
            flash("You are not authorized for that action.")
            return redirect("views.profiles")

        photo_form = PhotoForm()

        if photo_form.validate_on_submit():
            filename = PHOTO_UPLOAD_SET.save(photo_form.photo.file)
            photo = Photo(filename, g.user.id)
            db.session.add(photo)
            db.session.commit()
            flash("Photo saved.")
            return redirect(url_for("views.photos", username=g.user.username))
        return render_template("photos.html", profile_user=g.user, username=g.user.username, photo_form=photo_form)
Exemple #5
0
def upload_image():
    user = get_current_user()
    form = PhotoForm()
    if form.validate_on_submit():
        file = form.photo.data
        if file and allowed_file(file.filename):
            filename = secure_filename(rename_file(file.filename))
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            try:
                old_file = 'static/img/' + user.photo_file_name
                os.remove(old_file)
            except OSError:
                pass
            with pg_db.atomic():
                img_q = User.update(photo_file_name=filename).where(User.username == user.username)
                img_q.execute()

            flash('Your profile photo has been changed')
            return redirect(url_for('profile', username=user.username))
    return render_template('upload_image.html', form=form, title='Change your avatar')
Exemple #6
0
def upload():
    form = PhotoForm()

    if form.validate_on_submit():
        f = form.photo.data
        filename = str(uuid.uuid1()) + '_' + secure_filename(f.filename)
        logging.debug('filename:: %s' % filename)
        logging.debug('path:: %s' % os.path.join(
            UPLOAD_PATH, filename
        ) )

        f.save(os.path.join(
            UPLOAD_PATH, filename
        ))
        #return redirect(url_for('upload'))
        flash("Image uploaded successfully !")
        return render_template('upload.html', form=form)

    error = None
    if 'photo' in form.errors: error = form.errors['photo']
    return render_template('upload.html', form=form, error=error)
def submit():
    form = PhotoForm()
    if request.method == 'POST':

        if form.validate_on_submit():
            try:
                form.handle_submit(request)
                flash('Your picture has been sent successfully!', 'success')
                return redirect(url_for('submit'))
            except:
                flash_message = 'An internal error occured. Sorry...'
                if (DEBUG):
                    import sys
                    e = sys.exc_info()
                    flash_message += ' DEBUG : (' + str(e[1]) + ')'
                flash(flash_message, 'danger')
        else:
            flash(
                'Invalid form. Only jpg, jpeg, png and tiff files are allowed !',
                'danger')

    return render_template('submit.html', form=form)
Exemple #8
0
def photos(username):
    if request.method == 'GET':
        return render_template('photos.html',
                               profile_user=User.get_user(username),
                               photo_form=PhotoForm())

    else:
        if not (g.user and g.user.username == username):
            flash("You are not authorized for that action.")
            return redirect('views.profiles')

        photo_form = PhotoForm()

        if photo_form.validate_on_submit():
            filename = PHOTO_UPLOAD_SET.save(photo_form.photo.file)
            photo = Photo(filename, g.user.id)
            db.session.add(photo)
            db.session.commit()
            flash("Photo saved.")
            return redirect(url_for('views.photos', username=g.user.username))
        return render_template('photos.html',
                               profile_user=g.user,
                               username=g.user.username,
                               photo_form=photo_form)
Exemple #9
0
def edit_photo(photo_id=None):
    form = PhotoForm()
    print(form.capture_date)
    photo = None
    title = "Whats the pic about"
    if photo_id is not None:
        photo = Photograph.query.filter(Photograph.id == photo_id).first()
    if photo is None:
        photo = Photograph(status="DRAFT")
    if request.method == 'POST':
        if form.validate_on_submit():
            photo_id = update_photo(form, photo)
            return redirect(url_for("posts.edit_photo", photo_id=photo_id))

    if request.method == "GET":
        form = PhotoForm(id=photo.id,
                         title=photo.title,
                         photograph_url=photo.photograph_url,
                         tag_ids=photo.all_tag_ids(),
                         capture_date=photo.capture_date,
                         location=photo.location)
        title = photo.title

    return render_template('edit_photo.html', title=title, form=form)