Exemplo n.º 1
0
    def add_to_database(self, appstruct):
        """ Extract the fields from the colander validated dictionary,
        add to the database.
        """
        # Get the user
        user = self.add_user_if_required()

        # Create a checkout with the current calibration data
        now = datetime.datetime.now()
        new_checkout = Checkout(serial=appstruct["serial"],
                                timestamp=now)

        calib = Calibration(calibration_name="wavelength",
                            coefficient_0=appstruct["coefficient_0"],
                            coefficient_1=appstruct["coefficient_1"],
                            coefficient_2=appstruct["coefficient_2"],
                            coefficient_3=appstruct["coefficient_3"])

        # Append this new calibration to the checkouts list of
        # calibrations
        new_checkout.calibrations.append(calib)

        # Append to that users' list of checkouts
        user.checkouts.append(new_checkout)
        DBSession.flush() # required to populate the id field
        return new_checkout.id
Exemplo n.º 2
0
    def file_add_to_database(self, appstruct):
        """ Write the file upload to the database. Append it to the list
        of files for the checkout.
        """
        #log.info("full appstruct: %s", appstruct)
        file_pointer = appstruct["file_upload"]["fp"]
        file_pointer.seek(0)

        filename = appstruct["file_upload"]["filename"]
        filename = self.strip_test_delimiters(filename)

        new_file = File(filename=filename,
                        file_data=file_pointer.read())
        #log.info("Obj: %r", file_pointer)
        log.info("assign: %s", new_file.filename)


        checkout_id = self.request.matchdict["checkout_id"]
        dbqry = DBSession.query(Checkout)
        checkout = dbqry.filter(Checkout.id == checkout_id).one()
        checkout.files.append(new_file)

        DBSession.flush() #required to get checkout id
        return checkout.id