Beispiel #1
0
def user_filters():
    """ Manage user's lens filters """
    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()
    filter_form = FilterForm()

    if request.method == 'POST':
        # Filters
        if request.form['button'] == 'addFilter':
            nextFilterID = next_id(connection, 'filterID', 'Filters')
            qry = text("""INSERT INTO Filters
                (userID, filterID, name, code, factor, ev)
                VALUES (:userID, :filterID, :name, :code, :factor, :ev)""")
            insert(connection,
                   qry,
                   "Filters",
                   userID=userID,
                   filterID=nextFilterID,
                   name=filter_form.name.data,
                   code=filter_form.code.data,
                   factor=filter_form.factor.data,
                   ev=filter_form.ev.data)

        if request.form['button'] == 'deleteFilter':
            qry = text("""DELETE FROM Filters
                WHERE userID = :userID
                AND filterID = :filterID""")
            delete(connection,
                   qry,
                   "Filter",
                   userID=userID,
                   filterID=int(request.form['filterID']))

    qry = text("""SELECT filterID, name, code, factor, ev
        FROM Filters
        WHERE userID = :userID ORDER BY name""")
    filters = connection.execute(qry, userID=current_user.get_id()).fetchall()

    transaction.commit()
    return render_template('/gear/filters.html',
                           filter_form=filter_form,
                           filters=filters)
Beispiel #2
0
def developing():
    """ Index page for developing section """
    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()
    developer_form = DeveloperForm()

    if request.method == 'POST':
        if developer_form.validate_on_submit():
            qry = text("""INSERT INTO Developers
                (userID, developerID, name, mixedOn, capacity, type, kind,
                state, notes)
                VALUES (:userID, :developerID, :name, :mixedOn,
                :capacity, :type, :kind, :state, :notes)""")
            functions.insert(connection, qry, "Developers",
                             userID=userID,
                             developerID=functions.next_id(connection,
                                                           'developerID',
                                                           'Developers'),
                             name=developer_form.name.data,
                             mixedOn=developer_form.mixedOn.data,
                             capacity=developer_form.capacity.data,
                             type=developer_form.type.data,
                             kind=developer_form.kind.data,
                             state=developer_form.state.data,
                             notes=developer_form.notes.data)

    qry = text("""SELECT developerID, name, type, kind FROM Developers
        WHERE userID = :userID
        AND state = 'Active'""")
    active_developers = connection.execute(qry, userID=userID).fetchall()

    qry = text("""SELECT developerID, name, type, kind FROM Developers
        WHERE userID = :userID
        AND state = 'Retired'""")
    retired_developers = connection.execute(qry, userID=userID).fetchall()

    transaction.commit()
    return render_template('/developing/index.html',
                           active_developers=active_developers,
                           retired_developers=retired_developers,
                           developer_form=developer_form)
