Esempio n. 1
0
def log_tasks(user, subject, body):
    details = {'user': user}
    date = parse_date(subject)
    if date:
        details['date'] = date - timedelta(hours=user.timezone)

    for task in parse_body(body):
        details['description'] = task
        Task.create(**details)
    def test_update_task(self):
        """Org admins can't change some tasks."""
        org = Organization.create(name='org')
        org.put()
        user = User.create(email='*****@*****.**',
                           user_type='user',
                           owned_organizations=[org.uid])
        user.put()

        orig_config = organization_tasks.tasklist_template
        organization_tasks.tasklist_template = [{
            'tasks': [{
                'label': 'task_foo',
                'non_admin_may_edit': False,
            }]
        }]

        task = Task.create('task_foo', 1, 'checkpoint_foo', parent=org)
        task.put()

        # Org admin shouldn't be able to mark the task as complete, even though
        # they own the task.
        task.status = 'complete'
        response = self.testapp.put_json('/api/tasks/{}'.format(task.uid),
                                         task.to_client_dict(),
                                         headers=login_headers(user.uid),
                                         status=403)

        organization_tasks.tasklist_template = orig_config
Esempio n. 3
0
    def create_project_task(self, cohort_date=datetime.datetime.today()):
        program_label = 'demo-program'
        task_label = 'task_project_foo'
        project = Project.create(program_label=program_label,
                                 organization_id='Organization_Foo')

        task_template = {
            'label':
            task_label,
            'data_type':
            'radio',
            'select_options': [{
                'value': 'normal',
                'label': 'true names'
            }, {
                'value': 'alias',
                'label': 'aliases'
            }],
        }
        Program.mock_program_config(
            program_label,
            {'project_tasklist_template': [{
                'tasks': [task_template]
            }]})

        t = Task.create(task_label,
                        1,
                        'checkpoint_foo',
                        parent=project,
                        program_label=program_label)
        t.put()
        return t
Esempio n. 4
0
    def test_project_task_body(self):
        """Tasks should get dynamic properties from their definition."""
        program_label = 'demo-program'
        task_label = 'task_foo'
        project = Project.create(program_label=program_label,
                                 organization_id='Organization_Foo')

        task_template = {
            'label': task_label,
            'body': "<p>Demo body.</p>",
        }
        Program.mock_program_config(
            program_label,
            {'project_tasklist_template': [{
                'tasks': [task_template]
            }]})
        t = Task.create(task_label,
                        1,
                        'checkpoint_foo',
                        parent=project,
                        program_label=program_label)
        t_dict = t.to_client_dict()

        self.assertIsInstance(t_dict['body'], basestring)
        self.assertGreater(len(t_dict['body']), 0)
Esempio n. 5
0
    def test_create_select(self):
        program_label = 'demo-program'
        task_label = 'task_foo'
        project = Project.create(program_label=program_label,
                                 organization_id='Organization_Foo')

        task_template = {
            'label':
            task_label,
            'data_type':
            'radio',
            'select_options': [{
                'value': 'normal',
                'label': 'true names'
            }, {
                'value': 'alias',
                'label': 'aliases'
            }],
        }
        Program.mock_program_config(
            program_label,
            {'project_tasklist_template': [{
                'tasks': [task_template]
            }]})

        t = Task.create(task_label,
                        1,
                        'checkpoint_foo',
                        parent=project,
                        program_label=program_label)
        t_dict = t.to_client_dict()
        self.assertEqual(t_dict['select_options'],
                         task_template['select_options'])
Esempio n. 6
0
    def test_org_task_body(self):
        """Tasks should get dynamic properties from their definition."""
        org = Organization.create(name='org')
        org.put()

        orig_config = organization_tasks.tasklist_template
        organization_tasks.tasklist_template = [{
            'tasks': [{
                'label': 'task_foo',
                'body': "<p>Demo body.</p>",
            }]
        }]

        t = Task.create('task_foo', 1, 'checkpoint_foo', parent=org)
        t_dict = t.to_client_dict()

        self.assertIsInstance(t_dict['body'], basestring)
        self.assertGreater(len(t_dict['body']), 0)

        organization_tasks.tasklist_template = orig_config
Esempio n. 7
0
def submit():
    user = check_session()
    if user is None:
        return Response(response="unauthorized",
                        status=401,
                        mimetype="text/plain")

    content = request.json
    app.logger.info('submit %s %s', user.email, content['language'])

    challenge = next(x for x in CHALLENGES
                     if x.identifier == content['challenge'])

    identifier = str(uuid.uuid4())
    task = Task.create(uuid=identifier,
                       user=user,
                       state='reset',
                       challenge=challenge.identifier)
    task.max = challenge.max

    write_file(task.answer, content['answer'])

    meta = {
        "email": user.email,
        "language": content['language'],
    }

    write_file(task.meta, json.dumps(meta))

    task.state = 'todo'
    task.save()

    response = {'result': 'OK', 'task': task.json}
    return Response(response=json.dumps(response),
                    status=200,
                    mimetype="application/json")