def __get_release_according_to_filters_and_order_by_for_date_sort( org, filter_params, date_query_q, order_by, ): """ Helper function that executes a query on Release table based on different filters provided as inputs and orders that query based on `order_by` input provided Inputs:- * org: Organization object * filter_params: * order_by: Contains columns that are used for ordering to sort based on date Returns:- Queryset that contains one element that represents either next or previous release based on the inputs """ queryset = Release.objects.filter( date_query_q, organization=org, projects__id__in=filter_params["project_id"], ) # Add env filter queryset = add_environment_to_queryset(queryset, filter_params) # Orderby passed cols and limit to 1 queryset = queryset.order_by(*order_by)[:1] return queryset
def __get_top_of_queryset_release_version_based_on_order_by( org, proj_and_env_dict, order_by): """ Helper function that executes a query on Release table orders that query based on `order_by` input provided Inputs:- * org: Organization object * proj_and_env_dict: contains only two keys project_id and environment * order_by: Contains columns that are used for ordering to sort based on date Returns:- Release version of the top element of the queryset returned through ordering the Release table by the order_by input """ queryset = Release.objects.filter( organization=org, projects__id__in=proj_and_env_dict["project_id"]) queryset = add_environment_to_queryset(queryset, proj_and_env_dict) return queryset.order_by(*order_by).first().version