def getLastIssue(attrib=None): # noqa """ Retorna um objeto ``LastIssue`` 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 {} attributes = ( ('volume', '100'), ('number', '100'), ('year', 2030), ('label', 'label'), ('type', 'regular'), ('suppl_text', None), ('start_month', 1), ('end_month', 1), ('sections', None), ('cover_url', ''), ('iid', 'ID'), ) last_issue = {} for k, val in attributes: last_issue[k] = attrib.get(k) or val last_issue['url_segment'] = '{}.{}{}{}'.format( last_issue.get("year"), "v" + last_issue.get('volume') if last_issue.get('volume') else "", "n" + last_issue.get('number') if last_issue.get('number') else "", last_issue.get('suppl_text') or "", ) return models.LastIssue(**last_issue)
def register_last_issues(ds, **kwargs): mongo_connect() for journal in models.Journal.objects.all(): try: logging.info("Id do journal: %s" % journal._id) last_j_issue = ( models.Issue.objects.filter(journal=journal._id) .order_by("-year", "-order") .first() .select_related() ) l_issue_sec = [] if hasattr(last_j_issue, "sections"): l_issue_sec = last_j_issue.sections last_issue = {"sections": l_issue_sec} if hasattr(last_j_issue, "volume"): last_issue["volume"] = last_j_issue.volume if hasattr(last_j_issue, "iid"): last_issue["iid"] = last_j_issue.iid if hasattr(last_j_issue, "number"): last_issue["number"] = last_j_issue.number if hasattr(last_j_issue, "start_month"): last_issue["start_month"] = last_j_issue.start_month if hasattr(last_j_issue, "end_month"): last_issue["end_month"] = last_j_issue.end_month if hasattr(last_j_issue, "label"): last_issue["label"] = last_j_issue.label if hasattr(last_j_issue, "year"): last_issue["year"] = last_j_issue.year if hasattr(last_j_issue, "type"): last_issue["type"] = last_j_issue.type if hasattr(last_j_issue, "suppl_text"): last_issue["suppl_text"] = last_j_issue.suppl_text journal.last_issue = models.LastIssue(**last_issue) journal.save() except AttributeError: logging.info("No issues are registered to models.Journal: %s " % journal)