Exemplo n.º 1
0
def add_publication(request, method):
    # check if user has edit permissions
    try:
        social = request.user.social_auth.get(provider='github')
        access_token = social.extra_data['access_token']
    except:
        access_token = ''
    if access_token:
        has_permission = has_commit_permission(access_token, 'dipy_web')
    else:
        has_permission = False

    # if user does not have edit permission:
    if not has_permission:
        raise PermissionDenied

    # if user has edit permission:
    if(method == "manual"):
        context = {}
        if request.method == 'POST':
            submitted_form = AddEditPublicationForm(request.POST)
            if submitted_form.is_valid():
                submitted_form.save()
                return redirect('/dashboard/publications/')
            else:
                context['form'] = submitted_form
                return render(request, 'website/addeditpublication.html',
                              context)

        form = AddEditPublicationForm()
        context['form'] = form
        return render(request, 'website/addeditpublication.html', context)
    elif(method == "bibtex"):
        if request.method == 'POST':
            bibtex_entered = request.POST.get('bibtex')
            try:
                bib_parsed = bibtexparser.loads(bibtex_entered)
                bibInfo = bib_parsed.entries[0]

                if 'title' in bibInfo:
                    title = bibInfo['title']
                else:
                    title = None

                if 'author' in bibInfo:
                    authors = bibInfo['author']
                elif 'authors' in bibInfo:
                    authors = bibInfo['aithors']
                else:
                    authors = None

                if 'url' in bibInfo:
                    url = bibInfo['url']
                elif 'link' in bibInfo:
                    url = bibInfo['link']
                elif 'doi' in bibInfo:
                    url = "http://dx.doi.org/" + bibInfo['doi']
                else:
                    url = None

                if(title and authors and url):
                    publicationObj = Publication(title=title,
                                                 author=authors,
                                                 url=url)
                    if 'ENTRYTYPE' in bibInfo:
                        publicationObj.entry_type = bibInfo['ENTRYTYPE']
                    if 'doi' in bibInfo:
                        publicationObj.doi = bibInfo['doi']
                    if 'journal' in bibInfo:
                        publicationObj.published_in = bibInfo['journal']
                    if 'booktitle' in bibInfo:
                        publicationObj.published_in = bibInfo['booktitle']
                    if 'publisher' in bibInfo:
                        publicationObj.publisher = bibInfo['publisher']
                    if 'year' in bibInfo:
                        publicationObj.year_of_publication = bibInfo['year']
                    if 'month' in bibInfo:
                        publicationObj.month_of_publication = bibInfo['month']
                    publicationObj.bibtex = bibtex_entered
                    publicationObj.save()
                    return redirect('/dashboard/publications/')

                else:
                    return render(request,
                                  'website/addpublicationbibtex.html', {})
            except:
                return render(request, 'website/addpublicationbibtex.html', {})

        else:
            return render(request, 'website/addpublicationbibtex.html', {})
    else:
        raise Http404("Not a valid method for adding publications.")
