Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add future default true to Feature flags #7524

Merged
merged 8 commits into from Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/projects/admin.py
Expand Up @@ -366,7 +366,7 @@ class DomainAdmin(admin.ModelAdmin):
class FeatureAdmin(admin.ModelAdmin):
model = Feature
form = FeatureForm
list_display = ('feature_id', 'project_count', 'default_true')
list_display = ('feature_id', 'project_count', 'default_true', 'future_default_true')
search_fields = ('feature_id',)
filter_horizontal = ('projects',)
readonly_fields = ('add_date',)
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/projects/forms.py
Expand Up @@ -722,7 +722,7 @@ class FeatureForm(forms.ModelForm):

class Meta:
model = Feature
fields = ['projects', 'feature_id', 'default_true']
fields = ['projects', 'feature_id', 'default_true', 'future_default_true']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
@@ -0,0 +1,23 @@
# Generated by Django 2.2.16 on 2020-10-16 14:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('projects', '0063_extend_domain_from_timestamp_model'),
]

operations = [
migrations.AddField(
model_name='feature',
name='future_default_true',
field=models.BooleanField(default=False, verbose_name='Default all future projects to True'),
),
migrations.AlterField(
model_name='feature',
name='default_true',
field=models.BooleanField(default=False, verbose_name='Default all past projects to True'),
),
]
8 changes: 7 additions & 1 deletion readthedocs/projects/models.py
Expand Up @@ -1742,8 +1742,14 @@ def add_features(sender, **kwargs):
_('Date feature was added'),
auto_now_add=True,
)
# TODO: rename this field to `past_default_true` and follow this steps when deploying
# https://github.com/readthedocs/readthedocs.org/pull/7524#issuecomment-703663724
default_true = models.BooleanField(
ericholscher marked this conversation as resolved.
Show resolved Hide resolved
_('Historical default is True'),
_('Default all past projects to True'),
default=False,
)
future_default_true = models.BooleanField(
_('Default all future projects to True'),
default=False,
)

Expand Down
3 changes: 2 additions & 1 deletion readthedocs/projects/querysets.py
Expand Up @@ -239,7 +239,8 @@ class FeatureQuerySet(models.QuerySet):
def for_project(self, project):
return self.filter(
Q(projects=project) |
Q(default_true=True, add_date__gt=project.pub_date),
Q(default_true=True, add_date__gt=project.pub_date) |
Q(future_default_true=True, add_date__lt=project.pub_date)
).distinct()


Expand Down
26 changes: 26 additions & 0 deletions readthedocs/rtd_tests/tests/test_project_querysets.py
Expand Up @@ -259,6 +259,32 @@ def test_feature_for_project_is_implicitly_applied(self):
ordered=False,
)

def test_feature_future_default_true(self):
project = fixture.get(Project, main_language_project=None)
# Explicit feature
feature1 = fixture.get(Feature, projects=[project])

# False implicit feature
feature2 = fixture.get(
Feature,
projects=[],
add_date=project.pub_date + timedelta(days=1),
future_default_true=False,
)

# True implicit feature after add date
feature3 = fixture.get(
Feature,
projects=[],
add_date=project.pub_date - timedelta(days=1),
future_default_true=True,
)
self.assertQuerysetEqual(
Feature.objects.for_project(project),
[repr(feature1), repr(feature3)],
ordered=False,
)

def test_feature_multiple_projects(self):
project1 = fixture.get(Project, main_language_project=None)
project2 = fixture.get(Project, main_language_project=None)
Expand Down