示例#1
0
    def get_object(self):
        if self.kwargs.get("id") == "my-barriers":
            return get_my_barriers_saved_search(self.request.user)

        if self.kwargs.get("id") == "team-barriers":
            return get_team_barriers_saved_search(self.request.user)

        return super().get_object()
示例#2
0
def mark_user_saved_searches_as_notified(user):
    """
    Mark all of a user's saved searches as notified.

    We need to do this regardless of if the user has actually been notified, so that if
    they switch notifications on, we know what barriers were previously in the search.
    """
    my_barriers = get_my_barriers_saved_search(user)
    my_barriers.mark_as_notified()

    team_barriers = get_team_barriers_saved_search(user)
    team_barriers.mark_as_notified()

    for saved_search in user.saved_searches.all():
        saved_search.mark_as_notified()
示例#3
0
    def update_saved_search_if_required(self):
        search_id = self.request.GET.get("search_id")
        query_dict = self.request.query_params.dict()

        if search_id:
            saved_search = self.get_saved_search(search_id)
            if saved_search and saved_search.are_api_parameters_equal(query_dict):
                saved_search.mark_as_seen()

        if self.is_my_barriers_search():
            saved_search = get_my_barriers_saved_search(self.request.user)
            if saved_search.are_api_parameters_equal(query_dict):
                saved_search.mark_as_seen()

        if self.is_team_barriers_search():
            saved_search = get_team_barriers_saved_search(self.request.user)
            if saved_search.are_api_parameters_equal(query_dict):
                saved_search.mark_as_seen()
示例#4
0
def get_saved_searches_for_notification(user):
    """
    Get saved searches where there have been changes and user has asked to be notified.
    """
    my_barriers = get_my_barriers_saved_search(user)
    team_barriers = get_team_barriers_saved_search(user)

    saved_searches = []

    if my_barriers.should_notify():
        saved_searches.append(my_barriers)

    if team_barriers.should_notify():
        saved_searches.append(team_barriers)

    for saved_search in user.saved_searches.all():
        if saved_search.should_notify():
            saved_searches.append(saved_search)

    return saved_searches