Exemplo n.º 1
0
    def get(self, template, context_id):
        # Attempt to treat id as as project cohort (it might be a program, or
        # invalid).
        project_cohort = ProjectCohort.get_by_id(context_id)

        def todt(s):
            return datetime.datetime.strptime(s, config.iso_date_format)

        if project_cohort:
            # This is a "real" set of instructions with data filled in.
            organization = Organization.get_by_id(
                project_cohort.organization_id)
            liaison = User.get_by_id(organization.liaison_id)
            program = Program.get_config(project_cohort.program_label)
            cohort = program['cohorts'][project_cohort.cohort_label]
            participation_open_date = todt(cohort['open_date'])
            # See notes in program config for why we take a day off for display.
            participation_close_date = (todt(cohort['close_date']) -
                                        datetime.timedelta(1))
        else:
            # This is a generic example version of the document.
            try:
                program = Program.get_config(context_id)
            except ImportError:
                return self.http_not_found()
            organization = None
            liaison = None
            project_cohort = None
            cohort = None
            participation_open_date = None
            participation_close_date = None

        if template == 'custom_portal_technical_guide':
            # This template doesn't vary by program.
            template_filename = '{}.html'.format(template)
        else:
            template_filename = '{}_{}.html'.format(program['label'], template)

        self.write(
            template_filename,
            organization=organization,
            liaison=liaison,
            program_name=program['name'],
            cohort_name=cohort['name'] if cohort else '',
            program_description=program['description'],
            project_cohort=project_cohort,
            participation_open_date=participation_open_date,
            participation_close_date=participation_close_date,
        )
    def test_join_cohort(self, cohort_date=datetime.date.today()):
        """Allowed for org admin owner of project."""

        # Existing things to relate to.
        program_label = 'demo-program'
        cohort_label = 'demo-cohort'
        program = Program.get_config(program_label)
        org_id = 'Org_Foo'
        user = User.create(email="*****@*****.**",
                           owned_organizations=[org_id])
        project = Project.create(organization_id=org_id,
                                 program_label=program_label)
        user.put()
        project.put()

        # Guarantee the dates will work by mocking the cohort config.
        one_day = datetime.timedelta(days=1)
        cohort_config = {
            'label': cohort_label,
            'name': 'Demo Cohort',
            'open_date': str(cohort_date - one_day),  # yesterday
            'close_date': str(cohort_date + one_day),  # tomorrow
        }
        program['cohorts'][cohort_label] = cohort_config
        Program.mock_program_config(
            program_label,
            {'cohorts': {cohort_label: cohort_config}},
        )

        # Create the project cohort through the api. Any response other than
        # 200 will fail the test.
        response = self.testapp.post_json(
            '/api/project_cohorts',
            {
                'project_id': project.uid,
                'organization_id': org_id,
                'program_label': program_label,
                'cohort_label': cohort_label,
                'liaison_id': user.uid,
            },
            headers=login_headers(user.uid)
        )
        response_dict = json.loads(response.body)

        return (ProjectCohort.get_by_id(response_dict['uid']), user)
Exemplo n.º 3
0
    def test_update_project_cohort(self):
        org, project, pc, checkpoint = self.create_with_project_cohort()

        # Now changing the status should update the cached properties of the
        # project cohort.
        checkpoint.status = 'waiting'
        checkpoint.put()

        fetched = ProjectCohort.get_by_id(pc.uid)
        # There should be one survey checkpoint that was changed
        fetched_checkpoint = [
            c for c in fetched.get_cached_properties()['checkpoints']
            if c.parent_kind == 'Survey'
        ][0]

        self.assertEqual(
            fetched_checkpoint.status,
            'waiting',
        )
Exemplo n.º 4
0
def downloaded_identifiers(user, project_cohort_id):
    supers = User.get(user_type='super_admin')
    notes = []

    project_cohort = ProjectCohort.get_by_id(project_cohort_id)
    organization = Organization.get_by_id(project_cohort.organization_id)
    program = Program.get_config(project_cohort.program_label)
    cohort_name = program['cohorts'][project_cohort.cohort_label]['name']

    for sup in supers:
        note = Notification.create(
            parent=sup,
            context_id=project_cohort_id,
            subject="IDs Downloaded",
            body=u"{} ({}) downloaded IDs for {}: {} {}.".format(
                user.name, user.email, organization.name, program['name'],
                cohort_name),
            link='/dashboard/{}'.format(project_cohort.short_uid),
            autodismiss=True,
        )
        notes.append(note)
    ndb.put_multi(notes)
Exemplo n.º 5
0
def add_completed_report_task_ids_to_project_cohort(task):
    """See Issue #1020 & PR #1062. In order to facilitate creating the
    Returning Organizations report, we need to know which Project Cohorts
    are returning. Returning is defined as an Organization that has
    participated in a previous cohort and has enrolled again. We are counting
    Project Cohorts as having participated if they have a completed report
    uploaded. This job adds the UID of report tasks that have a file attached
    to the associated Project Cohort's completed_report_task_ids property."""

    report_task_labels = [
        'cg17_survey__report_1', 'cb17_survey__report_1',
        'hg17_survey__report_2', 'sse_survey__report_1'
    ]

    if task.label in report_task_labels and task.attachment:
        parent_key = task.key.parent()
        survey = parent_key.get()
        project_cohort = ProjectCohort.get_by_id(survey.project_cohort_id)

        if (project_cohort
                and task.uid not in project_cohort.completed_report_task_ids):
            project_cohort.completed_report_task_ids.append(task.uid)
            yield op.db.Put(project_cohort)