Beispiel #3
0
def user_enlargers():
    """ Manage user's enlargers """
    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()

    enlarger_lens_form = EnlargerLensForm()
    enlarger_form = EnlargerForm()

    if request.method == 'POST':
        app.logger.debug('POST')
        # Enlarger Lenses
        if request.form['button'] == 'addEnlargerLens':
            nextEnlargerLensID = next_id(connection, 'enlargerLensID',
                                         'EnlargerLenses')
            qry = text("""INSERT INTO EnlargerLenses
                (enlargerLensID, userID, name)
                VALUES (:enlargerLensID, :userID, :name)""")
            insert(connection,
                   qry,
                   "Enlarger Lens",
                   enlargerLensID=nextEnlargerLensID,
                   userID=userID,
                   name=enlarger_lens_form.name.data)
        if request.form['button'] == 'deleteEnlargerLens':
            qry = text("""DELETE FROM EnlargerLenses
                WHERE userID = :userID
                AND enlargerLensID = :enlargerLensID""")
            connection.execute(qry,
                               userID=userID,
                               enlargerLensID=int(
                                   request.form['enlargerLensID']))

        if request.form['button'] == 'addEnlarger':
            nextEnlargerID = next_id(connection, 'enlargerID', 'Enlargers')
            qry = text("""INSERT INTO Enlargers
                (userID, enlargerID, name, type, lightsource, wattage, temperature, notes)
                VALUES (:userID, :enlargerID, :name, :type, :lightsource, :wattage,
                    :temperature, :notes)""")
            connection.execute(qry,
                               userID=userID,
                               enlargerID=nextEnlargerID,
                               name=enlarger_form.name.data,
                               type=enlarger_form.type.data,
                               lightsource=enlarger_form.lightsource.data,
                               wattage=enlarger_form.wattage.data,
                               temperature=enlarger_form.temperature.data,
                               notes=enlarger_form.notes.data)
        if request.form['button'] == 'deleteEnlarger':
            qry = text("""DELETE FROM Enlargers
                WHERE userID = :userID
                AND enlargerID = :enlargerID""")
            connection.execute(qry,
                               userID=userID,
                               enlargerID=int(request.form['enlargerID']))

    qry = text("""SELECT enlargerLensID, name
        FROM EnlargerLenses
        WHERE userID = :userID ORDER BY name""")
    enlargerLenses = connection.execute(
        qry, userID=current_user.get_id()).fetchall()

    qry = text("""SELECT enlargerID, name, type, lightsource, wattage,
        temperature, notes
        FROM Enlargers
        WHERE userID = :userID ORDER BY name""")
    enlargers = connection.execute(qry,
                                   userID=current_user.get_id()).fetchall()

    transaction.commit()
    return render_template('/gear/enlargers.html',
                           enlarger_lens_form=enlarger_lens_form,
                           enlarger_form=enlarger_form,
                           enlargerLenses=enlargerLenses,
                           enlargers=enlargers)
Beispiel #4
0
def user_cameras():
    """ Manage a user's cameras """
    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()
    camera_form = CameraForm()
    camera_lens_form = CameraLensForm()

    if request.method == 'POST':
        # Camera
        if request.form['button'] == 'addCamera':
            app.logger.debug('Add Camera')
            nextCameraID = next_id(connection, 'cameraID', 'Cameras')
            qry = text("""INSERT INTO Cameras
                (cameraID, userID, name, filmSize) VALUES (:cameraID, :userID, :name, :filmSize)"""
                       )
            insert(connection,
                   qry,
                   "Camera",
                   cameraID=nextCameraID,
                   userID=int(current_user.get_id()),
                   name=camera_form.name.data,
                   filmSize=camera_form.filmSize.data)

        # Camera Lenses
        if request.form['button'] == 'addCameraLens':
            nextLensID = next_id(connection, 'lensID', 'Lenses')
            qry = text("""INSERT INTO Lenses
                (lensID, userID, name, shutter)
                VALUES (:lensID, :userID, :name, :shutter)""")
            insert(connection,
                   qry,
                   "Lens",
                   lensID=nextLensID,
                   userID=userID,
                   name=camera_lens_form.name.data,
                   shutter=camera_lens_form.shutter.data)

        if request.form['button'] == 'deleteCameraLens':
            qry = text("""DELETE FROM Lenses
                WHERE userID = :userID
                AND lensID = :lensID""")
            delete(connection,
                   qry,
                   "Lens",
                   userID=userID,
                   lensID=int(request.form['lensID']))

    qry = text("""SELECT cameraID, name, filmSize, status
        FROM Cameras
        WHERE userID = :userID ORDER BY filmSize, name""")
    cameras = connection.execute(qry, userID=userID).fetchall()

    qry = text("""SELECT lensID, name, shutter
        FROM Lenses
        WHERE userID = :userID ORDER BY name""")
    cameraLenses = connection.execute(qry, userID=userID).fetchall()

    transaction.commit()
    return render_template('/gear/cameras.html',
                           camera_form=camera_form,
                           camera_lens_form=camera_lens_form,
                           cameras=cameras,
                           cameraLenses=cameraLenses)
