Esempio n. 1
0
def find(request, keyword = "", page = 1):
	
	page = int(page)
	
	if "keywords" in request.GET:
		keyword = request.GET["keywords"]
	
	results = []
	
	if keyword:
		results = GoogleBooks().search(keyword, page)
		
		template_values = {
			'totalResults': results.TotalResults,
			'results': results.items,
			'keywords' : keyword
		}
		
		paging.preparePagingTemplateForSearch(template_values, page, results.TotalResults)
		
	else:
		template_values = {}
		
	if Reader.byCurrentUser():
		template_values["isLoggedIn"] = True
	
	# load template
	t = get_template('searchresults.html')
	html = t.render(Context(template_values))
	
	return HttpResponse(html)
Esempio n. 2
0
def markAsTodo(request, identifier):
	book = Book().get(db.Key(identifier))
	readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book)
	readerBook.state = 'unread'
	readerBook.put()
	
	return redirectToBook(book)
Esempio n. 3
0
def create(request):

    user = users.get_current_user()

    if not user:
        HttpResponseRedirect('/reader/')

    username = request.POST["username"]

    if not re.match(r"^\w{4,16}$", username):
        return index(
            request,
            "Username can contain only letters and digits, 4-16 characters long"
        )

    r = Reader.byCurrentUser()

    if not r:
        r = Reader()

    r.name = request.POST["name"]
    r.username = username
    r.email = user.email()
    r.id = user.user_id()

    r.put()

    return HttpResponseRedirect('/reader')
Esempio n. 4
0
def delete(request, identifier):
    book = Book().get(identifier)
    readerBook = ReaderBook().byReaderAndBook(Reader.byCurrentUser(), book)

    readerBook.delete()

    return HttpResponseRedirect('/')
Esempio n. 5
0
def find(request, keyword="", page=1):

    page = int(page)

    if "keywords" in request.GET:
        keyword = request.GET["keywords"]

    results = []

    if keyword:
        results = GoogleBooks().search(keyword, page)

        template_values = {
            'totalResults': results.TotalResults,
            'results': results.items,
            'keywords': keyword
        }

        paging.preparePagingTemplateForSearch(template_values, page,
                                              results.TotalResults)

    else:
        template_values = {}

    if Reader.byCurrentUser():
        template_values["isLoggedIn"] = True

    # load template
    t = get_template('searchresults.html')
    html = t.render(Context(template_values))

    return HttpResponse(html)
Esempio n. 6
0
def markAsTodo(request, identifier):
    book = Book().get(db.Key(identifier))
    readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book)
    readerBook.state = 'unread'
    readerBook.put()

    return redirectToBook(book)
Esempio n. 7
0
def delete(request, identifier):
	book = Book().get(identifier)
	readerBook = ReaderBook().byReaderAndBook(Reader.byCurrentUser(), book)
	
	readerBook.delete()
	
	return HttpResponseRedirect('/')
Esempio n. 8
0
def ajaxAddBook(request):
	reader = Reader.byCurrentUser()
	if not reader:
		return HttpResponse("Login or create account to add books")
	
	book = fetchCreateByISBN(request.POST["isbn"], invokeSearchByIsbn, True)
	
	createReaderBookIfNecessary(reader, book, request.POST["state"])
	
	return HttpResponse("success")
Esempio n. 9
0
def ajaxAddBook(request):
    reader = Reader.byCurrentUser()
    if not reader:
        return HttpResponse("Login or create account to add books")

    book = fetchCreateByISBN(request.POST["isbn"], invokeSearchByIsbn, True)

    createReaderBookIfNecessary(reader, book, request.POST["state"])

    return HttpResponse("success")
Esempio n. 10
0
def delete(request):

    r = Reader.byCurrentUser()

    if r:
        list = ReaderBook.all(keys_only=True).ancestor(r).fetch(1000)
        db.delete(list)
        r.delete()
    else:
        return HttpResponseRedirect('/')

    return HttpResponse(render('reader_delete_confirm.html', None))
