Example #1
0
def test_get_hashed_filename():
    a = get_hashed_filename("foo bar baz.mp3")
    time.sleep(3)
    b = get_hashed_filename("foo bar baz.mp3")
    time.sleep(1)
    c = get_hashed_filename("foo bar baz.mp3")
    time.sleep(0.4)
    d = get_hashed_filename("foo bar baz.mp3")
    assert a != b != c != d
Example #2
0
def new():
    pcfg = {"title": gettext("Add Camera")}

    form = CameraAddForm()
    if form.validate_on_submit():
        camera = Camera()
        camera.state = form.state.data
        camera.state_notes = form.state_notes.data

        camera.manufacturer = form.manufacturer.data
        camera.model = form.model.data
        camera.model_notes = form.model_notes.data
        camera.description = form.description.data
        camera.serial = form.serial.data
        camera.mount = form.mount.data

        camera.camera_type = form.camera_type.data

        camera.film_type = form.film_type.data
        camera.auto_expo = form.auto_expo.data
        camera.auto_focus = form.auto_focus.data
        camera.batteries = form.batteries.data
        camera.hot_shoe = form.hot_shoe.data
        camera.fixed_lens = form.fixed_lens.data

        camera.iso_min = form.iso_min.data
        camera.iso_max = form.iso_max.data
        camera.focale_min = form.focale_min.data
        camera.focale_max = form.focale_max.data
        camera.min_aperture = form.min_aperture.data
        camera.max_aperture = form.max_aperture.data
        camera.blades = form.blades.data
        camera.filter_diameter = form.filter_diameter.data
        camera.weight = form.weight.data
        camera.length = form.length.data
        camera.focus = form.focus.data
        camera.focus_length = form.focus_length.data
        camera.macro = form.macro.data
        camera.macro_length = form.macro_length.data

        camera.private = form.private.data

        camera.url1 = form.url1.data
        camera.url2 = form.url2.data
        camera.url3 = form.url3.data

        camera.user_id = current_user.id

        if "picture" in request.files:
            camera.pic_filename = get_hashed_filename(
                request.files["picture"].filename)
            pictures.save(request.files["picture"],
                          folder=current_app.config["UPLOADED_PICTURES_DEST"],
                          name=camera.pic_filename)

        db.session.add(camera)
        db.session.commit()
        flash("Successfully added camera.", "success")
        return redirect(url_for("bp_users.cameras", name=current_user.name))
    return render_template("cameras/new.jinja2", pcfg=pcfg, form=form)