Exemplo n.º 2
0
def dashboard_publications(request):
    all_journal = JournalImage.objects.all()
    print(all_journal)
    all_publications = Publication.objects.all()
    context = {'all_journal': all_journal,
               'all_publications': all_publications}

    if request.method == 'POST':
        if 'journal' in request.POST:
            submitted_form = AddEditJournalForm(request.POST, request.FILES)
            if submitted_form.is_valid():
                submitted_form.save()
                return redirect(reverse('dashboard_publications'))
            else:
                messages.error(request, submitted_form.errors)
                context['journal_form'] = submitted_form
                return render(request, 'website/dashboard_publications.html', context)

        if 'manual' in request.POST:
            submitted_form = AddEditPublicationForm(request.POST, request.FILES)
            if submitted_form.is_valid():
                submitted_form.save()
                return redirect(reverse('dashboard_publications'))
            else:
                messages.error(request, submitted_form.errors)
                context['form'] = submitted_form
                return render(request, 'website/dashboard_publications.html', context)

        elif 'bibtex' in request.POST:
            bibtex_entered = request.POST.get('bibtex')
            try:
                bib_parsed = bibtexparser.loads(bibtex_entered)
                bib_info = bib_parsed.entries[0]

                if 'title' in bib_info:
                    title = bib_info['title']
                else:
                    title = None

                if 'author' in bib_info:
                    authors = bib_info['author']
                elif 'authors' in bib_info:
                    authors = bib_info['aithors']
                else:
                    authors = None

                if 'url' in bib_info:
                    url = bib_info['url']
                elif 'link' in bib_info:
                    url = bib_info['link']
                elif 'doi' in bib_info:
                    url = "http://dx.doi.org/" + bib_info['doi']
                else:
                    url = None

                if title and authors and url:
                    publication_obj = Publication(title=title, author=authors, url=url)
                    if 'ENTRYTYPE' in bib_info:
                        publication_obj.entry_type = bib_info['ENTRYTYPE']
                    if 'doi' in bib_info:
                        publication_obj.doi = bib_info['doi']
                    if 'journal' in bib_info:
                        publication_obj.published_in = bib_info['journal']
                    if 'booktitle' in bib_info:
                        publication_obj.published_in = bib_info['booktitle']
                    if 'publisher' in bib_info:
                        publication_obj.publisher = bib_info['publisher']
                    if 'year' in bib_info:
                        publication_obj.year_of_publication = bib_info['year']
                    if 'month' in bib_info:
                        publication_obj.month_of_publication = bib_info['month']
                        publication_obj.bibtex = bibtex_entered
                        publication_obj.save()
                    return redirect(reverse('dashboard_publications'))

                else:
                    return render(request, 'website/dashboard_publications.html', context)
            except Exception as e:
                messages.error(request, str(e))
                return render(request, 'website/dashboard_publications.html', context)

        else:
            raise Http404("Not a valid method for adding publications.")

    journal_form = AddEditJournalForm()
    form = AddEditPublicationForm()
    context['form'] = form
    context['journal_form'] = journal_form

    return render(request, 'website/dashboard_publications.html', context)
Exemplo n.º 3
0
def add_publication(request, method):
    # check if user has edit permissions
    try:
        social = request.user.social_auth.get(provider='github')
        access_token = social.extra_data['access_token']
    except:
        access_token = ''
    if access_token:
        has_permission = has_commit_permission(access_token, 'dipy_web')
    else:
        has_permission = False

    # if user does not have edit permission:
    if not has_permission:
        raise PermissionDenied

    # if user has edit permission:
    if (method == "manual"):
        context = {}
        if request.method == 'POST':
            submitted_form = AddEditPublicationForm(request.POST)
            if submitted_form.is_valid():
                submitted_form.save()
                return redirect('/dashboard/publications/')
            else:
                context['form'] = submitted_form
                return render(request, 'website/addeditpublication.html',
                              context)

        form = AddEditPublicationForm()
        context['form'] = form
        return render(request, 'website/addeditpublication.html', context)
    elif (method == "bibtex"):
        if request.method == 'POST':
            bibtex_entered = request.POST.get('bibtex')
            try:
                bib_parsed = bibtexparser.loads(bibtex_entered)
                bibInfo = bib_parsed.entries[0]

                if 'title' in bibInfo:
                    title = bibInfo['title']
                else:
                    title = None

                if 'author' in bibInfo:
                    authors = bibInfo['author']
                elif 'authors' in bibInfo:
                    authors = bibInfo['aithors']
                else:
                    authors = None

                if 'url' in bibInfo:
                    url = bibInfo['url']
                elif 'link' in bibInfo:
                    url = bibInfo['link']
                elif 'doi' in bibInfo:
                    url = "http://dx.doi.org/" + bibInfo['doi']
                else:
                    url = None

                if (title and authors and url):
                    publicationObj = Publication(title=title,
                                                 author=authors,
                                                 url=url)
                    if 'ENTRYTYPE' in bibInfo:
                        publicationObj.entry_type = bibInfo['ENTRYTYPE']
                    if 'doi' in bibInfo:
                        publicationObj.doi = bibInfo['doi']
                    if 'journal' in bibInfo:
                        publicationObj.published_in = bibInfo['journal']
                    if 'booktitle' in bibInfo:
                        publicationObj.published_in = bibInfo['booktitle']
                    if 'publisher' in bibInfo:
                        publicationObj.publisher = bibInfo['publisher']
                    if 'year' in bibInfo:
                        publicationObj.year_of_publication = bibInfo['year']
                    if 'month' in bibInfo:
                        publicationObj.month_of_publication = bibInfo['month']
                    publicationObj.bibtex = bibtex_entered
                    publicationObj.save()
                    return redirect('/dashboard/publications/')

                else:
                    return render(request, 'website/addpublicationbibtex.html',
                                  {})
            except:
                return render(request, 'website/addpublicationbibtex.html', {})

        else:
            return render(request, 'website/addpublicationbibtex.html', {})
    else:
        raise Http404("Not a valid method for adding publications.")
