Пример #1
0
    def teams_to_dict(self, teams, members):
        teams_as_dict = {
            team.id: to_dict(team, ['team_name'])
            for team in teams
        }
        for (team_id, team) in teams_as_dict.items():
            teams_as_dict[team_id]['members_count'] = 0

        for member in members:
            team_roles = member.teamRoles.all()
            for teamRole in team_roles:
                teams_as_dict[teamRole.team_id]['members_count'] += 1

        # Add the "All" team special case
        teams_as_dict[-1]['members_count'] = len(members)

        # Remove team without any members
        teams_as_dict = {
            key: val
            for key, val in teams_as_dict.items() if val['members_count'] > 0
        }

        # Sort teams
        teams_as_dict = OrderedDict(
            sorted(teams_as_dict.items(), key=lambda t: t[0]))
        return teams_as_dict
Пример #2
0
    def get_flatten_members_list(self):
        members = Member.objects.prefetch_related(
            'memberextrainfo_set',
            'memberextrainfo_set__info_type').order_by("first_name")

        result = []
        for member in members:
            member_as_dict = to_dict(member)

            member_as_dict['formation'] = str(member.formation)

            # Convert datetime to dates
            member_as_dict['date_joined'] = member_as_dict['date_joined'].date(
            )
            if 'date_left' in member_as_dict and isinstance(
                    member_as_dict['date_left'], datetime):
                member_as_dict['date_left'] = member_as_dict['date_left'].date(
                )

            for extra in member.memberextrainfo_set.all():
                member_as_dict[EXTRA_VALUE_PREFIX +
                               extra.info_type.code] = extra.value
            result.append(member_as_dict)

        return result
Пример #3
0
    def members_to_dict(self, members):
        members_as_dict = []
        for member in members:
            new_member = to_dict(member, ['bio'])
            team_roles = member.teamRoles.all()
            new_member['teamRoles'] = [
                to_dict(teamRole, ['role']) for teamRole in team_roles
            ]
            new_member['projects'] = [
                to_dict(project, ['description'])
                for project in member.projects.all()
            ]
            new_member['formation'] = to_dict(member.formation,
                                              ['name', 'url'])
            members_as_dict.append(new_member)

        return members_as_dict
Пример #4
0
def get_user_status_list(member):
    service_info = []
    default_username = '******'

    for connector_type in AVAILABLE_CONNECTORS:
        username_getter = MEMBER_CONNECTOR_FIELD_GETTERS.get(connector_type)

        username = username_getter(member) or default_username
        service_error = None
        try:
            is_active = do_action('check', connector_type, member)
            username = username_getter(member)
        except Exception as error:
            error_template = "Failed to check if the user({}) is valid for {}. Error: {}"
            service_error = error_template.format(member.id, connector_type,
                                                  error)
            logger.error(service_error, error)

            is_active = False

        service_info.append({
            'username': username,
            'name': connector_type.value,
            'displayName': connector_type.name,
            'status': is_active,
            'warning': service_error,
            'isCustomService': False
        })

    custom_services = ServiceInstructions.objects.all()

    member_as_dict = to_dict(member)
    for extra in member.memberextrainfo_set.all():
        member_as_dict[EXTRA_VALUE_PREFIX + extra.info_type.code] = extra.value

    for custom_service in custom_services:
        service_info.append({
            'username':
            member_as_dict.get(custom_service.member_mapping_to_username,
                               default_username),
            'name':
            custom_service.service_name,
            'displayName':
            custom_service.service_name,
            'status':
            'N/A',
            'registerUrl':
            custom_service.register_url,
            'unregisterUrl':
            custom_service.unregister_url,
            'instructionUrl':
            str(custom_service.instruction_file),
            'isCustomService':
            True
        })
    return service_info
Пример #5
0
    def projects_to_dict(self, projects):
        # projects_as_dict = {project.id: model_to_dict(project) for project in projects}

        projects_as_dict = []
        for project in projects:
            new_project = to_dict(project, ['description'])
            images = project.images.all()
            new_images = []
            for image_obj in images:
                new_image = str(image_obj)
                new_images.append(new_image)
            new_project['images'] = new_images
            new_project['status_text'] = project.status.status
            projects_as_dict.append(new_project)

        return projects_as_dict
Пример #6
0
    def teams_to_dict(self, teams, members):
        teams_as_dict = {
            team.id: to_dict(team, ['team_name'])
            for team in teams
        }
        for (team_id, team) in teams_as_dict.items():
            teams_as_dict[team_id]['members_count'] = 0

        for member in members:
            team_roles = member.teamRoles.all()
            for teamRole in team_roles:
                teams_as_dict[teamRole.team_id]['members_count'] += 1

        # All special case
        teams_as_dict[-1]['members_count'] = len(members)
        teams_as_dict = OrderedDict(
            sorted(teams_as_dict.items(), key=lambda t: t[0]))
        return teams_as_dict