コード例 #1
0
 def _get_basket_db_item(self, basket_id):
     if self._is_mixed_species():
         basket_q = CatchAdditionalBaskets.get(
             CatchAdditionalBaskets.catch_addtl_baskets == basket_id)
     else:
         basket_q = SpeciesCompositionBaskets.get(
             SpeciesCompositionBaskets.species_comp_basket == basket_id)
     return basket_q
コード例 #2
0
 def remove_an_additional_unweighed_full_basket(self):
     """
     Use in Weight Method 3 data entry to reduce the tally of unweighed baskets by one.
     
     Remove one unweighed catch additional basket. Since the only purpose of these entries is to maintain
     a tally of unweighed baskets, and there's no data of interest other than the basket_type being unweighed,
     the implementation may remove any unweighed entry.
     
     Should not be called if no unweighed baskets are present, but in that case doesn't throw exception -
     just logs error message and returns.
     :return: 
     """
     try:
         # Get the first (earliest?) record for this catch with an unweighed basket type.
         basket_q = CatchAdditionalBaskets.get(
                 (CatchAdditionalBaskets.catch == self._current_catch.catch) &
                 (CatchAdditionalBaskets.basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_UNWEIGHED_FULL))
         basket_q.delete_instance()
         self._logger.debug(
                 f"WM3: Deleted an unweighed catch additional basket for Catch ID {self._current_catch.catch}.")
     except CatchAdditionalBaskets.DoesNotExist:
         self._logger.error("WM3: No unweighed baskets to remove.")
コード例 #3
0
    def remove_additional_basket(self, basket_id):
        """
        While this method can be used for either weighed or unweighed (tally) baskets, it's intended for use
        with weighed baskets. With unweighed baskets, any entry can be removed - it doesn't matter which -
        so it's easier to use remove_an_additional_unweighed_full_basket() (no basket id needed).
        
        :param basket_id: 
        :return: None
        """
        if not basket_id:
            self._logger.error(f"Passed a null id for CatchAdditionalBaskets. Taking no action.")
            return

        if self._weight_method != '3':
            msg = f"Weight Method is '{self._weight_method}', not '3'; removing additional baskets not allowed."
            self._logger.error(msg)
            raise Exception(msg)

        try:
            basket_q = CatchAdditionalBaskets.get(CatchAdditionalBaskets.catch_addtl_baskets == basket_id)
            basket_q.delete_instance()
            self._logger.debug(f"Deleted catch additional basket ID {basket_id} from database.")

            # Remove from view model - if a weighed basket. Unweighed baskets aren't added to view,
            # so won't be found here (i.e. idx < 0).
            idx = self._catch_additional_baskets_view_model.get_item_index('catch_addtl_baskets', basket_id)
            if idx >= 0:
                self._catch_additional_baskets_view_model.remove(idx)
                self._logger.debug(f"Deleted catch additional weighed basket ID {basket_id} from view model.")
            else:
                if basket_q.basket_type in (ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_WEIGHED_PARTIAL,
                                            ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_WEIGHED_FULL):
                    self._logger.error(f"Error looking up catch additional basket ID {basket_id} in view model")
            return
        except CatchAdditionalBaskets.DoesNotExist as e:
            self._logger.error(e)
            return
コード例 #4
0
    def _edit_additional_basket(self, basket_id, basket_weight: float, basket_type: int=None):
        """
        Change one or more non-null fields of an entry in CATCH_ADDITIONAL_BASKETS.
        Since all fields whose change is supported are non-nullable, a value of None indicates:
        don't change field.
        Changes to fields created_date and created_by are not supported - no need as yet.
        
        :param basket_id: Primary key to CATCH_ADDITIONAL_BASKETS
        :param basket_weight: as a float
        :param basket_type: as an integer
        :return: 
        """
        if not basket_id:
            self._logger.error(f"Passed a null id for CatchAdditionalBaskets. Taking no action.")
            return

        if basket_weight is None and basket_type is None:
            self._logger.info(f"Neither basket_weight nor basket_type specified. Taking no action.")
            return

        if self._weight_method != '3':
            msg = f"Weight Method is '{self._weight_method}', not '3';" \
                  f"editing additional baskets not allowed."
            self._logger.error(msg)
            raise Exception(msg)

        # Consistency check: if requested basket type is unweighed,
        # requested basket weight should be 0 or None
        if basket_type == ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_UNWEIGHED_FULL and \
                basket_weight is not None and basket_weight != 0.0:
            msg = f"Basket type unweighed should have no or zero basket weight."
            self._logger.error(f"Basket type unweighed should have no or zero basket weight.")
            raise Exception(msg)

        try:
            basket_q = CatchAdditionalBaskets.get(CatchAdditionalBaskets.catch_addtl_baskets == basket_id)
            weight_modified_msg = ""
            type_modified_msg = ""
            if basket_weight is not None:
                basket_q.basket_weight = basket_weight
                weight_modified_msg = f"Weight={basket_weight}"
            if basket_type is not None:
                # Note: Changing a basket from unweighed to weighed or vice versa is not allowed.
                basket_q.basket_type = basket_type  # DB type is integer
                type_modified_msg = f"Basket Type={basket_type}"
            basket_q.save()
            self._logger.debug(f"Updates to catch additional basket ID {basket_id}: " +
                               weight_modified_msg + " " + type_modified_msg)

            # Update view model containing weighed baskets (full or partial)
            if basket_q.basket_type in (ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_WEIGHED_FULL,
                                        ObserverCatchBaskets.LOOKUP_VALUE_CAB_BASKET_TYPE_WEIGHED_PARTIAL):
                idx = self._catch_additional_baskets_view_model.get_item_index('catch_addtl_baskets',
                                                                               basket_id)
                if idx >= 0:
                    if basket_weight is not None:
                        self._catch_additional_baskets_view_model.setProperty(
                                idx, 'basket_weight', basket_weight)
                        self._logger.debug(f"Basket ID {basket_id}'s view model weight={basket_weight}.")
                    if basket_type is not None:
                        self._catch_additional_baskets_view_model.setProperty(
                                idx, 'basket_type', basket_type)
                        self._logger.debug(f"Basket ID {basket_id}'s view model type="
                                           f"{self._catch_additional_basket_types[basket_type]}.")

        except CatchAdditionalBaskets.DoesNotExist as e:
            self._logger.error(e)