Beispiel #5
0
def expsoure_details(binderID, projectID, filmID, exposureNumber):
    """ Detailed exposure information """
    # pylint: disable=too-many-locals
    # Another heavierweight part of the app which could stand to be improved,
    # but works for now.

    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()

    if request.method == 'POST':
        form = ExposureForm()
        filmSizeID = zero_to_none(form.filmSizeID.data)

        if request.form['button'] == 'addExposure':
            # First we get basic info about the film log
            qry = text("""SELECT filmTypeID, filmSizeID FROM Films
                WHERE projectID = :projectID
                AND filmID = :filmID
                AND userID = :userID""")
            filmInfo = connection.execute(qry,
                                          projectID=projectID,
                                          filmID=filmID,
                                          userID=userID).fetchone()
            filmTypeID = filmInfo.filmTypeID
            filmSizeID = filmInfo.filmSizeID

            # Determine if the format is sheet film
            qry = text("""SELECT 1 FROM FilmSizes
                WHERE filmSizeID = :filmSizeID
                AND format = 'Sheet'""")
            sheet_film = connection.execute(qry,
                                            filmSizeID=filmSizeID).fetchone()

            # If exposure number has a dash, it means
            # we are adding a range of exposures
            exposureNumber = form.exposureNumber.data
            if re.search("-", exposureNumber):
                ranges = exposureNumber.split("-", 2)
                sequence = range(int(ranges[0]), int(ranges[1]) + 1)
            else:
                sequence = [int(exposureNumber)]
            for exposure in sequence:
                qry = text("""INSERT INTO Exposures
                    (userID, filmID, exposureNumber, lensID, holderID, shutter, aperture,
                    filmTypeID, iso, metering, flash, subject, development, notes)
                    VALUES (:userID, :filmID, :exposureNumber, :lensID, :holderID,
                    :shutter, :aperture, :filmTypeID, :shotISO, :metering,
                    :flash, :subject, :development, :notes)""")
                insert(connection,
                       qry,
                       "Exposure",
                       userID=userID,
                       filmID=filmID,
                       exposureNumber=exposure,
                       lensID=zero_to_none(form.lensID.data),
                       holderID=zero_to_none(form.holderID.data),
                       shutter=encode_shutter(form.shutter.data),
                       aperture=form.aperture.data,
                       filmTypeID=zero_to_none(form.filmTypeID.data),
                       shotISO=zero_to_none(form.shotISO.data),
                       metering=zero_to_none(form.metering.data),
                       flash=form.flash.data,
                       subject=form.subject.data,
                       development=form.development.data,
                       notes=form.notes.data)

                qry = text("""INSERT INTO ExposureFilters
                (userID, filmID, exposureNumber, filterID)
                VALUES (:userID, :filmID, :exposureNumber, :filterID)""")
                for filterID in form.filters.data:
                    insert(connection,
                           qry,
                           "Filter",
                           userID=userID,
                           filmID=filmID,
                           exposureNumber=exposure,
                           filterID=filterID)

                if sheet_film:
                    auto_decrement_film_stock(connection, filmTypeID,
                                              filmSizeID)

        if request.form['button'] == 'updateExposure':
            qry = text("""UPDATE Exposures
                SET exposureNumber = :exposureNumberNew,
                    shutter = :shutter,
                    aperture = :aperture,
                    lensID = :lensID,
                    holderID = :holderID,
                    flash = :flash,
                    metering = :metering,
                    notes = :notes,
                    subject = :subject,
                    development = :development,
                    filmTypeID = :filmTypeID,
                    iso = :shotISO
                WHERE filmID = :filmID
                AND exposureNumber = :exposureNumberOld
                AND userID = :userID""")
            connection.execute(qry,
                               userID=userID,
                               filmID=filmID,
                               exposureNumberNew=form.exposureNumber.data,
                               exposureNumberOld=exposureNumber,
                               lensID=zero_to_none(form.lensID.data),
                               holderID=zero_to_none(form.holderID.data),
                               shutter=encode_shutter(form.shutter.data),
                               aperture=form.aperture.data,
                               filmTypeID=zero_to_none(form.filmTypeID.data),
                               filmSizeID=filmSizeID,
                               shotISO=zero_to_none(form.shotISO.data),
                               metering=zero_to_none(form.metering.data),
                               flash=form.flash.data,
                               subject=form.subject.data,
                               development=form.development.data,
                               notes=form.notes.data)

            qry = text("""DELETE FROM ExposureFilters
                WHERE filmID = :filmID
                AND exposureNumber = :exposureNumber
                AND userID = :userID""")
            connection.execute(qry,
                               filmID=filmID,
                               userID=userID,
                               exposureNumber=request.form['exposureNumber'])

            qry = text("""INSERT INTO ExposureFilters
                (userID, filmID, exposureNumber, filterID)
                VALUES (:userID, :filmID, :exposureNumber, :filterID)""")
            for filterID in request.form.getlist('filters'):
                insert(connection,
                       qry,
                       "Filter",
                       userID=userID,
                       filmID=filmID,
                       exposureNumber=request.form['exposureNumber'],
                       filterID=filterID)
        transaction.commit()
        return redirect('/binders/' + str(binderID) + '/projects/' +
                        str(projectID) + '/films/' + str(filmID))

    qry = text("""SELECT exposureNumber, shutter, aperture,
        lensID, flash, notes, metering, subject, development, filmTypeID,
        iso AS shotISO, holderID
        FROM Exposures
        WHERE filmID = :filmID
        AND exposureNumber = :exposureNumber
        AND userID = :userID""")
    exposure_result = connection.execute(qry,
                                         filmID=filmID,
                                         exposureNumber=exposureNumber,
                                         userID=userID).fetchall()
    row = result_to_dict(exposure_result)
    exposure = row[0]
    exposure['shutter'] = format_shutter(exposure['shutter'])

    qry = text("""SELECT cameraID, format
        FROM Films
        LEFT OUTER JOIN FilmSizes ON FilmSizes.filmSizeID = Films.filmSizeID
        WHERE userID = :userID
        AND filmID = :filmID""")
    extras_result = connection.execute(qry, userID=userID,
                                       filmID=filmID).fetchone()
    cameraID = extras_result[0]
    filmFormat = extras_result[1]

    qry = text("""SELECT Filters.filterID AS filterID FROM ExposureFilters
        JOIN Filters ON Filters.filterID = ExposureFilters.filterID
        WHERE filmID = :filmID
        AND exposureNumber = :exposureNumber
        AND ExposureFilters.userID = :userID""")
    filtersResult = connection.execute(qry,
                                       filmID=filmID,
                                       exposureNumber=exposureNumber,
                                       userID=userID).fetchall()
    transaction.commit()

    form = ExposureForm()
    form = ExposureForm(data=exposure)
    form.populate_select_fields(connection, cameraID)
    form.populate_filter_selections(filtersResult)

    return render_template('film/edit-exposure.html',
                           form=form,
                           userID=userID,
                           binderID=binderID,
                           projectID=projectID,
                           filmID=filmID,
                           filmFormat=filmFormat,
                           exposureNumber=exposureNumber)
