def view_inproceedings_bib(id): db = get_db() cur = db.execute("select * from inproceedings where id = ?", [id]) ref = [ dict( id=row[0], bibtexkey=row[1], author=row[2], title=row[3], booktitle=row[4], year=row[5], editor=row[6], volume=row[7], number=row[8], series=row[9], pages=row[10], address=row[11], month=row[12], organization=row[13], publisher=row[14], note=row[15], ) for row in cur.fetchall() ] return inproceedings_to_bib(ref[0])
def add_inproceedings(): db = get_db() form = forms.ConferenceForm(request.form) if request.method == "POST" and form.validate(): db.execute( """INSERT INTO inproceedings (bibtexkey, author, title, booktitle, year, editor, volume, number, series, pages, address, month, organization, publisher, note) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, [ form.bibtexkey.data, form.author.data, form.title.data, form.booktitle.data, form.year.data, form.editor.data, form.volume.data, form.number.data, form.series.data, form.pages.data, form.address.data, form.month.data, form.organization.data, form.publisher.data, form.note.data, ], ) db.commit() return redirect("/refs") return render_template("add_inproceedings.html", form=form)
def add_book(): db = get_db() form = forms.BookForm(request.form) if request.method == "POST" and form.validate(): db.execute( """INSERT INTO books (bibtexkey, author, title, editor, publisher, year, volume, number, series, address, edition, month, note) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, [ form.bibtexkey.data, form.author.data, form.title.data, form.editor.data, form.publisher.data, form.year.data, form.volume.data, form.number.data, form.series.data, form.address.data, form.edition.data, form.month.data, form.note.data, ], ) db.commit() return redirect("/refs") return render_template("add_book.html", form=form)
def edit_booklet(id): ref = select_booklet(id)[0] form = forms.BookletForm(request.form) del form.bibtexkey if request.method == "GET": form.title.data = ref["title"] form.author.data = ref["author"] form.howpublished.data = ref["howpublished"] form.address.data = ref["address"] if ref["month"] != "NULL": form.month.data = ref["month"] if ref["year"] != "NULL": form.year.data = ref["year"] form.note.data = ref["note"] if request.method == "POST" and form.validate(): db = get_db() db.execute( """UPDATE booklets SET title = ?, author = ?, howpublished = ?, address = ?, month = ?, year = ?, note = ? WHERE bibtexkey = ?""", [ form.title.data, form.author.data, form.howpublished.data, form.address.data, form.month.data, form.year.data, form.note.data, ref["bibtexkey"], ], ) db.commit() return redirect(url_for("view_booklet", id=id)) return render_template("edit_booklet.html", form=form, ref=ref)
def add_article(): db = get_db() form = forms.ArticleForm(request.form) if request.method == "POST" and form.validate(): db.execute( """INSERT INTO articles (bibtexkey, author, title, journal, year, volume, number, pages, month, note) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, [ form.bibtexkey.data, form.author.data, form.title.data, form.journal.data, form.year.data, form.volume.data, form.number.data, form.pages.data, form.month.data, form.note.data, ], ) db.commit() return redirect("/refs") return render_template("add_article.html", form=form)
def testBookRequiredFields(self): rv = self._postBook({"author": ""}) db = hauska.get_db() cur = db.execute("SELECT count(1) FROM books") self.assertEqual(cur.fetchone()[0], 0) self.assertIn("This field is required.", rv.data)
def testInproceedingsRequiredFields(self): rv = self._postInproceedings({"title": ""}) db = hauska.get_db() cur = db.execute("SELECT count(1) FROM inproceedings") self.assertEqual(cur.fetchone()[0], 0) self.assertIn("This field is required.", rv.data)
def testDeletingReferenceActuallyDeletes(self): db = hauska.get_db() cur = db.execute("SELECT count(1) FROM articles") self.assertEqual(cur.fetchone()[0], 0) rv = self.app.post("/add/article", data={ "bibtexkey": "xx1", "author": "123", "title": "123", "journal": "123", "year": "123", "volume": "123", "number": "123", "pages": "123", "month": "123", "note": "123", }, follow_redirects=True) cur = db.execute("SELECT count(1) FROM articles") self.assertEqual(cur.fetchone()[0], 1) self.assertEqual(rv.status_code, 200) self.assertIn("bibtex key: xx1", rv.data) #send form containing bibtexkey to /delete via button in view_<ref>.html rv = self.app.post("/delete", data={ "bibtexkey": "xx1" }, follow_redirects=True) self.assertNotIn("bibtex key: xx1", rv.data)
def testRefs(self): db = hauska.get_db() db.execute("""INSERT INTO articles (bibtexkey, author, title, journal, year, volume, number, pages, month, note) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ["123"]*10) rv = self.app.get("/refs") assert 'No entries yet' not in rv.data
def testCannotSubmitDuplicateArticle(self): db = get_db() self._postArticle() cur = db.execute("SELECT count(1) FROM articles WHERE bibtexkey=1") self.assertEqual(cur.fetchone()[0], 1) rv = self._postArticle() cur = db.execute("SELECT count(1) FROM articles WHERE bibtexkey=1") self.assertEqual(cur.fetchone()[0], 1) self.assertIn("This reference name already exists", rv.data)
def bibtexkey_exists(bibtexkey): db = get_db() for table in ['articles', 'books', 'booklets', 'conferences', 'inbooks', 'incollections', 'inproceedings', 'manuals', 'masterstheses', 'miscs', 'phdtheses', 'proceedings', 'techreports', 'unpublished',]: cur = db.execute("SELECT count(id) FROM %s WHERE bibtexkey=?" % table, [bibtexkey]) count, = cur.fetchone() if count > 0: return True return False
def testAddingBookletActuallyAdds(self): db = hauska.get_db() cur = db.execute("SELECT count(1) FROM booklets") self.assertEqual(cur.fetchone()[0], 0) rv = self._postBooklet() cur = db.execute("SELECT count(1) FROM booklets") self.assertEqual(cur.fetchone()[0], 1) self.assertEqual(rv.status_code, 200) self.assertIn("bibtex key: 3", rv.data)
def testAddingConferenceActuallyAdds(self): db = hauska.get_db() cur = db.execute("SELECT count(1) FROM conferences") self.assertEqual(cur.fetchone()[0], 0) rv = self._postConference() cur = db.execute("SELECT count(1) FROM conferences") self.assertEqual(cur.fetchone()[0], 1) self.assertEqual(rv.status_code, 200) self.assertIn("bibtex key: 4", rv.data)
def testAddingInproceedingsActuallyAdds(self): db = hauska.get_db() cur = db.execute("SELECT count(1) FROM inproceedings") self.assertEqual(cur.fetchone()[0], 0) rv = self._postInproceedings() cur = db.execute("SELECT count(1) FROM inproceedings") self.assertEqual(cur.fetchone()[0], 1) self.assertEqual(rv.status_code, 200) self.assertIn("bibtex key: 5", rv.data)
def edit_inproceedings(id): ref = select_inproceedings(id)[0] form = forms.ConferenceForm(request.form) del form.bibtexkey if request.method == "GET": form.author.data = ref["author"] form.title.data = ref["title"] form.booktitle.data = ref["booktitle"] form.year.data = ref["year"] form.editor.data = ref["editor"] if ref["volume"] != "NULL": form.volume.data = ref["volume"] if ref["number"] != "NULL": form.number.data = ref["number"] form.series.data = ref["series"] form.pages.data = ref["pages"] form.address.data = ref["address"] if ref["month"] != "NULL": form.month.data = ref["month"] form.organization.data = ref["organization"] form.publisher.data = ref["publisher"] form.note.data = ref["note"] if request.method == "POST" and form.validate(): db = get_db() db.execute( """UPDATE inproceedings SET author = ?, title = ?, booktitle = ?, year = ?, editor = ?, volume = ?, number = ?, series = ?, pages = ?, address = ?, month = ?, organization = ?, publisher = ?, note = ? WHERE bibtexkey = ?""", [ form.author.data, form.title.data, form.booktitle.data, form.year.data, form.editor.data, form.volume.data, form.number.data, form.series.data, form.pages.data, form.address.data, form.month.data, form.organization.data, form.publisher.data, form.note.data, ref["bibtexkey"], ], ) db.commit() return redirect(url_for("view_inproceedings", id=id)) return render_template("edit_inproceedings.html", form=form, ref=ref)
def edit_book(id): ref = select_book(id)[0] form = forms.BookForm(request.form) del form.bibtexkey if request.method == "GET": # validaattorin kierto käyttämällä epätodennäköistä placeholder avainta # form.bibtexkey.data = ref['bibtexkey']+'_*EDIT*_#EDIT#' form.title.data = ref["title"] form.author.data = ref["author"] form.editor.data = ref["editor"] form.publisher.data = ref["publisher"] form.year.data = ref["year"] if ref["volume"] != "NULL": form.volume.data = ref["volume"] if ref["number"] != "NULL": form.number.data = ref["number"] form.series.data = ref["series"] form.address.data = ref["address"] form.edition.data = ref["edition"] if ref["month"] != "NULL": form.month.data = ref["month"] form.note.data = ref["note"] if request.method == "POST" and form.validate(): db = get_db() db.execute( """UPDATE books SET title = ?, author = ?, editor = ?, publisher = ?, year = ?, volume = ?, number = ?, series = ?, address = ?, edition = ?, month = ?, note = ? WHERE bibtexkey = ?""", [ form.title.data, form.author.data, form.editor.data, form.publisher.data, form.year.data, form.volume.data, form.number.data, form.series.data, form.address.data, form.edition.data, form.month.data, form.note.data, ref["bibtexkey"], ], ) db.commit() return redirect(url_for("view_book", id=id)) return render_template("edit_book.html", form=form, ref=ref)
def select_booklet(id): db = get_db() cur = db.execute("select * from booklets where id = ?", [id]) return [ dict( id=row[0], bibtexkey=row[1], title=row[2], author=row[3], howpublished=row[4], address=row[5], month=row[6], year=row[7], note=row[8], ) for row in cur.fetchall() ]
def delete_with_key(key): # koska bibtexkey on uniikki kaikilla tauluilla, # vain yksi entry poistetaan db = get_db() del1 = """DELETE FROM articles WHERE bibtexkey = ?""" db.execute(del1, [key]) db.commit() del2 = """DELETE FROM books WHERE bibtexkey = ?""" db.execute(del2, [key]) db.commit() del3 = """DELETE FROM booklets WHERE bibtexkey = ?""" db.execute(del3, [key]) db.commit() del4 = """DELETE FROM conferences WHERE bibtexkey = ?""" db.execute(del4, [key]) db.commit() del5 = """DELETE FROM inproceedings WHERE bibtexkey = ?""" db.execute(del5, [key]) db.commit()
def select_article(id): db = get_db() cur = db.execute("select * from articles where id = ?", [id]) return [ dict( id=row[0], bibtexkey=row[1], author=row[2], title=row[3], journal=row[4], year=row[5], volume=row[6], number=row[7], pages=row[8], month=row[9], note=row[10], ) for row in cur.fetchall() ]
def select_book(id): db = get_db() cur = db.execute("select * from books where id = ?", [id]) return [ dict( id=row[0], bibtexkey=row[1], title=row[2], author=row[3], editor=row[4], publisher=row[5], year=row[6], volume=row[7], number=row[8], series=row[9], address=row[10], edition=row[11], month=row[12], note=row[13], ) for row in cur.fetchall() ]
def add_booklet(): db = get_db() form = forms.BookletForm(request.form) if request.method == "POST" and form.validate(): db.execute( """INSERT INTO booklets (bibtexkey, author, title, howpublished, address, month, year, note) VALUES (?, ?, ?, ?, ?, ?, ?, ?) """, [ form.bibtexkey.data, form.author.data, form.title.data, form.howpublished.data, form.address.data, form.month.data, form.year.data, form.note.data, ], ) db.commit() return redirect("/refs") return render_template("add_booklet.html", form=form)
def edit_article(id): ref = select_article(id)[0] form = forms.ArticleForm(request.form) del form.bibtexkey if request.method == "GET": form.author.data = ref["author"] form.title.data = ref["title"] form.journal.data = ref["journal"] form.year.data = ref["year"] form.volume.data = ref["volume"] if ref["number"] != "NULL": form.number.data = ref["number"] form.pages.data = ref["pages"] if ref["month"] != "NULL": form.month.data = ref["month"] form.note.data = ref["note"] if request.method == "POST" and form.validate(): db = get_db() db.execute( """UPDATE articles SET author = ?, title = ?, journal = ?, year = ?, volume = ?, number = ?, pages = ?, month = ?, note = ? WHERE bibtexkey = ?""", [ form.author.data, form.title.data, form.journal.data, form.year.data, form.volume.data, form.number.data, form.pages.data, form.month.data, form.note.data, ref["bibtexkey"], ], ) db.commit() return redirect(url_for("view_article", id=id)) return render_template("edit_article.html", form=form, ref=ref)
def list_refs(): db = get_db() cur = db.execute("select id, bibtexkey from articles ORDER BY id asc") articles = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from books ORDER BY id asc") books = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from booklets ORDER BY id asc") booklets = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from conferences ORDER BY id asc") conferences = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from inbooks ORDER BY id asc") inbooks = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from incollections ORDER BY id asc") incollections = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from inproceedings ORDER BY id asc") inproceedings = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from manuals ORDER BY id asc") manuals = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from masterstheses ORDER BY id asc") masterstheses = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from miscs ORDER BY id asc") miscs = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from phdtheses ORDER BY id asc") phdtheses = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from proceedings ORDER BY id asc") proceedings = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from techreports ORDER BY id asc") techreports = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] cur = db.execute("select id, bibtexkey from unpublished ORDER BY id asc") unpublished = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # print refs no_entries = not any( [ articles, books, booklets, conferences, inbooks, incollections, inproceedings, manuals, masterstheses, miscs, phdtheses, proceedings, techreports, unpublished, ] ) return render_template( "refs.html", articles=articles, books=books, booklets=booklets, conferences=conferences, inbooks=inbooks, incollections=incollections, inproceedings=inproceedings, manuals=manuals, masterstheses=masterstheses, miscs=miscs, phdtheses=phdtheses, proceedings=proceedings, techreports=techreports, unpublished=unpublished, no_entries=no_entries, )
def list_refs_bib(): bibtex_compilation = [] db = get_db() cur = db.execute("select * from articles ORDER BY id asc") articles = [ dict( id=row[0], bibtexkey=row[1], author=row[2], title=row[3], journal=row[4], year=row[5], volume=row[6], number=row[7], pages=row[8], month=row[9], note=row[10], ) for row in cur.fetchall() ] bibtex_compilation.extend(article_to_bib(ref) for ref in articles) cur = db.execute("select * from books ORDER BY id asc") books = [ dict( id=row[0], bibtexkey=row[1], title=row[2], author=row[3], editor=row[4], publisher=row[5], year=row[6], volume=row[7], number=row[8], series=row[9], address=row[10], edition=row[11], month=row[12], note=row[13], ) for row in cur.fetchall() ] bibtex_compilation.extend(book_to_bib(ref) for ref in books) cur = db.execute("select * from booklets ORDER BY id asc") booklets = [ dict( id=row[0], bibtexkey=row[1], title=row[2], author=row[3], howpublished=row[4], address=row[5], month=row[6], year=row[7], note=row[8], ) for row in cur.fetchall() ] bibtex_compilation.extend(booklet_to_bib(ref) for ref in booklets) cur = db.execute("select * from conferences ORDER BY id asc") conferences = [ dict( id=row[0], bibtexkey=row[1], author=row[2], title=row[3], booktitle=row[4], year=row[5], editor=row[6], volume=row[7], number=row[8], series=row[9], pages=row[10], address=row[11], month=row[12], organization=row[13], publisher=row[14], note=row[15], ) for row in cur.fetchall() ] bibtex_compilation.extend(conference_to_bib(ref) for ref in conferences) cur = db.execute("select * from inbooks ORDER BY id asc") inbooks = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(inbook_to_bib(ref) for ref in inbooks) cur = db.execute("select * from incollections ORDER BY id asc") incollections = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(incollection_to_bib(ref) for ref in incollections) cur = db.execute("select * from inproceedings ORDER BY id asc") inproceedings = [ dict( id=row[0], bibtexkey=row[1], author=row[2], title=row[3], booktitle=row[4], year=row[5], editor=row[6], volume=row[7], number=row[8], series=row[9], pages=row[10], address=row[11], month=row[12], organization=row[13], publisher=row[14], note=row[15], ) for row in cur.fetchall() ] bibtex_compilation.extend(inproceedings_to_bib(ref) for ref in inproceedings) cur = db.execute("select * from manuals ORDER BY id asc") manuals = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(manual_to_bib(ref) for ref in manuals) cur = db.execute("select * from masterstheses ORDER BY id asc") masterstheses = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(masterthesis_to_bib(ref) for ref in mastertheses) cur = db.execute("select * from miscs ORDER BY id asc") miscs = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(misc_to_bib(ref) for ref in miscs) cur = db.execute("select * from phdtheses ORDER BY id asc") phdtheses = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(phdthesis_to_bib(ref) for ref in phdtheses) cur = db.execute("select * from proceedings ORDER BY id asc") proceedings = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(proceeding_to_bib(ref) for ref in proceedings) cur = db.execute("select * from techreports ORDER BY id asc") techreports = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(techreport_to_bib(ref) for ref in techreports) cur = db.execute("select * from unpublished ORDER BY id asc") unpublished = [dict(id=row[0], bibtexkey=row[1]) for row in cur.fetchall()] # bibtex_compilation.extend(unpublished_to_bib(ref) for ref in unpublished) return "\n".join(bibtex_compilation)