Exemplo n.º 1
0
def contest_import_from_dict(cls, data):
    """Build the object using data from a dictionary.

    """
    data['tasks'] = [Task.import_from_dict(task_data)
                     for task_data in data['tasks']]
    tasks_by_name = dict(map(lambda x: (x.name, x), data['tasks']))
    data['users'] = [User.import_from_dict(user_data,
                                           tasks_by_name=tasks_by_name)
                     for user_data in data['users']]
    data['announcements'] = [Announcement.import_from_dict(ann_data)
                             for ann_data in data['announcements']]
    if 'start' in data and data['start'] is not None:
        data['start'] = make_datetime(data['start'])
    if 'stop' in data and data['stop'] is not None:
        data['stop'] = make_datetime(data['stop'])
    if 'token_min_interval' in data:
        data['token_min_interval'] = \
            timedelta(seconds=data['token_min_interval'])
    if 'token_gen_time' in data:
        data['token_gen_time'] = timedelta(minutes=data['token_gen_time'])
    if 'per_user_time' in data and data['per_user_time'] is not None:
        data['per_user_time'] = timedelta(seconds=data['per_user_time'])
    if 'min_submission_interval' in data and \
            data['min_submission_interval'] is not None:
        data['min_submission_interval'] = \
            timedelta(seconds=data['min_submission_interval'])
    if 'min_usertest_interval' in data and \
            data['min_usertest_interval'] is not None:
        data['min_usertest_interval'] = \
            timedelta(seconds=data['min_usertest_interval'])
    return cls(**data)
Exemplo n.º 2
0
def contest_import_from_dict(cls, data):
    """Build the object using data from a dictionary.

    """
    data['tasks'] = [Task.import_from_dict(task_data)
                     for task_data in data['tasks']]
    tasks_by_name = dict(map(lambda x: (x.name, x), data['tasks']))
    data['users'] = [User.import_from_dict(user_data,
                                           tasks_by_name=tasks_by_name)
                     for user_data in data['users']]
    data['announcements'] = [Announcement.import_from_dict(ann_data)
                             for ann_data in data['announcements']]
    if data['ranking_view'] is not None:
        data['ranking_view'] = RankingView.import_from_dict(
            data['ranking_view'],
            tasks_by_name=tasks_by_name,
            users=data['users'])
    return cls(**data)