Skip to content

Commit

Permalink
determine public data based on config value #312
Browse files Browse the repository at this point in the history
  • Loading branch information
VKTB committed Feb 8, 2022
1 parent 58e777b commit 1021c80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 9 additions & 4 deletions datagateway_api/src/search_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic import BaseModel, Field, ValidationError, validator
from pydantic.error_wrappers import ErrorWrapper

from datagateway_api.src.common.config import Config
from datagateway_api.src.common.date_handler import DateHandler
from datagateway_api.src.search_api.panosc_mappings import mappings

Expand Down Expand Up @@ -197,8 +198,10 @@ def set_is_public(cls, value): # noqa: B902, N805

creation_date = DateHandler.str_to_datetime_object(value)
current_datetime = datetime.now(timezone.utc)
three_years_ago = current_datetime - relativedelta(years=3)
return creation_date < three_years_ago
rd = relativedelta(
years=Config.config.search_api.num_of_years_determining_public_data,
)
return creation_date < (current_datetime - rd)

@classmethod
def from_icat(cls, icat_data, required_related_fields):
Expand Down Expand Up @@ -236,8 +239,10 @@ def set_is_public(cls, value): # noqa: B902, N805

creation_date = DateHandler.str_to_datetime_object(value)
current_datetime = datetime.now(timezone.utc)
three_years_ago = current_datetime - relativedelta(years=3)
return creation_date < three_years_ago
rd = relativedelta(
years=Config.config.search_api.num_of_years_determining_public_data,
)
return creation_date < (current_datetime - rd)

@classmethod
def from_icat(cls, icat_data, required_related_fields):
Expand Down
9 changes: 6 additions & 3 deletions datagateway_api/src/search_api/query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dateutil.relativedelta import relativedelta

from datagateway_api.src.common.base_query_filter_factory import QueryFilterFactory
from datagateway_api.src.common.config import Config
from datagateway_api.src.common.exceptions import FilterError, SearchAPIError
from datagateway_api.src.search_api.filters import (
SearchAPIIncludeFilter,
Expand Down Expand Up @@ -361,16 +362,18 @@ def convert_is_public_field_value_and_operation(value, operation):
so that all Datasets older than 3 years (which ISIS considers public) are
returned.
"""
current_datetime = datetime.now(timezone.utc)
three_years_ago = current_datetime - relativedelta(years=3)
value = not value if operation == "neq" else value
if value is True:
operation = "lt"
else:
operation = "gt"

current_datetime = datetime.now(timezone.utc)
rd = relativedelta(
years=Config.config.search_api.num_of_years_determining_public_data,
)
# The timezone part has a plus sign so replacing
# with a blank space to avoid issues
value = str(three_years_ago).replace("+", " ")
value = str(current_datetime - rd).replace("+", " ")

return value, operation

0 comments on commit 1021c80

Please sign in to comment.