Ejemplo n.º 1
0
def get_paper_data(paper, user):
    self_assigned = ''
    other_user = ''
    if paper.owner == user:
        self_assigned = 'checked'
    elif paper.owner is not None and paper.owner != '':
        other_user = '******'

    paper_owner_name = 'None'
    if paper.owner is not None:
        paper_owner_name = f"{paper.owner.first_name} {paper.owner.last_name}, {paper.owner.affiliation}"

    paper_dict = {
        'short_cit': paper.short_citation,
        'doi': paper.doi,
        'date': paper.date,
        'title': paper.title,
        'journal': paper.journal,
        'authors': papers_functions.list_to_string(paper.authors),
        'tags': papers_functions.list_to_string(paper.tags),
        'self_assigned': self_assigned,
        'disable_for_other_user': other_user,
        'id': paper.id,
        'paper_owner_name': paper_owner_name
    }

    return paper_dict
Ejemplo n.º 2
0
def query_crossref():
    paper = Paper.objects(id=request.form['paper_id'])[0]
    doi = str(paper.doi).replace(' ', '')

    title, authors_list, journal, date, cite_mini = papers_crossref.get_metadata_from_crossref(
        doi)

    print(f"{title}, {authors_list}, {journal}, {type(date)}, {cite_mini}")

    if cite_mini == '':
        result = {
            'status': 'danger',
            'msg': 'DOI not found in crossref',
            'issues': []
        }

    else:
        paper_dict = {
            'short_cit': cite_mini,
            'doi': doi,
            'date': str(date),
            'title': title,
            'journal': journal,
            'authors': papers_functions.list_to_string(authors_list)
        }

        result = {
            'status': 'success',
            'msg': 'Fields updated, click save to update the database',
            'issues': [],
            'paper': paper_dict
        }

    return jsonify(result=result)
Ejemplo n.º 3
0
def create_paper():
    form = PaperInfo()

    if 'doi' in session:
        doi = session['doi']
    else:
        doi = ''

    if form.validate_on_submit() == False:
        user = User.objects(id=current_user.id)[0]
        papers = Paper.objects(doi__iexact=doi)
        if len(papers) != 0:

            paper = papers[0]
            if paper.owner == user or user.has_role('super_contributor'):
                flash("Paper already in the database", 'success')
                return redirect(
                    url_for("biocatdb.submission_main_page",
                            paper_id=paper.id))

            elif paper.owner == None:
                flash(
                    'Paper already in database, self-assign the paper to add data',
                    'warning')
                return redirect(url_for("biocatdb.papers_that_need_data"))

            elif paper.owner != user and not user.has_role(
                    'super_contributor'):
                flash(
                    "Paper already in the database and is assigned to another user",
                    'danger')

            else:
                flash("error", 'danger')
                return redirect(url_for("biocatdb.launch_add_paper"))

        else:
            title, authors_list, journal, date, cite_mini = papers_crossref.get_metadata_from_crossref(
                doi)
            if cite_mini == '':
                title, authors_list, journal, date, cite_mini = papers_functions.query_pubmed(
                    doi)
            form.title.data = title
            form.authors.data = papers_functions.list_to_string(authors_list)
            form.journal.data = journal
            form.date.data = date
            form.short_cit.data = cite_mini
            form.doi.data = doi.replace(' ', '').lower()

            can_self_assign = papers_functions.can_self_assign(user)

            if cite_mini == '':
                flash(
                    "Paper not found in crossref, pubmed or db, please add manually",
                    'fail')
            else:
                flash("Paper found, please check information", 'success')

            return render_template(
                'add_paper_workflow/edit_paper_information.html',
                form=form,
                can_self_assign=can_self_assign)

    else:
        user = User.objects(id=current_user.id)[0]
        session.pop('doi')
        if form.self_assign.data == True:
            owner = user
        else:
            owner = None

        new_paper = Paper(doi=form.doi.data.replace(' ', '').lower(),
                          short_citation=form.short_cit.data,
                          title=form.title.data,
                          html='https://doi.org/' + form.doi.data,
                          journal=form.journal.data,
                          date=form.date.data,
                          tags=form.tags.data.split(', '),
                          authors=form.authors.data.split(', '),
                          owner=owner,
                          added_by=user,
                          status='Data required')
        new_paper.save()
        flash("Paper saved", 'success')

        if owner == user:
            return redirect(
                url_for("biocatdb.submission_main_page",
                        paper_id=new_paper.id))

        else:
            return redirect(url_for("biocatdb.launch_add_paper"))