Skip to content

Commit

Permalink
Merge branch 'feature/prereg-winddown' into winddown-waffle-the-rest
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnetordoff committed Dec 3, 2018
2 parents a07393c + b63ff29 commit a84f7ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
5 changes: 2 additions & 3 deletions osf/migrations/0144_add_prereg_winddown_switches.py
Expand Up @@ -4,7 +4,7 @@
from django.db import migrations

from osf import features
from osf.utils.migrations import AddWaffleSwitch
from osf.utils.migrations import AddWaffleSwitches


class Migration(migrations.Migration):
Expand All @@ -14,6 +14,5 @@ class Migration(migrations.Migration):
]

operations = [
AddWaffleSwitch(features.ENABLE_INACTIVE_SCHEMAS, active=False),
AddWaffleSwitch(features.OSF_PREREGISTRATION, active=False)
AddWaffleSwitches([features.ENABLE_INACTIVE_SCHEMAS, features.OSF_PREREGISTRATION], active=False),
]
10 changes: 5 additions & 5 deletions osf/migrations/0146_update_registration_schemas.py
Expand Up @@ -6,15 +6,15 @@
from osf.utils.migrations import UpdateRegistrationSchemas

V2_INVISIBLE_SCHEMAS = [
'RIDIE Registration - Study Complete',
'RIDIE Registration - Study Initiation',
'EGAP Project',
'OSF Preregistration',
'Confirmatory - General',
'RIDIE Registration - Study Complete',
'RIDIE Registration - Study Initiation',
]

V2_INACTIVE_SCHEMAS = [
V2_INACTIVE_SCHEMAS = V2_INVISIBLE_SCHEMAS + [
'Election Research Preacceptance Competition',
'OSF Preregistration',
]

def remove_version_1_schemas(state, schema):
Expand All @@ -25,7 +25,7 @@ def remove_version_1_schemas(state, schema):

def update_v2_schemas(state, schema):
RegistrationSchema = state.get_model('osf', 'registrationschema')
RegistrationSchema.objects.filter(name__in=V2_INVISIBLE_SCHEMAS).update(visible=False, active=False)
RegistrationSchema.objects.filter(name__in=V2_INVISIBLE_SCHEMAS).update(visible=False)
RegistrationSchema.objects.filter(name__in=V2_INACTIVE_SCHEMAS).update(active=False)

def noop(*args, **kwargs):
Expand Down
22 changes: 12 additions & 10 deletions osf/utils/migrations.py
Expand Up @@ -2,6 +2,7 @@
import itertools
import json
import logging
import warnings

from contextlib import contextmanager
from django.apps import apps
Expand Down Expand Up @@ -175,7 +176,7 @@ def database_forwards(self, app_label, schema_editor, from_state, to_state):
ensure_schemas(to_state.apps)

def database_backwards(self, app_label, schema_editor, from_state, to_state):
logger.info('Reversing UpdateRegistrationSchemas is a noop')
warnings.warn('Reversing UpdateRegistrationSchemas is a noop')

def describe(self):
return 'Updated registration schemas'
Expand Down Expand Up @@ -237,29 +238,30 @@ def describe(self):
return 'Removes waffle flags: {}'.format(', '.join(self.flag_names))


class AddWaffleSwitch(Operation):
"""Custom migration operation to add a waffle switch
class AddWaffleSwitches(Operation):
"""Custom migration operation to add waffle switches
Params:
- name: string, the name of the switch to create
- active: boolean (default False), whether the switch should be active
- switch_names: iterable of strings, the names of the switches to create
- active: boolean (default False), whether the switches should be active
"""
reversible = True

def __init__(self, name, active=False):
self.name = name
def __init__(self, switch_names, active=False):
self.switch_names = switch_names
self.active = active

def state_forwards(self, app_label, state):
pass

def database_forwards(self, app_label, schema_editor, from_state, to_state):
Switch = to_state.apps.get_model('waffle', 'switch')
Switch.objects.get_or_create(name=self.name, active=self.active)
for switch in self.switch_names:
Switch.objects.get_or_create(name=switch, defaults={'active': self.active})

def database_backwards(self, app_label, schema_editor, from_state, to_state):
Switch = to_state.apps.get_model('waffle', 'switch')
Switch.objects.filter(name=self.name).delete()
Switch.objects.filter(name__in=self.switch_names).delete()

def describe(self):
return 'Adds waffle switch: {}'.format(self.name)
return 'Adds waffle switches: {}'.format(', '.join(self.switch_names))
2 changes: 2 additions & 0 deletions scripts/remove_after_use/end_prereg_challenge.py
Expand Up @@ -27,6 +27,8 @@ def main(dry_run=True):
prereg_schema = RegistrationSchema.objects.get(name='OSF Preregistration')
logger.info('Setting {} schema to active'.format(prereg_schema.name))
prereg_schema.active = True
logger.info('Setting {} schema to visible'.format(prereg_schema.name))
prereg_schema.visible = True
if dry_run:
logger.warn('This is a dry run')
else:
Expand Down

0 comments on commit a84f7ea

Please sign in to comment.