示例#1
0
def _operation_context(plan, deployment_id, *entity_keys):
    if entity_keys[2] == utils.pluralize(ENTITY_TYPES.RELATIONSHIP):
        entity_context = RelationshipInterfaceOperationContext
    else:
        entity_context = NodeInterfaceOperationContext

    return entity_context(plan, deployment_id, *entity_keys)
示例#2
0
 def summarize(self, audioextensions):
     # Summarize the counts of files per extension
     extensioncounts = [(extension, len([() for filename in self.media.values() if os.path.splitext(filename)[1].lower() == extension.lower()])) for extension in audioextensions]
     formattedcounts = [str(count) + " " + extension + " " + utils.pluralize("file", count) for extension, count in extensioncounts if count > 0]
     
     if len(formattedcounts) > 0:
         # Only include brackets around the extension counts in this case
         return self.name + " (" + ", ".join(formattedcounts) + ")"
     else:
         return self.name
    def __init__(self, song=None):
        super(Header, self).__init__()
        self.song = song
        self.settings = get_settings()

        self.layout = QGridLayout()
        self.layout.setMargin(0)
        self.layout.setContentsMargins(0, 0, 0, 25)

        self.setObjectName(u'header')
        self.setAttribute(Qt.WA_StyledBackground, True)
        self.setStyleSheet(
            css('''
            #header {
                border-bottom: 1px solid {{backgroundColor}};
            }
            ''',
                backgroundColor=colors.SECONDARY_COLOR))

        self.left_container = QWidget()
        self.left_container.setStyleSheet(
            css('color: {{color}};', color=colors.GREY_COLOR))
        self.left_container_layout = QHBoxLayout(alignment=Qt.AlignLeft)
        self.left_container_layout.setMargin(0)
        self.left_container.setLayout(self.left_container_layout)

        self.right_container = QWidget()
        self.right_container_layout = QHBoxLayout(alignment=Qt.AlignRight)
        self.right_container_layout.setMargin(0)
        self.right_container.setLayout(self.right_container_layout)

        self.layout.addWidget(self.left_container, 0, 0)
        self.layout.addWidget(self.right_container, 0, 1)

        # Info on the left
        songs_amount = len(
            self.song['songlist']) if self.song['full_release'] else len(
                [s for s in self.song['songlist'] if s['released']])
        songs_text = pluralize('song', 'songs', songs_amount)
        info_text = '{} · {}'.format(self.song['genre'], songs_text).upper()
        self.left_container_layout.addWidget(QLabel(info_text))

        # Download buttons on the right
        if 'download_links' in self.song:
            for item in self.song['download_links']:
                btn = IconButton(text=item['label'],
                                 icon='download',
                                 on_click=self.download(item))
                self.right_container_layout.addWidget(btn)

        self.setLayout(self.layout)
示例#4
0
def get_file_stats(v, separator=None, as_statistic=True):
    stats = []
    agg = v.get("datagetter_aggregates")
    if agg is None:
        return stats

    count = agg.get("count", 0)
    stats.append(
        to_statistic(humanize.intcomma(count), pluralize("grant", count)))

    recip = agg.get("distinct_recipient_org_identifier_count", 0)
    if recip > 0:
        stats.append(
            to_statistic(
                humanize.intcomma(recip),
                pluralize("recipient", recip),
            ))

    funders = agg.get("distinct_funding_org_identifier_count", 0)
    if funders > 1:
        stats.append(
            to_statistic(
                humanize.intcomma(funders),
                pluralize("funder", funders),
            ))

    if len(agg.get("currencies", {})) == 1:
        for c in agg["currencies"]:
            cur = format_currency(agg["currencies"][c].get("total_amount", 0),
                                  c)
            stats.append(to_statistic(cur[0], cur[1]))

    if separator:
        result = [separator] * (len(stats) * 2 - 1)
        result[0::2] = stats
        return result

    return stats
示例#5
0
    def summarize(self, audioextensions):
        # Summarize the counts of files per extension
        extensioncounts = [
            (extension,
             len([
                 () for filename in self.media.values()
                 if os.path.splitext(filename)[1].lower() == extension.lower()
             ])) for extension in audioextensions
        ]
        formattedcounts = [
            str(count) + " " + extension + " " +
            utils.pluralize("file", count)
            for extension, count in extensioncounts if count > 0
        ]

        if len(formattedcounts) > 0:
            # Only include brackets around the extension counts in this case
            return self.name + " (" + ", ".join(formattedcounts) + ")"
        else:
            return self.name
