Skip to content
Snippets Groups Projects
Commit d89e2b6e authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Community labs should get migrated as labs and not funds.

parent c99d25ac
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ from django_fsm import FSMField
from opentech.apply.categories.models import Category, Option
from opentech.apply.categories.categories_seed import CATEGORIES
from opentech.apply.funds.models import ApplicationSubmission, FundType, Round, RoundForm
from opentech.apply.funds.models import ApplicationSubmission, LabType, LabForm
from opentech.apply.funds.workflow import INITIAL_STATE
User = get_user_model()
......@@ -135,9 +135,8 @@ STREAMFIELD_MAP = {
},
}
FUND = FundType.objects.get(title='Community lab')
ROUND = Round.objects.get(title='Community lab open round')
FORM = RoundForm.objects.get(round=ROUND)
LAB = LabType.objects.get(title='Community lab')
FORM = LabForm.objects.get(lab=LAB)
# Monkey patch the status field so it is no longer protected
patched_status_field = FSMField(default=INITIAL_STATE, protected=False)
......@@ -178,8 +177,7 @@ class Command(BaseCommand):
submission.submit_time = datetime.fromtimestamp(int(node['created']), timezone.utc)
submission.user = self.get_user(node['uid'])
submission.page = FUND
submission.round = ROUND
submission.page = LAB
submission.form_fields = FORM.form.form_fields
submission.status = self.get_workflow_state(node)
......
......@@ -6,26 +6,18 @@ from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand
from django.db import transaction
from opentech.apply.funds.models import ApplicationForm, FundForm, FundType, Round
from opentech.apply.funds.models import ApplicationForm, LabForm, LabType
from opentech.apply.home.models import ApplyHomePage
from opentech.apply.users.groups import STAFF_GROUP_NAME
CL_ROUND_TITLE = 'Community lab open round'
class Command(BaseCommand):
help = "Pre-seeds the Community lab application form and fund type. Depends on the categories seed being run first."
help = "Pre-seeds the Community lab application form and lab type. Depends on the categories seed being run first."
@transaction.atomic
def handle(self, *args, **options):
# There's an Community lab open round, so bail out. Avoids duplicate command runs.
if Round.objects.filter(title=CL_ROUND_TITLE).count():
self.stdout.write(self.style.WARNING('Skipping. The target Round/Fund Type and Application Form exist'))
return
application_form = self.create_community_lab_form()
fund = self.create_community_lab_fund_type(application_form)
self.create_community_lab_round(fund)
self.create_community_lab_fund_type(application_form)
def create_community_lab_form(self):
......@@ -68,21 +60,6 @@ class Command(BaseCommand):
return application_form
def create_community_lab_fund_type(self, application_form):
try:
fund = FundType.objects.get(title='Community lab')
except FundType.DoesNotExist:
apply_home = ApplyHomePage.objects.first()
fund = FundType(title='Community lab', workflow_name='single')
apply_home.add_child(instance=fund)
fund_form = FundForm.objects.create(fund=fund, form=application_form)
fund.forms = [fund_form]
fund.save()
return fund
def create_community_lab_round(self, fund):
User = get_user_model()
try:
......@@ -90,12 +67,16 @@ class Command(BaseCommand):
except User.DoesNotExist:
lead = User.objects.filter(groups__name=STAFF_GROUP_NAME).first()
round = Round(
title=CL_ROUND_TITLE,
lead=lead,
# The date of the original Community lab request type
start_date=date(2015, 8, 28),
end_date=None
)
round.parent_page = fund
fund.add_child(instance=round)
try:
lab = LabType.objects.get(title='Community lab')
except LabType.DoesNotExist:
apply_home = ApplyHomePage.objects.first()
lab = LabType(title='Community lab', lead=lead, workflow_name='single')
apply_home.add_child(instance=lab)
lab_form = LabForm.objects.create(lab=lab, form=application_form)
lab.forms = [lab_form]
lab.save()
return lab
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment