示例#1
0
def addBook():
    if 'editor' not in current_user.roles and 'admin' not in current_user.roles:
        flash(u'Bu sayfaya erişim izniniz yok.', 'warning')
        return redirect(url_for('index'))
    form = BookAddForm(request.form)
    if form.validate_on_submit():
        author = dao.getObject(form.author.data, Author)
        
        publisher = None
        ebook_fname = None
        image_fname = None
        if form.publisher.data:
            publisher = dao.getObject(form.publisher.data, Publisher)
        if form.ebook.data:
            ebook_fname = ebooks.save(request.files[form.ebook.name])
        if form.image.data:
            image_fname = book_images.save(request.files[form.image.name])
        book = Book(
                name = form.name.data,
                author = author,
                publication_place= form.publication_place.data,
                publication_year= form.publication_year.data,
                publisher = publisher,
                isbn = form.isbn.data,
                page_amount = form.page_amount.data,
                description = form.description.data,
                ebook_fname = ebook_fname,
                image_fname = image_fname
        )
        dao.addObject(book)
        dao.commit();
        flash('Kitap eklendi.', 'info')
        return redirect(url_for('index'))
    return render_template('add_book.html', form=form)
示例#2
0
def bookPage(book_id):
    book = dao.getObject(book_id, Book)
    if book is None:
        flash('Kitap bulunmuyor', 'warning')
        return redirect(request.referrer or '/')
    assoc = dao.findUserBook(current_user.id, book_id)
    return render_template('book_page.html', book=book, assoc=assoc, comment_form=WriteCommentForm())
示例#3
0
def registerUser():
    form = UserRegisterForm(request.form)
    if form.validate_on_submit():
        user = User(
                name = form.name.data,
                surname = form.surname.data,
                email = form.email.data,
                password = utils.encrypt_password(form.password.data),
                birth_date = form.birth_date.data,
                #country = form.country.data,
                il_id = form.il.data if form.il.data > 0 else None,
                ilce_id = form.ilce.data if form.ilce.data > 0 else None,
                semt_id = form.semt.data if form.semt.data > 0 else None,
                confirmed = False,
                active = True
        )
        for i in form.interests.data:
			#dao.addObject(interests_users(interest_id=i, user_id=user.id))
			user.interests.append(dao.getObject(i, InterestArea))
        dao.addObject(user)
        dao.commit()
        login_user(user)
        flash(u'Kayıt oldunuz', 'info')
        return redirect(url_for('index'))
    return render_template('register_user.html', form=form)
示例#4
0
def removeComment(comment_id):
    comment = dao.getObject(comment_id, Comment)
    if comment.user != current_user:
        return redirect(request.referrer or url_for('index'))
    dao.deleteObject(comment)
    dao.commit()
    flash("Yorum silindi!", 'info')
    return redirect(request.referrer or url_for('bookPage', book_id=comment.book.id))
示例#5
0
def removeNote(note_id):
    note = dao.getObject(note_id, Note)
    if note.user != current_user:
        return redirect(request.referrer or url_for('index'))
    dao.deleteObject(note)
    dao.commit()
    flash("Not silindi!", 'info')
    return redirect(request.referrer or url_for('bookPage', book_id=note.book.id))
示例#6
0
def deleteSummary(assoc_id):
    assoc = dao.getObject(assoc_id, UserBook)
    if assoc is None or assoc not in current_user.book_assocs or assoc.status != Status.have_read or assoc.summary == None:
        flash(u'Var olmayan bir özeti silemezsiniz!', 'warning')
        return redirect(request.referrer or url_for('index'))
    dao.deleteObject(assoc.summary)
    dao.commit()
    flash(u'Özet silindi!', 'info')
    return redirect(url_for('index'))
示例#7
0
def editComment(comment_id):
    comment = dao.getObject(comment_id, Comment)
    if comment is None or comment.user != current_user:
        flash(u'Bu yorumu düzenleyemezsiniz!', 'warning')
        return redirect(request.referrer or url_for('index'))
    comment.text = request.form["comment"]
    comment.time_last_modified = datetime.now()
    dao.commit()
    flash(u'Yorum düzenlendi!', 'info')
    return redirect(request.referrer or url_for('bookPage', book_id=comment.book.id))