Beispiel #6
0
def print_exposure(binderID, projectID, filmID, printID):
    """ Manage a specific exposure print """
    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()
    form = PrintForm()
    form.populate_select_fields(connection, filmID)

    if request.method == 'POST':
        if request.form['button'] == 'deletePrint':
            fileID = check_for_print_file(connection, printID)
            qry = text("""DELETE FROM Prints
                WHERE printID = :printID
                AND userID = :userID""")
            connection.execute(qry, printID=printID, userID=userID)
            if fileID:
                files.delete_file(connection, transaction, fileID)
            transaction.commit()
            return redirect('/binders/' + str(binderID) + '/projects/' +
                            str(projectID) + '/films/' + str(filmID) +
                            '/prints')

        if request.form['button'] == 'updatePrint':
            if form.validate_on_submit():
                # See if there is a fileID
                fileID = check_for_print_file(connection, printID)
                # If the user has a file already, delete it first.
                # Otherwise treat it like a new file.
                if form.file.data:
                    if fileID:
                        app.logger.info('Replace File')
                        files.delete_file(connection, transaction, fileID)
                        files.upload_file(request, connection, transaction,
                                          fileID)
                    else:
                        app.logger.info('Brand New File')
                        fileID = functions.next_id(connection, 'fileID',
                                                   'Files')
                        files.upload_file(request, connection, transaction,
                                          fileID)
                qry = text("""REPLACE INTO Prints
                    (printID, filmID, exposureNumber, userID, paperID, paperFilterID,
                    enlargerLensID, enlargerID, fileID, aperture, ndFilter, headHeight, exposureTime, printType, size, notes)
                    VALUES (:printID, :filmID, :exposureNumber, :userID, :paperID,
                    :paperFilterID, :enlargerLensID, :enlargerID, :fileID, :aperture, :ndFilter, :headHeight, :exposureTime,
                    :printType, :size, :notes)""")
                insert(
                    connection,
                    qry,
                    "Print",
                    printID=printID,
                    filmID=filmID,
                    userID=userID,
                    fileID=fileID,
                    exposureNumber=form.exposureNumber.data,
                    paperID=zero_to_none(form.paperID.data),
                    paperFilterID=zero_to_none(form.paperFilterID.data),
                    enlargerLensID=zero_to_none(form.enlargerLensID.data),
                    enlargerID=zero_to_none(form.enlargerID.data),
                    aperture=form.aperture.data,
                    ndFilter=form.ndFilter.data,
                    headHeight=form.headHeight.data,
                    exposureTime=functions.time_to_seconds(
                        form.exposureTime.data),
                    #exposureTime=form.exposureTime.data,
                    printType=form.printType.data,
                    size=form.size.data,
                    notes=form.notes.data)
                transaction.commit()
                return redirect('/binders/' + str(binderID) + '/projects/' +
                                str(projectID) + '/films/' + str(filmID) +
                                '/prints')

    film = functions.get_film_details(connection, binderID, projectID, filmID)
    qry = text("""SELECT printID, exposureNumber, Papers.name AS paperName,
        PaperDevelopers.name AS paperDeveloperName,
        PaperDevelopers.dilution AS paperDeveloperDilution,
        Papers.paperID, PaperFilters.paperFilterID, PaperFilters.name AS paperFilterName,
        EnlargerLenses.enlargerLensID, EnlargerLenses.name AS enlargerLensName,
        Enlargers.enlargerID, Enlargers.name AS enlargerName,
        printType, size, aperture, ndFilter, headHeight, Prints.notes, fileID,
        SECONDS_TO_DURATION(exposureTime) AS exposureTime
        FROM Prints
        LEFT OUTER JOIN Papers ON Papers.paperID = Prints.paperID
            AND Papers.userID = Prints.userID
        LEFT OUTER JOIN PaperDevelopers ON PaperDevelopers.paperDeveloperID = Prints.paperDeveloperID
        LEFT OUTER JOIN PaperFilters ON PaperFilters.paperFilterID = Prints.paperFilterID
        LEFT OUTER JOIN EnlargerLenses ON EnlargerLenses.enlargerLensID = Prints.enlargerLensID
            AND EnlargerLenses.userID = Prints.userID
        LEFT OUTER JOIN Enlargers ON Enlargers.enlargerID = Prints.enlargerID
            AND Enlargers.userID = Prints.userID
        WHERE Prints.userID = :userID
        AND Prints.printID = :printID""")
    print_details = connection.execute(qry, userID=userID,
                                       printID=printID).fetchone()
    transaction.commit()
    form = PrintForm(data=print_details)
    form.populate_select_fields(connection, filmID)
    return render_template('darkroom/print.html',
                           form=form,
                           film=film,
                           binderID=binderID,
                           projectID=projectID,
                           printID=printID,
                           print_details=print_details,
                           view='prints')
