diff --git a/django/core/models.py b/django/core/models.py index cbe41e939..ecd33019a 100644 --- a/django/core/models.py +++ b/django/core/models.py @@ -538,7 +538,9 @@ def get_expired_q(self): started less than 2 days ago """ now = timezone.now().date() - start_date_threshold = now - timedelta(days=Event.EXPIRED_EVENT_DAYS_THRESHOLD) + start_date_threshold = now - timedelta( + days=settings.EXPIRED_EVENT_DAYS_THRESHOLD + ) return models.Q(start_date__lt=start_date_threshold) | models.Q( end_date__lt=now, end_date__isnull=False ) @@ -557,7 +559,6 @@ def public(self): @add_to_comses_permission_whitelist class Event(index.Indexed, ClusterableModel): - EXPIRED_EVENT_DAYS_THRESHOLD = 2 title = models.CharField(max_length=300) date_created = models.DateTimeField(default=timezone.now) last_modified = models.DateTimeField(auto_now=True) @@ -656,11 +657,12 @@ def upcoming(self, **kwargs): def get_expired_q(self): """ returns a Q object for all Jobs with a non-null application deadline before today or - posted/modified in the last [POST_DATE_DAYS_AGO_TRESHOLD] days if application deadline is null + posted/modified in the last [settings.EXPIRED_JOB_DAYS_THRESHOLD] days if + application deadline is null """ today = timezone.now() - post_date_days_ago_threshold = settings.POST_DATE_DAYS_AGO_THRESHOLD - post_date_threshold = today - timedelta(days=post_date_days_ago_threshold) + threshold = settings.EXPIRED_JOB_DAYS_THRESHOLD + post_date_threshold = today - timedelta(days=threshold) return models.Q( application_deadline__isnull=False, application_deadline__lt=today ) | models.Q( diff --git a/django/core/settings/defaults.py b/django/core/settings/defaults.py index dfaaf95bd..d01283527 100644 --- a/django/core/settings/defaults.py +++ b/django/core/settings/defaults.py @@ -266,12 +266,16 @@ def is_test(self): # regular settings -POST_DATE_DAYS_AGO_THRESHOLD = config.getint( - "default", "POST_DATE_DAYS_AGO_THRESHOLD", fallback=180 +EXPIRED_JOB_DAYS_THRESHOLD = config.getint( + "default", "EXPIRED_JOB_DAYS_THRESHOLD", fallback=180 +) + +EXPIRED_EVENT_DAYS_THRESHOLD = config.getint( + "default", "EXPIRED_EVENT_DAYS_THRESHOLD", fallback=2 ) # Database configuration -# https://docs.djangoproject.com/en/3.2/ref/settings/#databases +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases DEFAULT_AUTO_FIELD = "django.db.models.AutoField" @@ -530,7 +534,7 @@ def is_test(self): "discourse", "DISCOURSE_API_USERNAME", fallback="unconfigured" ) -# https://docs.djangoproject.com/en/3.2/ref/settings/#templates +# https://docs.djangoproject.com/en/4.2/ref/settings/#templates TEMPLATES = [ { "BACKEND": "django.template.backends.jinja2.Jinja2", diff --git a/django/core/tests/test_models.py b/django/core/tests/test_models.py index 119b12c4b..47dc484c4 100644 --- a/django/core/tests/test_models.py +++ b/django/core/tests/test_models.py @@ -17,7 +17,7 @@ def setUp(self): self.job_factory = JobFactory(submitter=self.user) today = timezone.now() - self.threshold = settings.POST_DATE_DAYS_AGO_THRESHOLD + self.threshold = settings.EXPIRED_JOB_DAYS_THRESHOLD # active jobs self.active_job = self.job_factory.create( @@ -123,7 +123,7 @@ def setUp(self): end_date=None, title="No End Date Current Event", ) - for threshold in range(Event.EXPIRED_EVENT_DAYS_THRESHOLD) + for threshold in range(settings.EXPIRED_EVENT_DAYS_THRESHOLD) ] # expired events @@ -132,11 +132,12 @@ def setUp(self): end_date=now - timedelta(days=7), title="Expired Event", ) + expired_days_threshold = settings.EXPIRED_EVENT_DAYS_THRESHOLD + 1 sample_expired_event_thresholds = set( - random.sample(range(Event.EXPIRED_EVENT_DAYS_THRESHOLD + 1, 365), 10) + random.sample(range(expired_days_threshold, 365), 10) ) sample_expired_event_thresholds.add( - Event.EXPIRED_EVENT_DAYS_THRESHOLD + 1 + expired_days_threshold ) # always test the edge self.no_end_date_expired_events = [ self.event_factory.create(