Ejemplo n.º 1
0
    def formatter(bwo, **kwargs):
        """Return formatted data of object."""
        from lxml import etree

        of = kwargs.get("of", "hd")

        extra_data = bwo.get_extra_data()
        parser = etree.XMLParser(remove_blank_text=True)
        tree = etree.fromstring(extra_data.get("marcxml"), parser)
        xml = etree.tostring(tree, pretty_print=True)

        id_user = bwo.id_user
        user_email = acc_get_user_email(id_user)
        ticket_id = extra_data.get("ticket_id")
        ticket_url = "https://rt.inspirehep.net/Ticket/Display.html?id={}".format(
            ticket_id
            )

        if of == "xm":
            return xml
        else:
            return render_template("authors/workflows/authorupdate.html",
                                   user_email=user_email,
                                   ticket_url=ticket_url,
                                   comments=extra_data.get("comments"))
Ejemplo n.º 2
0
    def _create_curation_ticket(obj, eng):
        from invenio.modules.access.control import acc_get_user_email

        recid = obj.extra_data.get('recid')
        record_url = obj.extra_data.get('url')

        user_email = acc_get_user_email(obj.id_user)

        bai = ""
        if obj.data.get("bai"):
            bai = "[{}]".format(obj.data.get("bai"))
        subject = "Curation needed for author {} {}".format(
            obj.data.get("name").get("preferred_name"),
            bai
        )
        body = render_template(
            template,
            email=user_email,
            object=obj,
            recid=recid,
            record_url=record_url,
            user_comment=obj.extra_data.get("comments", ""),
        ).strip()

        submit_rt_ticket(
            obj=obj,
            queue=queue,
            subject=subject,
            body=body,
            requestors=user_email,
            ticket_id_key=ticket_id_key
        )
Ejemplo n.º 3
0
    def _create_curator_ticket_update(obj, eng):
        from invenio.base.globals import cfg

        user_email = acc_get_user_email(obj.id_user)
        recid = obj.data.get("recid", "")

        subject = "Your update to author {} on INSPIRE".format(
            obj.data.get("name").get("preferred_name")
        )
        record_url = os.path.join(cfg["AUTHORS_UPDATE_BASE_URL"], "record",
                                  str(recid))
        body = render_template(
            template,
            email=user_email,
            url=record_url,
            bibedit_url=record_url + "/edit",
            user_comment=obj.extra_data.get("comments", ""),
        ).strip()

        submit_rt_ticket(
            obj=obj,
            queue=queue,
            subject=subject,
            body=body,
            requestors=user_email,
            ticket_id_key=ticket_id_key
        )
Ejemplo n.º 4
0
    def formatter(bwo, **kwargs):
        """Return formatted data of object."""
        from invenio.modules.formatter import format_record

        of = kwargs.get("of", "hp")

        extra_data = bwo.get_extra_data()
        xml = extra_data.get("marcxml")

        id_user = bwo.id_user
        user_email = acc_get_user_email(id_user)
        ticket_id = extra_data.get("ticket_id")
        ticket_url = "https://rt.inspirehep.net/Ticket/Display.html?id={}".format(
            ticket_id
            )

        if of == "xm":
            return xml
        else:
            record_preview = format_record(
                    recID=None,
                    of=of,
                    xml_record=xml
                    )
            return render_template("authors/workflows/authorupdate.html",
                                   record_preview=record_preview,
                                   user_email=user_email,
                                   ticket_url=ticket_url,
                                   comments=extra_data.get("comments"))
Ejemplo n.º 5
0
    def get_title(bwo):
        """Return title of object."""
        from invenio.modules.access.control import acc_get_user_email
        id_user = bwo.id_user
        user_email = acc_get_user_email(id_user)

        return u"Demo form by: {0}".format(user_email)
