Exemplo n.º 1
0
def download(bID):
    if request.method == "POST":
        file_id = bID
        link = mongoBook.get_link(file_id)
        mongoBook.count_download(file_id)

    return render_template('download.html', len=len(link), link=link)
Exemplo n.º 2
0
def download(bID):
    if request.method=="POST":
        file_id = bID
        link = mongoBook.get_link(file_id)
        mongoBook.count_download(file_id)
        webbrowser.open_new_tab(link)
    return redirect(url_for('content_detail', bID=bID))
Exemplo n.º 3
0
def get_file():
    if request.method == 'GET':
        return redirect(url_for('upload'))
    elif request.method == 'POST':
        file = request.files["file"]
        file.save(os.path.join(UPLOAD_FOLDER, secure_filename(file.filename)))

        form = request.form

        new_file = 'temp/' + secure_filename(file.filename)
        print(new_file)
        if '.pdf' in new_file:
            try:
                file_id = uploadFile(new_file, form['Name'])
                new_pdffile = PDF(new_file)
                page_count = new_pdffile.get_page_count()
                front = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=' + file_id
                print("successfully uploaded")

                mongoBook.post_book(file_id, form['Name'], form['Type'], form['Subject'],
                                    form['Author'], form['Description'], page_count, front)
                
                os.remove(new_file)
                return render_template('upload.html', display_navbar="inline", name=first_Name, picture=profile_pic, display_upload="block", uploadNoti="Successfully uploaded to AmongUSTH")
            except Exception as e:
                print(e)
                print('Cannot upload file!')
                return render_template('upload.html', display_navbar="inline", name=first_Name, picture=profile_pic, display_upload="block", uploadNoti="Upload failed! Please try again or contact us!")
Exemplo n.º 4
0
def content_detail(bID):
    global file_id
    global up_count, down_count
    global upvote
    global downvote
    global book
    up_count = 0
    down_count = 0
    file_id = str(bID)
    book = mongoBook.get_book(file_id)
    # print(book)
    # print(type(book))
    image_link = book["front"]
    # image_link = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=1ArSB7DUAsUgxppF-Oc99n5BrztO7s-Ti'
    download_count = book["download"]
    file_link = 'https://drive.google.com/file/d/' + file_id + '/view?usp=sharing'
    page_num = book["page_number"]
    description = book["description"]
    Author = book["author"]
    upvote = len(book['upvote'])
    downvote = len(book["downvote"])
    title = book["book_name"]

    # Display comments
    comment_content = []
    comment_user_name = []
    comment_user_profilepic = []
    comment_time = []
    data = mongoComment.get_all_comment(file_id)
    print(data)
    for cursor in data:
        comment_content.append(cursor['content'])
        comment_user_profilepic.append(
            mongoUsr.get_profile_pic(cursor['user_id']))
        comment_user_name.append(mongoUsr.get_name(cursor['user_id']))
        comment_time.append(cursor['time'])

    comment_content.reverse()
    comment_user_name.reverse()
    comment_time.reverse()
    comment_user_profilepic.reverse()

    up_icon = down_icon = ''
    
    if id_ in mongoBook.get_up(file_id):
        up_icon = '/static/images/up_active.png'
        down_icon = '/static/images/down_disabled.png'
    elif id_ in mongoBook.get_down(file_id):
        up_icon = '/static/images/up_disabled.png'
        down_icon = '/static/images/down_active.png'
    else:
        up_icon = '/static/images/up.png'
        down_icon = '/static/images/down.png'

    return render_template("content.html", comment_numb=len(comment_content), content=comment_content, time=comment_time, cusername=comment_user_name, cprofile_pic=comment_user_profilepic, display_navbar="inline", title=title, name=first_Name, picture=profile_pic, upvote_count=upvote, downvote_count=downvote, download_count=download_count, Author=Author, file_link=file_link, image_link=image_link, page_num=page_num, description=description, file_id=bID, up_icon = up_icon, down_icon = down_icon)
Exemplo n.º 5
0
def downvote():
    global down_count
    global downvote
    global up_count
    down_count += 1 
    if down_count % 2 == 0: 
        mongoBook.upvote_(file_id)
        downvote -= 1
        print('not down anymore')
    elif down_count % 2 != 0:
        mongoBook.upvote(file_id)
        downvote += 1
        print('down')
    return str(downvote)
Exemplo n.º 6
0
def upvote():
    global up_count 
    global upvote
    global down_count
    up_count += 1
    if up_count % 2 == 0: 
        mongoBook.upvote_(file_id)
        upvote -= 1
        print('not up anymore')
    elif up_count % 2 != 0:
        mongoBook.upvote(file_id)
        upvote += 1
        print('up')
    return str(upvote)
