def IssueFactory(data, journal_id, issue_order):
    """
    Realiza o registro fascículo utilizando o opac schema.

    Esta função pode lançar a exceção `models.Journal.DoesNotExist`.
    """
    mongo_connect()

    metadata = data["metadata"]

    issue = models.Issue()
    issue._id = issue.iid = data.get("id")
    issue.type = metadata.get("type", "regular")
    issue.spe_text = metadata.get("spe_text", "")
    issue.start_month = metadata.get("publication_month", 0)
    issue.end_month = metadata.get("publication_season", [0])[-1]
    issue.year = metadata.get("publication_year")
    issue.volume = metadata.get("volume", "")
    issue.number = metadata.get("number", "")
    issue.label = metadata.get(
        "label", "%s%s" % ("v" + issue.volume, "n" + issue.number))
    issue.order = metadata.get("order", 0)
    issue.pid = metadata.get("pid", "")
    issue.journal = models.Journal.objects.get(_id=journal_id)
    issue.order = issue_order

    return issue
def register_issue(data, journal_id, issue_id, j_issues):
    """
    Realiza o registro fascículo utilizando o opac schema.
    """
    mongo_connect()

    journal = models.Journal.objects.get(_id=journal_id)

    metadata = data["metadata"]

    issue = models.Issue()
    issue._id = issue.iid = data.get("id")
    issue._id = issue.iid = data.get("id")
    issue.type = metadata.get("type", "regular")
    issue.spe_text = metadata.get("spe_text", "")
    issue.start_month = metadata.get("publication_month", 0)
    issue.end_month = metadata.get("publication_season", [0])[-1]
    issue.year = metadata.get("publication_year")
    issue.volume = metadata.get("volume", "")
    issue.number = metadata.get("number", "")

    issue.label = metadata.get(
        "label", "%s%s" % ("v" + issue.volume, "n" + issue.number)
    )
    issue.order = metadata.get("order", 0)
    issue.pid = metadata.get("pid", "")

    issue.journal = journal
    issue.order = j_issues.get(journal.id).index(issue_id)
    issue.save()

    return issue
Beispiel #3
0
def makeOneIssue(attrib=None):  # noqa
    """
    Retorna um objeto ``Issue`` com os atributos obrigatórios:
    ``_id``, ``jid``, ``is_public`` e ``journal_jid``.
    Atualiza o objeto de retorno com os valores do param ``attrib``.
    """

    attrib = attrib or {}
    default_id = attrib.get('_id', str(uuid4().hex))
    default_volume = attrib.get('volume', '1')  # improve para evitar dups
    default_number = attrib.get('number', '1')  # improve para evitar dups
    default_type = attrib.get('type', 'regular')
    default_pid = attrib.get('pid', '0000-000000000000')
    default_order = attrib.get('order', attrib.get('order', '1'))
    default_year = attrib.get('year', datetime.datetime.now().year)
    default_label = attrib.get('label',
                               '%s (%s)' % (default_volume, default_number))
    default_suppl_text = attrib.get('suppl_text', 'X')
    journal = attrib.get('journal', None)

    if not journal:
        journal = makeOneJournal()
    elif isinstance(journal, str) or isinstance(journal, str):
        # o valor de: journal é o Id do journal
        try:
            journal = models.Journal.objects.get(_id=journal)
        except models.Journal.DoesNotExist:
            journal = makeOneJournal({'_id': journal})
    elif isinstance(journal, models.Journal):
        pass
    else:
        raise ValueError('WTF is journal?')

    issue = {
        '_id': default_id,
        'iid': default_id,
        'volume': default_volume,
        'number': default_number,
        'type': default_type,
        'order': default_order,
        'year': default_year,
        'label': default_label,
        'suppl_text': default_suppl_text,
        'pid': default_pid,
        'is_public': attrib.get('is_public', True),
        'created': attrib.get('created', datetime.datetime.now()),
        'updated': attrib.get('updated', datetime.datetime.now()),
        'journal': journal.id
    }

    for k, v in attrib.items():
        if k not in list(issue.keys()):
            issue[k] = v

    return models.Issue(**issue).save()
 def setUp(self):
     self.document_front = load_json_fixture(
         "kernel-document-front-s1518-8787.2019053000621.json")
     data = {
         "id": "0101-0101",
         "created": "2019-11-28T00:00:00.000000Z",
         "metadata": {},
     }
     self.issue = models.Issue()
     self.issue._id = "0101-0101-aop"
     self.issue.year = "2019"
     self.issue.number = "ahead"
     self.issue.url_segment = "2019.nahead"