示例#6
0
class EntityContextBase(object):
    NODES = utils.pluralize(ENTITY_TYPES.NODE)
    RELATIONSHIPS = utils.pluralize(ENTITY_TYPES.RELATIONSHIP)
    OPERATIONS = utils.pluralize(ENTITY_TYPES.OPERATION)
    PROPERTIES = utils.pluralize(ENTITY_TYPES.PROPERTY)
    WORKFLOWS = utils.pluralize(ENTITY_TYPES.WORKFLOW)
    OUTPUTS = utils.pluralize(ENTITY_TYPES.OUTPUT)
    PLUGINS = utils.pluralize(ENTITY_TYPES.PLUGIN)
    DESCRIPTION = 'description'

    def __init__(self, plan, deployment_id, entity_type, top_level_entity_id):
        self.sm = get_storage_manager()
        self._deployment_id = deployment_id
        self._entity_type = entity_type
        self._top_level_entity_id = top_level_entity_id
        self._plan = plan

    @property
    def deployment_plan(self):
        return self._plan

    @property
    def entity_type(self):
        return self._entity_type

    @property
    def deployment_id(self):
        return self._deployment_id

    @property
    def entity_id(self):
        raise NotImplementedError

    @property
    def storage_entity_value(self):
        raise NotImplementedError

    @property
    def raw_entity_value(self):
        raise NotImplementedError
示例#7
0
class EntityContextBase(object):
    NODES = utils.pluralize(ENTITY_TYPES.NODE)
    RELATIONSHIPS = utils.pluralize(ENTITY_TYPES.RELATIONSHIP)
    OPERATIONS = utils.pluralize(ENTITY_TYPES.OPERATION)
    PROPERTIES = utils.pluralize(ENTITY_TYPES.PROPERTY)
    PLUGINS = 'plugins'

    def __init__(self, plan, deployment_id, entity_type, node_id):
        self.sm = storage_manager.get_storage_manager()
        self._deployment_id = deployment_id
        self._entity_type = entity_type
        self._node_id = node_id
        self._plan = plan
        self._raw_node = utils.get_raw_node(self.blueprint, self._node_id)

    @property
    def blueprint(self):
        return self._plan

    @property
    def entity_id(self):
        raise NotImplementedError

    @property
    def entity_type(self):
        return self._entity_type

    @property
    def storage_node(self):
        return self.sm.get_node(self._deployment_id, self._node_id) or {}

    @property
    def storage_node_instance(self):
        old_node_instances = self.sm.get_node_instance(
                filters={'deployment_id': self._deployment_id,
                         'node_id': self._node_id}
        )
        return old_node_instances[0] if old_node_instances else {}

    @property
    def raw_node(self):
        return self._raw_node

    @property
    def raw_node_id(self):
        return self.raw_node['id']

    @property
    def storage_node_id(self):
        return self.storage_node.id

    @property
    def storage_entity_value(self):
        raise NotImplementedError

    @property
    def raw_entity_value(self):
        raise NotImplementedError

    @property
    def deployment_id(self):
        return self._deployment_id
示例#8
0
def test__pluralize__default_subject__adds_s_or_not(count, expected_ending):
    assert expected_ending == utils.pluralize([None] * count)
示例#9
0
def update_status_container(search, licence, last_modified, currency, filetype,
                            fields):
    reg = get_registry_by_publisher(filters={
        "search": search,
        "licence": licence,
        "last_modified": last_modified,
        "currency": currency,
        "filetype": filetype,
        "fields": fields
    },
                                    reg_url=THREESIXTY_STATUS_JSON)

    file_count = sum([len(pub_reg) for pub, pub_reg in reg.items()])
    rows = [
        html.Div(className='w-100 f3',
                 children=[
                     html.Span(className="",
                               children=[
                                   html.Strong(len(reg)),
                                   ' ' + pluralize("publisher", len(reg))
                               ]),
                     html.Span(className='mh2', children='·'),
                     html.Span(className="",
                               children=[
                                   html.Strong(file_count),
                                   ' ' + pluralize("file", file_count)
                               ]),
                 ])
    ]
    for pub, pub_reg in reg.items():
        rows.append(
            html.Div(
                className='br2 ba dark-gray b--black-10 mv4 w-100 center mb4',
                children=[
                    html.Div(className='w-100 cf pa3',
                             children=[
                                 html.A(className='f3 link black b',
                                        href=pub_reg[0].get("publisher",
                                                            {}).get("website"),
                                        target='_blank',
                                        children=[
                                            pub_reg[0].get("publisher",
                                                           {}).get("name")
                                        ]),
                                 html.Img(className='fr mw5',
                                          src=pub_reg[0].get("publisher",
                                                             {}).get("logo"),
                                          style={'max-height': '8rem'}),
                             ]),
                    html.Div(className='content',
                             children=[
                                 html.Div(
                                     className='flex ph3',
                                     children=([
                                         to_statistic(
                                             len(pub_reg),
                                             pluralize("file", len(pub_reg)))
                                     ] + get_publisher_stats(
                                         pub_reg, separator=html.Span('·'))
                                               if len(pub_reg) > 1 else [])),
                                 html.Div(className='description',
                                          children=[
                                              file_row(v, len(pub_reg))
                                              for v in pub_reg
                                          ])
                             ])
                ]))
    return rows
示例#10
0
 def check(count, ending):
     assert ending == utils.pluralize([None] * count)