Ejemplo n.º 6
0
    def get_description(bwo):
        """Return description of object."""
        from invenio.modules.access.control import acc_get_user_email
        results = bwo.get_tasks_results()
        try:
            deposit_object = Deposition(bwo)
        except InvalidDepositionType:
            return "This submission is disabled: {0}.".format(bwo.workflow.name)

        id_user = deposit_object.workflow_object.id_user
        user_email = acc_get_user_email(id_user)

        sip = deposit_object.get_latest_sip()
        if sip:
            record = sip.metadata
            identifiers = []
            report_numbers = record.get("report_number", {})
            if not isinstance(report_numbers, list):
                report_numbers = [report_numbers]

            report_numbers += record.get("report_numbers", [])
            doi = record.get("doi", "")
            if report_numbers:
                for report_number in report_numbers:
                    number = report_number.get("primary", "")
                    if number:
                        identifiers.append(number)
            if doi:
                identifiers.append("doi:{0}".format(doi))

            categories = []
            subjects = record.get("subject_term", [])
            if subjects:
                categories += [subject.get("term") for subject in subjects]
            categories = [record.get("type_of_doc", "")] + categories

            authors = []
            authors += [record.get("_first_author", {})]
            authors += record.get("_additional_authors", [])
            return render_template(
                'workflows/styles/submission_record.html',
                categories=categories,
                authors=authors,
                identifiers=identifiers,
                results=results,
                user_email=user_email,
                object=bwo,
                record=record
            )
        else:
            return "Submitter: {0}".format(user_email)
Ejemplo n.º 7
0
def inform_submitter(obj, eng):
    """Send a mail to submitter with the outcome of the submission."""
    from invenio.modules.access.control import acc_get_user_email
    from invenio.ext.email import send_email
    d = Deposition(obj)
    id_user = d.workflow_object.id_user
    email = acc_get_user_email(id_user)
    if was_approved(obj, eng):
        body = 'Accepted: '
        extra_data = d.workflow_object.get_extra_data()
        body += extra_data.get('url', '')
    else:
        body = 'Rejected'
    send_email(CFG_SITE_SUPPORT_EMAIL, email, 'Subject', body, header='header')
Ejemplo n.º 8
0
def inform_submitter(obj, eng):
    """Send a mail to submitter with the outcome of the submission."""
    from invenio.modules.access.control import acc_get_user_email
    from invenio.ext.email import send_email
    d = Deposition(obj)
    id_user = d.workflow_object.id_user
    email = acc_get_user_email(id_user)
    if was_approved(obj, eng):
        body = 'Accepted: '
        extra_data = d.workflow_object.get_extra_data()
        body += extra_data.get('url', '')
    else:
        body = 'Rejected'
    send_email(CFG_SITE_SUPPORT_EMAIL, email, 'Subject', body, header='header')
Ejemplo n.º 9
0
 def get_description(bwo):
     """Return description of object."""
     deposit_object = Deposition(bwo)
     sip = deposit_object.get_latest_sip()
     if sip:
         record = sip.metadata
         identifiers = [record.get("arxiv_id", "")]
         categories = [record.get("type_of_doc", "")]
         return render_template('workflows/styles/submission_record.html',
                                categories=categories,
                                identifiers=identifiers)
     else:
         from invenio.modules.access.control import acc_get_user_email
         id_user = deposit_object.workflow_object.id_user
         return "Submitted by: %s" % str(acc_get_user_email(id_user))
Ejemplo n.º 10
0
 def get_description(bwo):
     """Return description of object."""
     deposit_object = Deposition(bwo)
     sip = deposit_object.get_latest_sip()
     if sip:
         record = sip.metadata
         identifiers = [record.get("arxiv_id", "")]
         categories = [record.get("type_of_doc", "")]
         return render_template('workflows/styles/submission_record.html',
                                categories=categories,
                                identifiers=identifiers)
     else:
         from invenio.modules.access.control import acc_get_user_email
         id_user = deposit_object.workflow_object.id_user
         return "Submitted by: %s" % str(acc_get_user_email(id_user))
Ejemplo n.º 11
0
    def _create_ticket(obj, eng):
        from invenio.modules.access.control import acc_get_user_email

        deposition = Deposition(obj)
        requestors = acc_get_user_email(obj.id_user)

        subject, body = get_ticket_body(template,
                                        deposition,
                                        deposition.get_latest_sip(sealed=False).metadata,
                                        requestors,
                                        obj)
        submit_rt_ticket(obj,
                         queue,
                         subject,
                         body,
                         requestors,
                         ticket_id_key)
Ejemplo n.º 12
0
    def _create_curation_ticket(obj, eng):
        from invenio.modules.access.control import acc_get_user_email

        deposition = Deposition(obj)
        requestors = acc_get_user_email(obj.id_user)
        metadata = deposition.get_latest_sip(sealed=True).metadata

        if obj.extra_data.get("core"):
            subject, body = get_curation_body(template,
                                              metadata,
                                              requestors,
                                              obj.extra_data)
            submit_rt_ticket(obj,
                             queue,
                             subject,
                             body,
                             requestors,
                             ticket_id_key)