Esempio n. 11
0
def addToReader(request):

    reader = Reader.byCurrentUser()
    if not reader:
        return HttpResponseRedirect('/')

    bookResult = SearchResult()
    bookResult.isbn = request.POST["isbn"]
    bookResult.detailUrl = request.POST["detailUrl"]
    bookResult.author = request.POST["author"]
    bookResult.title = request.POST["title"]
    bookResult.image = request.POST["image"]
    bookResult.imageSmall = request.POST["imageSmall"]
    bookResult.imageLarge = request.POST["imageLarge"]
    bookResult.numberOfPages = int(request.POST["numberOfPages"])

    book = fetchCreateByISBN(request.POST["isbn"], bookResult, False)

    createReaderBookIfNecessary(reader, book, 'unread')

    return redirectToBook(book)
Esempio n. 12
0
def addToReader(request):
	
	reader = Reader.byCurrentUser()
	if not reader:
		return HttpResponseRedirect('/')

	bookResult = SearchResult()
	bookResult.isbn = request.POST["isbn"]
	bookResult.detailUrl = request.POST["detailUrl"]
	bookResult.author = request.POST["author"]
	bookResult.title = request.POST["title"]
	bookResult.image = request.POST["image"]
	bookResult.imageSmall = request.POST["imageSmall"]
	bookResult.imageLarge = request.POST["imageLarge"]
	bookResult.numberOfPages = int(request.POST["numberOfPages"])
	
	book = fetchCreateByISBN(request.POST["isbn"], bookResult, False)
	
	createReaderBookIfNecessary(reader, book, 'unread')
	
	return redirectToBook(book)
Esempio n. 13
0
def viewByIsbn(request, isbn = ""):
	
	user = users.get_current_user()
	reader = None
	book = None
	readerBook = None
	
	if user:
		reader = Reader.byCurrentUser()
	
	book = fetchCreateByISBN(isbn, invokeSearchByIsbn, True)
	
	readerBook = ReaderBook.byReaderAndBook(reader, book)
		
	template_values = mapping.toReaderBookTemplate(book, readerBook)
	
	if not user:
		template_values["loginUrlToAdd"] = users.create_login_url('/book/isbn/' + isbn)
	else:
		if not reader:
			template_values["signupUrl"] = '/reader'
	
	return render(template_values)
Esempio n. 14
0
def index(request, error=None):

    user = users.get_current_user()
    loginUrl = users.create_login_url('/reader')

    if not user:
        return HttpResponseRedirect(loginUrl)

    r = Reader.byCurrentUser()

    if not r:
        r = Reader()

        template_values = {
            "isLoggedIn": True,
            "isNew": True,
            "name": "",
            "username": user.nickname(),
            "email": user.email()
        }
    else:
        template_values = {
            "isLoggedIn": True,
            "isNew": False,
            "name": r.name,
            "username": r.username,
            "email": r.email
        }

    template_values["logoutUrl"] = users.create_logout_url("/")

    if error:
        template_values["errorMsg"] = error

    html = render('reader.html', template_values)

    return HttpResponse(html)
Esempio n. 15
0
def viewByIsbn(request, isbn=""):

    user = users.get_current_user()
    reader = None
    book = None
    readerBook = None

    if user:
        reader = Reader.byCurrentUser()

    book = fetchCreateByISBN(isbn, invokeSearchByIsbn, True)

    readerBook = ReaderBook.byReaderAndBook(reader, book)

    template_values = mapping.toReaderBookTemplate(book, readerBook)

    if not user:
        template_values["loginUrlToAdd"] = users.create_login_url(
            '/book/isbn/' + isbn)
    else:
        if not reader:
            template_values["signupUrl"] = '/reader'

    return render(template_values)
Esempio n. 16
0
def getCurrentUserBook(identifier):
    return ReaderBook.byReaderAndBook(Reader.byCurrentUser(),
                                      db.Key(identifier))
Esempio n. 17
0
def getCurrentUserBook(identifier):
	return ReaderBook.byReaderAndBook(Reader.byCurrentUser(), db.Key(identifier))
Esempio n. 18
0
def view(request, identifier):

    book = db.get(db.Key(identifier))
    readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book)

    return render(mapping.toReaderBookTemplate(book, readerBook))
Esempio n. 19
0
def view(request, identifier):

	book = db.get(db.Key(identifier))
	readerBook = ReaderBook.byReaderAndBook(Reader.byCurrentUser(), book)
	
	return render( mapping.toReaderBookTemplate(book, readerBook) )