Example #3
0
def edit(camera_id):
    pcfg = {"title": gettext("Edit Camera")}

    camera = Camera.query.filter(Camera.id == camera_id,
                                 Camera.user_id == current_user.id).first()
    if not camera:
        flash("Camera not found", "error")
        return redirect(url_for("bp_users.cameras", name=current_user.name))

    form = CameraEditForm(request.form, obj=camera)

    if form.validate_on_submit():
        form.populate_obj(camera)

        if "picture" in request.files:
            camera.pic_filename = get_hashed_filename(
                request.files["picture"].filename)
            pictures.save(request.files["picture"],
                          folder=current_app.config["UPLOADED_PICTURES_DEST"],
                          name=camera.pic_filename)

        db.session.commit()
        flash("Successfully edited camera.", "success")
        return redirect(url_for("bp_users.cameras", name=current_user.name))

    # For some reasons the private.data isn't populated and stay to False even if camera.private == True
    form.private.data = camera.private
    form.auto_expo.data = camera.auto_expo
    form.auto_focus.data = camera.auto_focus
    form.hot_shoe.data = camera.hot_shoe
    form.fixed_lens.data = camera.fixed_lens
    form.blades.data = camera.blades
    form.macro.data = camera.macro

    return render_template("cameras/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           camera=camera)
Example #4
0
def edit(accessory_id):
    pcfg = {"title": gettext("Edit Accessory")}

    accessory = Accessory.query.filter(
        Accessory.id == accessory_id,
        Accessory.user_id == current_user.id).first()
    if not accessory:
        flash("Accessory not found", "error")
        return redirect(url_for("bp_users.accessories",
                                name=current_user.name))

    form = AccessoryEditForm(request.form, obj=accessory)

    if form.validate_on_submit():
        form.populate_obj(accessory)

        if "picture" in request.files:
            accessory.pic_filename = get_hashed_filename(
                request.files["picture"].filename)
            pictures.save(
                request.files["picture"],
                folder=current_app.config["UPLOADED_PICTURES_DEST"],
                name=accessory.pic_filename,
            )

        db.session.commit()
        flash("Successfully edited accessory.", "success")
        return redirect(url_for("bp_users.accessories",
                                name=current_user.name))

    # For some reasons the private.data isn't populated and stay to False even if accessory.private == True
    form.private.data = accessory.private

    return render_template("accessories/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           accessory=accessory)
Example #5
0
def new():
    pcfg = {"title": gettext("Add Accessory")}

    form = AccessoryAddForm()
    if form.validate_on_submit():
        accessory = Accessory()
        accessory.state = form.state.data
        accessory.state_notes = form.state_notes.data
        accessory.manufacturer = form.manufacturer.data
        accessory.model = form.model.data
        accessory.model_notes = form.model_notes.data
        accessory.description = form.description.data
        accessory.serial = form.serial.data
        accessory.mount = form.mount.data
        accessory.private = form.private.data
        accessory.url1 = form.url1.data
        accessory.url2 = form.url2.data
        accessory.url3 = form.url3.data
        accessory.batteries = form.batteries.data
        accessory.user_id = current_user.id

        if "picture" in request.files:
            accessory.pic_filename = get_hashed_filename(
                request.files["picture"].filename)
            pictures.save(
                request.files["picture"],
                folder=current_app.config["UPLOADED_PICTURES_DEST"],
                name=accessory.pic_filename,
            )

        db.session.add(accessory)
        db.session.commit()
        flash("Successfully added accessory.", "success")
        return redirect(url_for("bp_users.accessories",
                                name=current_user.name))
    return render_template("accessories/new.jinja2", pcfg=pcfg, form=form)
Example #6
0
def upload():
    pcfg = {"title": gettext("New upload")}
    user = User.query.filter(User.id == current_user.id).one()

    form = SoundUploadForm()

    if request.method == "POST" and "sound" in request.files:
        if form.validate_on_submit():
            filename_orig = request.files["sound"].filename
            filename_hashed = get_hashed_filename(filename_orig)

            sounds.save(request.files["sound"],
                        folder=user.slug,
                        name=filename_hashed)

            rec = Sound()
            rec.filename = filename_hashed
            rec.filename_orig = filename_orig
            rec.licence = form.licence.data
            if form.album.data:
                rec.album_id = form.album.data.id
                if not form.album.data.sounds:
                    rec.album_order = 0
                else:
                    rec.album_order = form.album.data.sounds.count() + 1

            rec.user_id = current_user.id
            if not form.title.data:
                rec.title = filename_orig
            else:
                rec.title = form.title.data
            rec.description = form.description.data
            rec.private = form.private.data

            if "flac" in request.files[
                    "sound"].mimetype or "ogg" in request.files[
                        "sound"].mimetype:
                rec.transcode_state = Sound.TRANSCODE_WAITING
                rec.transcode_needed = True

            db.session.add(rec)
            db.session.commit()

            # push the job in queue
            from tasks import upload_workflow

            upload_workflow.delay(rec.id)

            # log
            add_user_log(rec.id, user.id, "sounds", "info",
                         "Uploaded {0} -- {1}".format(rec.id, rec.title))

            flash(gettext("Uploaded ! Processing will now follow."), "success")
        else:
            return render_template("sound/upload.jinja2",
                                   pcfg=pcfg,
                                   form=form,
                                   flash="Error with the file")
        return redirect(
            url_for("bp_sound.show",
                    username=current_user.name,
                    soundslug=rec.slug))

    # GET
    return render_template("sound/upload.jinja2", pcfg=pcfg, form=form)