Beispiel #1
0
def makeOneJournal(attrib=None):  # noqa
    """
    Retorna um objeto ``Journal`` com os atributos obrigatórios:
    ``_id``, ``jid``, ``is_public``.
    Atualiza o objeto de retorno com os valores do param ``attrib``.
    """
    attrib = attrib or {}
    default_id = attrib.get('_id', str(uuid4().hex))
    default_title = "journal-%s" % default_id
    default_title_iso = default_title[:6]

    if 'social_networks' in list(attrib.keys()):
        social_networks = []
        for sn in attrib['social_networks']:
            social_account = models.SocialNetwork(account=sn['account'],
                                                  network=sn['network'])
            social_networks.append(social_account)
        attrib['social_networks'] = social_networks

    journal = {
        '_id':
        default_id,
        'jid':
        attrib.get('jid', default_id),
        'is_public':
        attrib.get('is_public', True),
        'title':
        attrib.get('title', default_title),
        'title_iso':
        attrib.get('title_iso', default_title_iso),
        'short_title':
        attrib.get('short_title', 'Jounal Ex.'),
        'created':
        attrib.get('created', datetime.datetime.now()),
        'updated':
        attrib.get('updated', datetime.datetime.now()),
        'acronym':
        attrib.get('acronym', "journal_acron"),
        'mission':
        attrib.get('mission',
                   [{
                       'language': 'pt',
                       'description': 'Esse periódico tem com objetivo xpto'
                   }, {
                       'language': 'es',
                       'description': 'Esta revista tiene como objetivo xpto'
                   }, {
                       'language': 'en',
                       'description': 'This journal is aiming xpto'
                   }])
    }
    if not journal.get("is_public") and not journal.get("unpublish_reason"):
        journal["unpublish_reason"] = "<unpublish_reason>"
    journal.update(attrib)
    return models.Journal(**journal).save()
def JournalFactory(data):
    """Produz instância de `models.Journal` a partir dos dados retornados do
    endpoint `/journals/:journal_id` do Kernel.
    """
    metadata = data["metadata"]

    journal = models.Journal()
    journal._id = journal.jid = data.get("id")
    journal.title = metadata.get("title", "")
    journal.title_iso = metadata.get("title_iso", "")
    journal.short_title = metadata.get("short_title", "")
    journal.acronym = metadata.get("acronym", "")
    journal.scielo_issn = metadata.get("scielo_issn", "")
    journal.print_issn = metadata.get("print_issn", "")
    journal.eletronic_issn = metadata.get("electronic_issn", "")

    # Subject Categories
    journal.subject_categories = metadata.get("subject_categories", [])

    # Métricas
    journal.metrics = models.JounalMetrics(**metadata.get("metrics", {}))

    # Issue count
    journal.issue_count = len(data.get("items", []))

    # Mission
    journal.mission = [
        models.Mission(**{
            "language": m["language"],
            "description": m["value"]
        }) for m in metadata.get("mission", [])
    ]

    # Study Area
    journal.study_areas = metadata.get("subject_areas", [])

    # Sponsors
    sponsors = metadata.get("sponsors", [])
    journal.sponsors = [s["name"] for s in sponsors if sponsors]

    # TODO: Verificar se esse e-mail é o que deve ser colocado no editor.
    # Editor mail
    if metadata.get("contact", ""):
        contact = metadata.get("contact")
        journal.editor_email = contact.get("email", "").split(";")[0].strip()

    journal.online_submission_url = metadata.get("online_submission_url", "")
    journal.logo_url = metadata.get("logo_url", "")
    journal.current_status = metadata.get("status", {}).get("status")

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

    return journal
Beispiel #3
0
def JournalFactory(data):
    """Produz instância de `models.Journal` a partir dos dados retornados do
    endpoint `/journals/:journal_id` do Kernel.
    """
    metadata = data["metadata"]

    try:
        journal = models.Journal.objects.get(_id=data.get("id"))
    except models.Journal.DoesNotExist:
        journal = models.Journal()

    journal._id = journal.jid = data.get("id")
    journal.title = metadata.get("title", "")
    journal.title_iso = metadata.get("title_iso", "")
    journal.short_title = metadata.get("short_title", "")
    journal.acronym = metadata.get("acronym", "")
    journal.scielo_issn = metadata.get("scielo_issn", "")
    journal.print_issn = metadata.get("print_issn", "")
    journal.eletronic_issn = metadata.get("electronic_issn", "")

    # Subject Categories
    journal.subject_categories = metadata.get("subject_categories", [])

    # Métricas
    journal.metrics = models.JounalMetrics(**metadata.get("metrics", {}))

    # Issue count
    journal.issue_count = len(data.get("items", []))

    # Mission
    journal.mission = [
        models.Mission(**{
            "language": m["language"],
            "description": m["value"]
        }) for m in metadata.get("mission", [])
    ]

    # Study Area
    journal.study_areas = metadata.get("subject_areas", [])

    # Sponsors
    sponsors = metadata.get("sponsors", [])
    journal.sponsors = [s["name"] for s in sponsors if sponsors]

    # TODO: Verificar se esse e-mail é o que deve ser colocado no editor.
    # Editor mail
    if metadata.get("contact", ""):
        contact = metadata.get("contact")
        journal.editor_email = EMAIL_SPLIT_REGEX.split(contact.get(
            "email", ""))[0].strip()
        journal.publisher_address = contact.get("address")

    if metadata.get("institution_responsible_for"):
        institutions = [
            item for item in metadata.get("institution_responsible_for", [{}])
            if item.get("name")
        ]
        if institutions:
            journal.publisher_name = ', '.join(
                item.get("name") for item in institutions)
            institution = institutions[0]
            journal.publisher_city = institution.get("city")
            journal.publisher_state = institution.get("state")
            journal.publisher_country = institution.get("country")

    journal.online_submission_url = metadata.get("online_submission_url", "")
    if journal.logo_url is None or len(journal.logo_url) == 0:
        journal.logo_url = metadata.get("logo_url", "")
    journal.current_status = metadata.get("status_history",
                                          [{}])[-1].get("status")

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

    return journal