Beispiel #7
0
def user_prints(binderID, projectID, filmID):
    """ Manage user's prints for a film """
    connection = engine.connect()
    transaction = connection.begin()
    userID = current_user.get_id()
    form = PrintForm()
    form.populate_select_fields(connection, filmID)

    if request.method == 'POST':
        if request.form['button'] == 'addPrint':
            if form.validate_on_submit():
                nextPrintID = functions.next_id(connection, 'printID',
                                                'Prints')
                log("Next Print ID: %s" % nextPrintID)
                # If user included a file, let's upload it. Otherwise skip it.
                if form.file.data:
                    nextFileID = functions.next_id(connection, 'fileID',
                                                   'Files')
                    files.upload_file(request, connection, transaction,
                                      nextFileID)
                else:
                    nextFileID = None

                qry = text("""INSERT INTO Prints
                    (printID, paperDeveloperID, filmID, exposureNumber, userID, paperID, paperFilterID,
                    enlargerLensID, enlargerID, fileID, aperture, ndFilter, headHeight, exposureTime, printType, size, notes)
                    VALUES (:printID, :paperDeveloperID, :filmID, :exposureNumber, :userID, :paperID,
                    :paperFilterID, :enlargerLensID, :enlargerID, :fileID, :aperture, :ndFilter, :headHeight, :exposureTime,
                    :printType, :size, :notes)""")
                insert(connection,
                       qry,
                       "Print",
                       printID=nextPrintID,
                       filmID=filmID,
                       userID=userID,
                       fileID=nextFileID,
                       paperDeveloperID=zero_to_none(
                           form.paperDeveloperID.data),
                       exposureNumber=form.exposureNumber.data,
                       paperID=zero_to_none(form.paperID.data),
                       paperFilterID=zero_to_none(form.paperFilterID.data),
                       enlargerLensID=zero_to_none(form.enlargerLensID.data),
                       enlargerID=zero_to_none(form.enlargerID.data),
                       aperture=form.aperture.data,
                       ndFilter=form.ndFilter.data,
                       headHeight=form.headHeight.data,
                       exposureTime=functions.time_to_seconds(
                           form.exposureTime.data),
                       printType=form.printType.data,
                       size=form.size.data,
                       notes=form.notes.data)
    film = functions.get_film_details(connection, binderID, projectID, filmID)

    qry = text("""SELECT printID, exposureNumber,
        PaperDevelopers.name AS paperDeveloperName,
        PaperDevelopers.dilution AS paperDeveloperDilution,
        Papers.name AS paperName,
        PaperFilters.name AS paperFilterName,
        printType, size, aperture, ndFilter, headHeight, Prints.notes, fileID,
        EnlargerLenses.name AS lens,
        Enlargers.name AS enlarger,
        SECONDS_TO_DURATION(exposureTime) AS exposureTime
        FROM Prints
        LEFT OUTER JOIN Papers ON Papers.paperID = Prints.paperID
            AND Papers.userID = Prints.userID
        LEFT OUTER JOIN PaperFilters ON PaperFilters.paperFilterID = Prints.paperFilterID
        LEFT OUTER JOIN PaperDevelopers ON PaperDevelopers.paperDeveloperID = Prints.paperDeveloperID
        LEFT OUTER JOIN EnlargerLenses ON EnlargerLenses.enlargerLensID = Prints.enlargerLensID
            AND EnlargerLenses.userID = Prints.userID
        LEFT OUTER JOIN Enlargers ON Enlargers.enlargerID = Prints.enlargerID
            AND Enlargers.userID = Prints.userID
        WHERE filmID = :filmID AND Prints.userID = :userID""")
    prints = connection.execute(qry, userID=userID, filmID=filmID)

    transaction.commit()
    return render_template('darkroom/prints.html',
                           form=form,
                           binderID=binderID,
                           projectID=projectID,
                           film=film,
                           prints=prints,
                           view='prints')