Ejemplo n.º 13
0
    def _create_curator_ticket_new(obj, eng):
        user_email = acc_get_user_email(obj.id_user)

        subject = "Your suggestion to INSPIRE: author {}".format(
            obj.data.get("name").get("preferred_name")
        )
        body = render_template(
            template,
            email=user_email,
            object=obj,
            user_comment=obj.extra_data.get("comments", ""),
        ).strip()

        submit_rt_ticket(
            obj=obj,
            queue=queue,
            subject=subject,
            body=body,
            requestors=user_email,
            ticket_id_key=ticket_id_key
        )
Ejemplo n.º 14
0
    def _convert_data_to_model(obj, eng):
        import copy
        # Save original form data for later access
        obj.extra_data["formdata"] = copy.deepcopy(obj.data)

        data = obj.data
        filter_empty_elements(data)

        data["name"] = {}
        if "status" in data and data["status"]:
            data["name"]["status"] = data["status"]
        if "given_names" in data and data["given_names"]:
            data["name"]["first"] = data["given_names"].strip()
        if "family_name" in data and data["family_name"]:
            data["name"]["last"] = data["family_name"].strip()
        if "display_name" in data and data["display_name"]:
            data["name"]["preferred_name"] = data["display_name"]
        data["urls"] = []
        if "websites" in data and data["websites"]:
            for website in data["websites"]:
                data["urls"].append({
                    "value": website["webpage"],
                    "description": ""
                })
        if "twitter_url" in data and data["twitter_url"]:
            data["urls"].append({
                "value": data["twitter_url"],
                "description": "TWITTER"
            })
        if "blog_url" in data and data["blog_url"]:
            data["urls"].append({
                "value": data["blog_url"],
                "description": "BLOG"
            })
        if "linkedin_url" in data and data["linkedin_url"]:
            data["urls"].append({
                "value": data["linkedin_url"],
                "description": "LINKEDIN"
            })
        data["ids"] = []
        if "orcid" in data and data["orcid"]:
            data["ids"].append({
                "type": "ORCID",
                "value": data["orcid"]
            })
        if "bai" in data and data["bai"]:
            data["ids"].append({
                "type": "BAI",
                "value": data["bai"]
            })
        data["_public_emails"] = []
        if "public_email" in data and data["public_email"]:
            data["_public_emails"].append({
                "value": data["public_email"],
                "current": "Current"
            })
        data["field_categories"] = []
        if "research_field" in data and data["research_field"]:
            for field in data["research_field"]:
                data["field_categories"].append({
                    "name": field,
                    "type": "INSPIRE"
                })
            del data["research_field"]
        data["positions"] = []
        if "institution_history" in data and data["institution_history"]:
            data["institution_history"] = sorted(data["institution_history"],
                                                 key=lambda k: k["start_year"],
                                                 reverse=True)
            for position in data["institution_history"]:
                data["positions"].append({
                    "institution": position["name"],
                    "status": "current" if position["current"] else "",
                    "start_date": position["start_year"],
                    "end_date": position["end_year"],
                    "rank": position["rank"] if position["rank"] != "rank" else ""
                })
            del data["institution_history"]
        data["phd_advisors"] = []
        if "advisors" in data and data["advisors"]:
            for advisor in data["advisors"]:
                if advisor["degree_type"] == "PhD" and not advisor["full_name"]:
                    continue
                data["phd_advisors"].append({
                    "name": advisor["full_name"],
                    "degree_type": advisor["degree_type"]
                })
        if "experiments" in data and data["experiments"]:
            for experiment in data["experiments"]:
                data["experiments"] = sorted(data["experiments"],
                                             key=lambda k: k["start_year"],
                                             reverse=True)
                if experiment["status"]:
                    experiment["status"] = "current"
                else:
                    experiment["status"] = ""

        # Add comments to extra data
        if "comments" in data and data["comments"]:
            obj.extra_data["comments"] = data["comments"]
            data["_private_note"] = data["comments"]

        # Add HEPNAMES collection
        data["collections"] = {
            "primary": "HEPNAMES"
        }

        # ==========
        # Owner Info
        # ==========
        user_email = acc_get_user_email(obj.id_user)
        sources = ["{0}{1}".format('inspire:uid:', obj.id_user)]
        data['acquisition_source'] = dict(
            source=sources,
            email=user_email,
            date=date.today().isoformat(),
            method="submission",
            submission_number=obj.id,
        )
Ejemplo n.º 15
0
    def get_title(bwo):
        """Return title of object."""
        id_user = bwo.id_user
        user_email = acc_get_user_email(id_user)

        return u"Author update by: {0}".format(user_email)