def upload(request): if request.method == "POST": form = forms.UploadForm(request.POST, request.FILES) if form.is_valid(): pub = Publication(user=request.user, image_file=request.FILES["image"]) pub.save() return HttpResponseRedirect("/")
def loadDatabase(self, bibtex_str): # load the bibtex entries into a database bib_database = bibtexparser.loads(bibtex_str) # print(bib_database.entries) for entry in bib_database.entries: pdf_file_loc = self.jon_webpage_url + get_val_key('local_pdf', entry) title = get_val_key('title', entry) print(str(exists(title)) + " " + title) # This is important because if local_pdf is not set then this part will crash, if a PDF is not included nothing will be done # TODO see what to do if no PDF is included # skip entry if PDF is missing, title is missing, or if title is already in the database if pdf_file_loc != self.jon_webpage_url and title != None and not exists(title): book_title = get_val_key('booktitle', entry) book_title_short = get_val_key('booktitle_short', entry) num_pages = get_val_key('numpages', entry) geo_location = get_val_key('location', entry) print(geo_location) video_url = get_val_key('video_url', entry) # Compare to pub_venue_type pub_type = get_val_key('pub_type', entry) date_text = get_val_key('month', entry) + ", " + get_val_key("year", entry) series = get_val_key('series', entry) isbn = get_val_key('isbn', entry) doi = get_val_key('doi', entry) publisher = get_val_key('published', entry) publisher_address = get_val_key('address', entry) page_range = get_val_key('pages', entry) acmid = get_val_key('acmid', entry) url = get_val_key('url', entry) # There are many ways that page range doesn't exist so this is to cover those cases if page_range != None and page_range != 'tbd' and page_range != '-' and page_range != "": # This is a workaround for entries with only one - instead of two if "-" in page_range and not "--" in page_range: page_start = page_range.split('-')[0] page_end = page_range.split('-')[1] else: page_start = page_range.split('--')[0] page_end = page_range.split('--')[1] # This is a workaround for entries with this form {9:1--9:27}, if ":" in page_start: page_start = page_start.split(":")[1] page_end = page_end.split(":")[1] else: page_start = None page_end = None date = datetime.strptime(date_text, '%B, %Y') print(date.date()) # Check type of pub and convert it to appropriate value if pub_type == None: pub_venue_type = "Other" elif "conference" in pub_type: pub_venue_type = "Conference" elif "journal" in pub_type: pub_venue_type = "Journal" elif "thesis" in pub_type: pub_venue_type = "MS Thesis" elif "workshop" in pub_type: pub_venue_type = "Workshop" elif "poster" in pub_type: pub_venue_type = "Poster" elif "book" in pub_type: pub_venue_type = "Book" # Is this right? # TODO Fix this. This is not correct. elif "doctoral_colloqium" in pub_type: pub_venue_type = "PhD Dissertation" # the rest aren't based on examples so they need to be checked over for consistency with established practice elif "demo" in pub_type: pub_venue_type = "Demo" elif "article" in pub_type: pub_venue_type = "Article" # This should probably be moved above book once it's been checked elif "book_chapter" in pub_type: pub_venue_type = "Book Chapter" elif "work_in_progress" in pub_type: pub_venue_type = "Work in Progress" elif "late_breaking" in pub_type: pub_venue_type = "Late Breaking Result" else: pub_venue_type = "Other" peer_reviewed_val = get_val_key('peer_reviewed', entry) if peer_reviewed_val == "yes": peer_reviewed = True else: peer_reviewed = False total_papers_submitted = get_val_key('total_paper_submitted', entry) total_papers_accepted = get_val_key('total_papers_accepted', entry) # Parse award choices award_name = get_val_key('award', entry) if award_name == None: award = None elif "Nomination" in award_name: award = "Best Paper Nominee" elif "Honorable Mention" in award_name: award = "Honorable Mention" elif "Award" in award_name: award = "Best Paper Award" else: award = None # Import file from web, then write it to a file, and finally open it as a File for django res = requests.get(pdf_file_loc) # TODO: update the filename so that it's FIRSTAUTHORLASTNAME_TITLECAMELCASE_VENUEYEAR.pdf filename = "import/temp/" + title + ".pdf" dirname = os.path.dirname(filename) if not os.path.exists(dirname): os.makedirs(dirname) temp_file = open(filename, 'wb') temp_file.write(res.content) temp_file.close() pdf_file = File(open(filename, 'rb')) video_url = get_val_key('video_url', entry) preview_video_url = get_val_key('video_preview_url', entry) if video_url != None and len(video_url) > 0: video = get_video(video_url, preview_video_url, date.date(), title, book_title_short) else: video = None # Create the new publication # Items have to be saved before you can do many to many queries new_pub = Publication(title=title, geo_location=geo_location, book_title=book_title, book_title_short=book_title_short, num_pages=num_pages, pub_venue_type=pub_venue_type, peer_reviewed=peer_reviewed, total_papers_accepted=total_papers_accepted, total_papers_submitted=total_papers_submitted, award=award, pdf_file=pdf_file, date=date.date(), video=video, series=series, isbn=isbn, doi=doi, publisher=publisher, publisher_address=publisher_address, acmid=acmid, page_num_start=page_start, page_num_end=page_end, official_url=url) new_pub.save() # Info on how to do the many to many stuff is from here https://docs.djangoproject.com/en/1.9/topics/db/examples/many_to_many/ # Parse authors author_str_list = parse_authors(get_val_key("author", entry)) author_obj_list = get_authors(author_str_list) for author in author_obj_list: new_pub.authors.add(author) # Parse keywords keyword_str_list = parse_keywords(get_val_key('keyword', entry)) keyword_obj_list = get_keywords(keyword_str_list) for keyword in keyword_obj_list: new_pub.keywords.add(keyword) project = get_val_key('project', entry) project_umbrellas = get_val_key('project_umbrellas', entry) if project != None and len(project) > 0: project_obj = get_project(project, project_umbrellas, author_obj_list, keyword_obj_list, new_pub) print(project_obj) new_pub.projects.add(project_obj) elif project_umbrellas != None and len(project_umbrellas) > 0: umbrellas = get_umbrellas(parse_umbrellas(project_umbrellas)) for umbrella in umbrellas: new_pub.project_umbrellas.add(umbrella) # Clean out import/temp os.system("rm import/temp/*")
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.")
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.")
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)
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.")