Beispiel #5
0
def IssueFactory(data, journal_id, issue_order=None, _type="regular"):
    """
    Realiza o registro fascículo utilizando o opac schema.

    Esta função pode lançar a exceção `models.Journal.DoesNotExist`.

    Para satisfazer a obrigatoriedade do ano para os "Fascículos" ahead, estamos fixando o ano de fascículos do tipo ``ahead`` com o valor 9999
    """
    mongo_connect()

    metadata = data["metadata"]

    try:
        issue = models.Issue.objects.get(_id=data["id"])
    except models.Issue.DoesNotExist:
        issue = models.Issue()
    else:
        journal_id = journal_id or issue.journal._id
        _type = "ahead" if _type == "ahead" or data["id"].endswith(
            "-aop") else _type

    issue._id = issue.iid = data["id"]
    issue.spe_text = metadata.get("spe_text", "")
    issue.start_month = metadata.get("publication_months", {
        "range": [0, 0]
    }).get("range", [0])[0]
    issue.end_month = metadata.get("publication_months", {
        "range": [0, 0]
    }).get("range", [0])[-1]

    if _type == "ahead":
        issue.year = issue.year or "9999"
        issue.number = issue.number or "ahead"
    else:
        issue.year = metadata.get("publication_year", issue.year)
        issue.number = metadata.get("number", issue.number)

    issue.volume = metadata.get("volume", "")

    if issue_order:
        issue.order = issue_order

    issue.pid = metadata.get("pid", "")
    issue.journal = models.Journal.objects.get(_id=journal_id)

    def _get_issue_label(metadata: dict) -> str:
        """Produz o label esperado pelo OPAC de acordo com as regras aplicadas
        pelo OPAC Proc e Xylose.

        Args:
            metadata (dict): conteúdo de um bundle

        Returns:
            str: label produzido a partir de um bundle
        """

        START_REGEX = re.compile("^0")
        END_REGEX = re.compile("0$")

        label_number = metadata.get("number", "")
        label_volume = metadata.get("volume", "")
        label_supplement = (" suppl %s" % metadata.get("supplement", "")
                            if metadata.get("supplement", "") else "")

        if label_number:
            label_number += label_supplement
            label_number = START_REGEX.sub("", label_number)
            label_number = END_REGEX.sub("", label_number)
            label_number = label_number.strip()

        return "".join(["v" + label_volume, "n" + label_number])

    issue.label = _get_issue_label(metadata)

    if metadata.get("supplement"):
        issue.suppl_text = metadata.get("supplement")
        issue.type = "supplement"
    elif issue.volume and not issue.number:
        issue.type = "volume_issue"
    elif issue.number and "spe" in issue.number:
        issue.type = "special"
    elif _type == "ahead" and not data.get("items"):
        """
        Caso não haja nenhum artigo no bundle de ahead, ele é definido como
        ``outdated_ahead``, para que não apareça na grade de fascículos
        """
        issue.type = "outdated_ahead"
    else:
        issue.type = _type

    issue.created = data.get("created", "")
    issue.updated = data.get("updated", "")

    return issue
Beispiel #6
0
def IssueFactory(data, journal_id, issue_order):
    """
    Realiza o registro fascículo utilizando o opac schema.

    Esta função pode lançar a exceção `models.Journal.DoesNotExist`.
    """
    mongo_connect()

    metadata = data["metadata"]

    issue = models.Issue()
    issue._id = issue.iid = data.get("id")
    issue.type = metadata.get("type", "regular")
    issue.spe_text = metadata.get("spe_text", "")
    issue.start_month = metadata.get("publication_month", 0)
    issue.end_month = metadata.get("publication_season", [0])[-1]
    issue.year = metadata.get("publication_year")
    issue.volume = metadata.get("volume", "")
    issue.number = metadata.get("number", "")
    issue.order = metadata.get("order", 0)
    issue.pid = metadata.get("pid", "")
    issue.journal = models.Journal.objects.get(_id=journal_id)
    issue.order = issue_order

    def _get_issue_label(metadata: dict) -> str:
        """Produz o label esperado pelo OPAC de acordo com as regras aplicadas
        pelo OPAC Proc e Xylose.
        
        Args:
            metadata (dict): conteúdo de um bundle
        
        Returns:
            str: label produzido a partir de um bundle
        """

        START_REGEX = re.compile("^0")
        END_REGEX = re.compile("0$")

        label_number = metadata.get("number", "")
        label_volume = metadata.get("volume", "")
        label_supplement = (
            " suppl %s" % metadata.get("supplement", "")
            if metadata.get("supplement", "")
            else ""
        )

        if label_number:
            label_number += label_supplement
            label_number = START_REGEX.sub("", label_number)
            label_number = END_REGEX.sub("", label_number)
            label_number = label_number.strip()

        return "".join(["v" + label_volume, "n" + label_number])

    issue.label = _get_issue_label(metadata)

    if metadata.get("supplement"):
        issue.suppl_text = metadata.get("supplement")
        issue.type = "supplement"
    elif issue.volume and not issue.number:
        issue.type = "volume_issue"
    elif issue.number and "spe" in issue.number:
        issue.type = "special"

    return issue