示例#8
0
 def test_comment(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         self.app.get(
             '/add_book_to_user?book_id=1&status=3',
             follow_redirects=True
         )
         book = getObject(1, Book)
         self.assertIn(book, current_user.books)
         # create
         response = self.app.post(
             '/write_comment/1',
             data=dict(comment="Comment comment comment"),
             follow_redirects=True
         )
         self.assertIn("Yorum yazıldı!", response.data)
         self.assertIsNotNone(book.comments)
         self.assertNotEqual(book.comments, [])
         self.assertEqual("Comment comment comment", book.comments[0].text)
         # read
         response = self.app.get(
             '/bookread/1',
             follow_redirects=True
         )
         self.assertIn("Comment comment comment", response.data)
         self.assertIn(format_time(book.comments[0].time_created), response.data)
         response = self.app.get(
             '/book/1',
             follow_redirects=True
         )
         self.assertIn("Comment comment comment", response.data)
         self.assertIn(format_time(book.comments[0].time_created), response.data)
         # update
         response = self.app.post(
             '/edit_comment/1',
             data=dict(comment="Hede hodo hudu"),
             follow_redirects=True
         )
         self.assertIn("Yorum düzenlendi!", response.data)
         self.assertIn("Hede hodo hudu", response.data)
         self.assertIn(format_time(book.comments[0].time_last_modified), response.data)
         self.assertEqual("Hede hodo hudu", book.comments[0].text)
         # delete
         response = self.app.get(
             '/remove_comment/1',
             follow_redirects=True
         )
         self.assertIn("Yorum silindi!", response.data)
         self.assertNotIn("Hede hodo hudu", response.data)
         self.assertEqual(book.comments, [])
         self.assertEqual(current_user.comments, [])
示例#9
0
 def test_add_book_to_user(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         response = self.app.get(
             '/add_book_to_user?book_id=1&status=1',
             follow_redirects=True
         )
         book = getObject(1, Book)
         self.assertIn(book, current_user.books)
         self.assertEqual(response.status_code, 200)
示例#10
0
def editSummary(assoc_id):
    assoc = dao.getObject(assoc_id, UserBook)
    if assoc is None or assoc not in current_user.book_assocs or assoc.status != Status.have_read or assoc.summary == None:
        flash(u'Var olmayan bir özeti güncelleyemezsiniz!', 'warning')
        return redirect(request.referrer or url_for('index'))
    form = WriteSummaryForm(request.form)
    if form.validate_on_submit():
        assoc.summary.text = form.summary.data
        assoc.summary.time_last_modified = datetime.now()
        dao.commit()
        flash(u'Özet güncellendi!', 'info')
        return redirect(url_for('bookPage', book_id=assoc.book.id))
    elif request.method == 'GET':
        form.summary.data = assoc.summary.text
    return render_template('write_summary.html', form=form)
示例#11
0
 def test_summary(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         self.app.get(
             '/add_book_to_user?book_id=1&status=3',
             follow_redirects=True
         )
         book = getObject(1, Book)
         self.assertIn(book, current_user.books)
         # create
         response = self.app.post(
             '/write_summary/1',
             data=dict(summary="Summary summary summary"),
             follow_redirects=True
         )
         assoc = findUserBook(current_user.id, 1)
         self.assertIn("Özet yazıldı", response.data)
         self.assertIsNotNone(assoc.summary)
         self.assertEqual("Summary summary summary", assoc.summary.text)
         # read
         response = self.app.get(
             '/summary/1',
             follow_redirects=True
         )
         self.assertIn("Summary summary summary", response.data)
         self.assertIn("Özetleyen - Userguy Userson", response.data)
         # update
         response = self.app.post(
             '/edit_summary/1',
             data=dict(summary="Hede hodo hudu"),
             follow_redirects=True
         )
         self.assertIn("Özet güncellendi!", response.data)
         self.assertIn("Hede hodo hudu", response.data)
         self.assertIn(format_time(assoc.summary.time_last_modified), response.data)
         self.assertEqual("Hede hodo hudu", assoc.summary.text)
         # delete
         response = self.app.get(
             '/delete_summary/1',
             follow_redirects=True
         )
         self.assertIn("Özet silindi!", response.data)
         self.assertNotIn("Hede hodo hudu", response.data)
         self.assertIsNone(assoc.summary)
示例#12
0
def writeSummary(assoc_id):
    assoc = dao.getObject(assoc_id, UserBook)
    if assoc is None or assoc not in current_user.book_assocs or assoc.status != Status.have_read or assoc.summary != None:
        flash(u'Sadece okumuş olduğunuz kitaplar hakkında birer adet özet yazabilirsiniz!', 'warning')
        return redirect(request.referrer or url_for('index'))
    
    form = WriteSummaryForm(request.form)
    if form.validate_on_submit():
        summary = Summary(
            text = form.summary.data,
            time_created = datetime.now(),
            time_last_modified = None,
            userbook = assoc
        )
        dao.addObject(summary)
        dao.commit()
        flash(u'Özet yazıldı!', 'info')
        return redirect(url_for('bookPage', book_id=assoc.book.id))
    return render_template('write_summary.html', form=form)
示例#13
0
def writeComment(book_id):
    book = dao.getObject(book_id, Book)
    if book is None:
        flash(u'Böyle bir kitap yok!', 'warning')
        return redirect(request.referrer or url_for('index'))
        
    form = WriteCommentForm(request.form)
    if form.validate_on_submit():
        comment = Comment(
            text = form.comment.data,
            user = current_user,
            book = book,
            time_created = datetime.now(),
            time_last_modified = None
        )
        dao.addObject(comment)
        dao.commit()
        flash(u'Yorum yazıldı!', 'info')
    return redirect(request.referrer or url_for('bookPage', book_id=book.id))
示例#14
0
 def test_update_book_in_user(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         self.app.get(
             '/add_book_to_user?book_id=1&status=1',
             follow_redirects=True
         )
         book = getObject(1, Book)
         self.assertIn(book, current_user.books)
         response = self.app.get(
             '/update_book_list?book_id=1&status=2',
             follow_redirects=True
         )
         assoc = findUserBook(current_user.id, 1)
         self.assertEqual(assoc.status, 2)
         self.assertEqual(response.status_code, 200)
示例#15
0
 def test_add_book(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         response = self.app.post(
             '/add_book',
             data=dict(name="New Book", author="1", publication_place="Hedede", publication_year="1950", publisher="1", page_amount="500"),
             follow_redirects=True
         )
         self.assertIn(b'Kitap eklendi.', response.data)
         book = getObject(5, Book)
         self.assertEqual("New Book", book.name)
         self.assertEqual("Tolstoy", book.author.surname)
         self.assertEqual("Hedede", book.publication_place)
         self.assertEqual(1950, book.publication_year)
         self.assertEqual("Bloomsbury", book.publisher.name)
         self.assertEqual(500, book.page_amount)
示例#16
0
def rateBook(assoc_id):
    rate = int(request.args.get("rate"))
    if rate is None or rate not in [-1, 1]:
        return redirect(url_for('home'))
    assoc = dao.getObject(assoc_id, UserBook)
    if assoc.rating == 0:
        assoc.rating = rate
        assoc.book.score_amount += 1
        if rate == 1:
            assoc.book.like_amount += 1
    elif assoc.rating == rate:
        assoc.rating = 0
        assoc.book.score_amount -= 1
        if rate == 1:
            assoc.book.like_amount -= 1
    else:
        assoc.rating = rate
        assoc.book.like_amount += 1 if rate == 1 else -1
    dao.commit()
    return redirect(request.referrer or url_for('index'))
示例#17
0
 def test_note(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         self.app.get(
             '/add_book_to_user?book_id=1&status=2',
             follow_redirects=True
         )
         book = getObject(1, Book)
         self.assertIn(book, current_user.books)
         # create
         response = self.app.post(
             '/write_note/1',
             data=dict(page=10, note="Note note note"),
             follow_redirects=True
         )
         assoc = findUserBook(current_user.id, 1)
         self.assertIn("Not yazıldı!", response.data)
         self.assertIsNotNone(assoc.notes)
         self.assertNotEqual(assoc.notes, [])
         self.assertEqual("Note note note", assoc.notes[0].text)
         self.assertEqual(10, assoc.notes[0].page)
         self.assertFalse(assoc.notes[0].is_public)
         # read note in the user page
         response = self.app.get(
             '/userpage',
             follow_redirects=True
         )
         self.assertIn("Note note note", response.data)
         self.assertIn(format_time(assoc.notes[0].time_created), response.data)
         # delete
         response = self.app.get(
             '/remove_note/1',
             follow_redirects=True
         )
         self.assertIn("Not silindi!", response.data)
         self.assertNotIn("Note note note", response.data)
         self.assertEqual(assoc.notes, [])
示例#18
0
def writeNote(assoc_id):
    assoc = dao.getObject(assoc_id, UserBook)
    if assoc is None or assoc.status != Status.reading:
        flash(u"Okumakta olmadığınız bir kitaba not alamazsınız", 'warning')
        return redirect(request.referrer or url_for('index'))
    note_form = WriteNoteForm(request.form)
    if note_form.validate_on_submit():
        note = Note(
            text = note_form.note.data,
            page = note_form.page.data,
            is_public = note_form.is_public.data,
            userbook = assoc,
            time_created = datetime.now(),
            time_last_modified = None
        )
        dao.addObject(note)
        dao.commit()
        flash(u'Not yazıldı!', 'info')
        return redirect(url_for('bookRead', book_id=assoc.book.id))
    else:
        flash(u'Not yazımı hatalı!', 'info')
        return redirect(url_for('bookRead', book_id=assoc.book.id, hide=""))
示例#19
0
 def test_rate(self):
     with self.app:
         self.app.post(
             '/login',
             data=dict(email="*****@*****.**", password="******"),
             follow_redirects=True
         )
         self.app.get(
             '/add_book_to_user?book_id=1&status=3',
             follow_redirects=True
         )
         book = getObject(1, Book)
         assoc = findUserBook(current_user.id, 1)
         self.assertIn(book, current_user.books)
         self.assertEqual(book.like_amount, 0)
         self.assertEqual(book.score_amount, 0)
         self.assertEqual(assoc.rating, 0)
         # 0 -> 1
         self.app.get(
             '/ratebook/1?rate=1'
         )
         self.assertEqual(book.like_amount, 1)
         self.assertEqual(book.score_amount, 1)
         self.assertEqual(assoc.rating, 1)
         # 1 -> 0
         self.app.get(
             '/ratebook/1?rate=1'
         )
         self.assertEqual(book.like_amount, 0)
         self.assertEqual(book.score_amount, 0)
         self.assertEqual(assoc.rating, 0)
         # 0 -> -1
         self.app.get(
             '/ratebook/1?rate=-1'
         )
         self.assertEqual(book.like_amount, 0)
         self.assertEqual(book.score_amount, 1)
         self.assertEqual(assoc.rating, -1)
         # -1 -> 0
         self.app.get(
             '/ratebook/1?rate=-1'
         )
         self.assertEqual(book.like_amount, 0)
         self.assertEqual(book.score_amount, 0)
         self.assertEqual(assoc.rating, 0)
         # -1 -> 1
         self.app.get(
             '/ratebook/1?rate=-1'
         )
         self.app.get(
             '/ratebook/1?rate=1'
         )
         self.assertEqual(book.like_amount, 1)
         self.assertEqual(book.score_amount, 1)
         self.assertEqual(assoc.rating, 1)
         # 1 -> -1
         self.app.get(
             '/ratebook/1?rate=-1'
         )
         self.assertEqual(book.like_amount, 0)
         self.assertEqual(book.score_amount, 1)
         self.assertEqual(assoc.rating, -1)
示例#20
0
def summaryPage(sum_id):
    summary = dao.getObject(sum_id, Summary)
    if summary is None:
        flash(u'Özet bulunmuyor', 'warning')
        return redirect(request.referrer or '/')
    return render_template('summary_page.html', summary=summary)