Exemplo n.º 4
0
def add_publication(request, method):
    if (method == "manual"):
        context = {'title': 'Add'}
        if request.method == 'POST':
            submitted_form = AddEditPublicationForm(request.POST)
            if submitted_form.is_valid():
                submitted_form.save()
                return redirect('/dashboard/publications/')
            else:
                context['form'] = submitted_form
                return render(request, 'website/addeditpublication.html',
                              context)

        form = AddEditPublicationForm()
        context['form'] = form
        return render(request, 'website/addeditpublication.html', context)
    elif (method == "bibtex"):
        if request.method == 'POST':
            bibtex_entered = request.POST.get('bibtex')
            try:
                bib_parsed = bibtexparser.loads(bibtex_entered)
                bibInfo = bib_parsed.entries[0]

                if 'title' in bibInfo:
                    title = bibInfo['title']
                else:
                    title = None

                if 'author' in bibInfo:
                    authors = bibInfo['author']
                elif 'authors' in bibInfo:
                    authors = bibInfo['aithors']
                else:
                    authors = None

                if 'url' in bibInfo:
                    url = bibInfo['url']
                elif 'link' in bibInfo:
                    url = bibInfo['link']
                elif 'doi' in bibInfo:
                    url = "https://doi.org/" + bibInfo['doi']
                else:
                    url = None

                if (title and authors and url):
                    publicationObj = Publication(title=title,
                                                 author=authors,
                                                 url=url)
                    if 'ENTRYTYPE' in bibInfo:
                        publicationObj.entry_type = bibInfo['ENTRYTYPE']
                    if 'doi' in bibInfo:
                        publicationObj.doi = bibInfo['doi']
                    if 'journal' in bibInfo:
                        publicationObj.published_in = bibInfo['journal']
                    if 'booktitle' in bibInfo:
                        publicationObj.published_in = bibInfo['booktitle']
                    if 'publisher' in bibInfo:
                        publicationObj.publisher = bibInfo['publisher']
                    if 'year' in bibInfo:
                        publicationObj.year_of_publication = bibInfo['year']
                    if 'month' in bibInfo:
                        publicationObj.month_of_publication = bibInfo['month']
                    publicationObj.bibtex = bibtex_entered
                    publicationObj.save()
                    return redirect('/dashboard/publications/')

                else:
                    return render(request, 'website/addpublicationbibtex.html',
                                  {})
            except Exception:
                return render(request, 'website/addpublicationbibtex.html', {})

        else:
            return render(request, 'website/addpublicationbibtex.html', {})
    else:
        raise Http404("Not a valid method for adding publications.")