Exemplo n.º 7
0
def getfile():
    if request.method == 'GET':
        return redirect(url_for('upload'))
    elif request.method == 'POST':
        file = request.files["file"]
        file.save(os.path.join(UPLOAD_FOLDER, secure_filename(file.filename)))

        new_file = 'temp/' + secure_filename(file.filename)
        print(new_file)
        if '.pdf' in new_file:
            try:
                new_file_id = uploadFile_duplicate(
                    new_file, mongoBook.get_file_name(file_id))

                mongoBook.append_link(file_id, new_file_id)
                print("successfully uploaded")
                return render_template('upload.html', display_navbar="inline", name=first_Name, picture=profile_pic, display_upload="block", uploadNoti="Successfully uploaded to AmongUSTH")

            except Exception:
                print(Exception)
                print('Cannot upload file!')
        return render_template('upload.html', display_navbar="inline", name=first_Name, picture=profile_pic, display_upload="block", uploadNoti="Upload failed! Please try again or contact us!")
Exemplo n.º 8
0
def downvote():
    global down_count
    global downvote
    global up_count

    user_id = id_
    if user_id in mongoBook.get_down(file_id):
        mongoBook.downvote_(file_id, user_id)
        print('not down anymore')
    elif user_id not in mongoBook.get_down(file_id) and user_id not in mongoBook.get_up(file_id):
        mongoBook.downvote(file_id, user_id)
        print('down')
    # elif user_id in mongoBook.get_up(file_id):
    #     return "You already upvoted!"

    return str(len(mongoBook.get_down(file_id)))
Exemplo n.º 9
0
def get_file():
    if request.method == 'GET':
        return redirect(url_for('upload'))
    elif request.method == 'POST':
        file = request.files["file"]
        file.save(os.path.join(UPLOAD_FOLDER, secure_filename(file.filename)))

        form = request.form

        new_file = 'temp/' + secure_filename(file.filename)
        print(new_file)
        if '.pdf' in new_file:
            try:
                file_id = uploadFile(new_file, form['Name'])
                new_pdffile = PDF(new_file)
                page_count = new_pdffile.get_page_count()
                front = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=' + file_id
                print("successfully uploaded")
                
                mongoBook.post_book(file_id, form['Name'], form['Type'], form['Subject'], form['Author'], form['Description'], page_count, front)
            except Exception:
                print (Exception)
                print('Cannot upload file!')
        return redirect(url_for('upload'))
Exemplo n.º 10
0
def content():
    # global file_id
    # global up_count, down_count
    # global upvote
    # global downvote
    up_count = 0
    down_count = 0
    file_id = '1ArSB7DUAsUgxppF-Oc99n5BrztO7s-Ti'
    image_link = mongoBook.get_front(file_id)
    download_count = mongoBook.get_download(file_id)
    file_link = 'https://drive.google.com/file/d/' + file_id + '/view?usp=sharing'
    page_num = mongoBook.get_page_number(file_id)
    description = mongoBook.get_description(file_id)
    Author = mongoBook.get_author(file_id)
    upvote = mongoBook.get_upvote(file_id)
    downvote = mongoBook.get_downvote(file_id)
    title = mongoBook.get_file_name(file_id)

    return render_template("content.html", display_navbar="inline", title = title, name=first_Name, picture=profile_pic, upvote_count = upvote, downvote_count = downvote, download_count = download_count, Author = Author, file_link = file_link, image_link = image_link, page_num = page_num, description = description)
Exemplo n.º 11
0
def content_detail(bID):
    global file_id
    global up_count, down_count
    global upvote
    global downvote
    global book
    up_count = 0
    down_count = 0
    file_id = str(bID)
    book = mongoBook.get_book(file_id)
    print(book)
    print(type(book))
    image_link = book["front"]
    # image_link = 'https://drive.google.com/thumbnail?authuser=0&sz=w320&id=1ArSB7DUAsUgxppF-Oc99n5BrztO7s-Ti'
    download_count = book["download"]
    file_link = 'https://drive.google.com/file/d/' + file_id + '/view?usp=sharing'
    page_num = book["page_number"]
    description = book["description"]
    Author = book["author"]
    upvote = book["upvote"]
    downvote = book["downvote"]
    title = book["book_name"]

    return render_template("content.html", display_navbar="inline", title = title, name=first_Name, picture=profile_pic, upvote_count = upvote, downvote_count = downvote, download_count = download_count, Author = Author, file_link = file_link, image_link = image_link, page_num = page_num, description = description, file_id=bID)       
Exemplo n.º 12
0
def browse():
    books = list(book for book in mongoBook.get_all_books())
    return render_template("browse.html", display_navbar="inline", name=first_Name, picture=profile_pic, books = books)
Exemplo n.º 13
0
def browse():
    books = list(book for book in mongoBook.get_all_materials("Book"))
    documents = list(doc for doc in mongoBook.get_all_materials("Document"))
    slides = list(slide for slide in mongoBook.get_all_materials("Slide"))
    return render_template("browse.html", display_navbar="inline", name=first_Name, picture=profile_pic, books=books, docs=documents, slides=slides)
Exemplo n.º 14
0
 def refuse(id_):
     Book.set_status(id_, 'refuse')
Exemplo n.º 15
0
 def get_pending():
     Book.get_pending()
Exemplo n.º 16
0
 def approve(id_):
     Book.set_status(id_, 'aprove')