def shownotes(query): form = Search() if request.method == 'GET': has_starred = False list_of_files = [] all_files = [] list_of_files = [] uniq = {} try: books = indexer.search(query) for x in books: all_files = files.query.filter(files.filename.like(x)) for file in all_files: try: if uniq[file.filename]: print "Duplicate" except: list_of_files.append((file.filename,file.author,file.tags,file.semester,file.description,file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"),file.department)) uniq[file.filename] = True try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass except: pass indexed_search = files.query.whoosh_search(query) has_starred = False for file in indexed_search: try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass list_of_files.append((file.filename,file.author,file.tags,file.semester,file.description,file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"),file.department)) return render_template('notes.html',list_of_files = list_of_files , search_form = form) elif request.method == 'POST': if request.form.get('star'): print 'AHAHH' print '{0} is the form'.format(request.form) if request.form['star'] == '1': stars.add_star(request.form['file_id'], request.form['user_rno']) if request.form['star'] == '-1': stars.reduce_star(request.form['file_id'],request.form['user_rno']) return "F**K YEAH" if request.form.get('query'): query = request.form['query'] return redirect(url_for('shownotes',query = query))
def UploadOrView(name, semester): form = MetaData() search_form = Search() if request.method == 'GET': ''' Get all the files from the db and display to the user ''' all_files = files.query.filter(and_(files.department.like(name), files.semester.like(int(semester)))) has_starred = False list_of_files = [] for file in all_files.all(): try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass list_of_files.append((file.filename,file.author,file.tags,file.semester,file.description,file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d %b %Y %H:%M"),file.department)) list_of_files = list(set(list_of_files)) return render_template("notes.html", list_of_files=list_of_files, dept=name, sem=semester,form=form,search_form = Search()) elif request.method == 'POST': if request.form.get('star'): if request.form['star'] == '1': stars.add_star(request.form['file_id'], request.form['user_rno']) if request.form['star'] == '-1': stars.reduce_star(request.form['file_id'],request.form['user_rno']) return "F**K YEAH" if request.form.get('query'): query = request.form['query'] return redirect(url_for('shownotes',query = query))
def Upload(name, semester): form = MetaData() search_form = Search() if request.method == 'GET': return render_template("upload.html",dept=name, sem=semester,form=form,search_form = Search()) elif request.method == 'POST': if request.form.get('query'): query = request.form['query'] return redirect(url_for('shownotes',query = query)) if g.user.rollNo and g.user.dept==name: uploaded_files = request.files.getlist('pdf') picture_files = [] for file in uploaded_files: fileFormat = file.content_type if file and allowed_file(file.filename): filename = secure_filename(file.filename) checkformat = re.search(fileformat,filename) if checkformat: if checkformat.group(2) in ['png','jpg','jpeg','bmp','gif']: picture_files.append(filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) if len(picture_files) == 0: print ' this shouldnt happen' uploads = files(filename=filename, department=name, semester=semester, author= request.form['author'], tags = request.form['tags'], description = request.form['description'],downloads = 0, uploader = g.user.rollNo, upload_date = datetime.datetime.now()) db.session.add(uploads) db.session.commit() #indexing.apply_async((filename,)) #indexer.index_it(filename, fileFormat) if picture_files: picture_files = [app.config['UPLOAD_FOLDER']+'/'+f for f in picture_files] c = canvas.Canvas(app.config['UPLOAD_FOLDER'] + '/' + checkformat.group(1)+'.pdf',pagesize=(460.0,820.0)) width , height = (460.0,820.0) for pics in picture_files: c.drawImage(pics,0,0) c.showPage() c.save() uploads = files(filename=filename,department=name, semester=semester, author= request.form['author'], tags = request.form['tags'], description = request.form['description'],downloads = 0, uploader = g.user.rollNo, upload_date = datetime.datetime.now()) db.session.add(uploads) db.session.commit() all_files = files.query.filter(and_(files.department.like(name), files.semester.like(int(semester)))) has_starred = False list_of_files = [] for file in all_files.all(): try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass list_of_files.append((file.filename,file.author,file.tags,file.semester,file.description,file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"),file.department)) return redirect(url_for('UploadOrView',name=name, semester=semester) ) else: return redirect(url_for('navigate'))
def UploadOrView(name, semester): form = MetaData() search_form = Search() if request.method == 'GET': ''' Get all the files from the db and display to the user ''' all_files = files.query.filter( and_(files.department.like(name), files.semester.like(int(semester)))) has_starred = False list_of_files = [] for file in all_files.all(): try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass list_of_files.append( (file.filename, file.author, file.tags, file.semester, file.description, file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d %b %Y %H:%M"), file.department)) list_of_files = list(set(list_of_files)) return render_template("notes.html", list_of_files=list_of_files, dept=name, sem=semester, form=form, search_form=Search()) elif request.method == 'POST': if request.form.get('star'): if request.form['star'] == '1': stars.add_star(request.form['file_id'], request.form['user_rno']) if request.form['star'] == '-1': stars.reduce_star(request.form['file_id'], request.form['user_rno']) return "F**K YEAH" if request.form.get('query'): query = request.form['query'] return redirect(url_for('shownotes', query=query))
def shownotes(query): form = Search() if request.method == 'GET': has_starred = False list_of_files = [] all_files = [] list_of_files = [] uniq = {} try: books = indexer.search(query) for x in books: all_files = files.query.filter(files.filename.like(x)) for file in all_files: try: if uniq[file.filename]: print "Duplicate" except: list_of_files.append( (file.filename, file.author, file.tags, file.semester, file.description, file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"), file.department)) uniq[file.filename] = True try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass except: pass indexed_search = files.query.whoosh_search(query) has_starred = False for file in indexed_search: try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass list_of_files.append( (file.filename, file.author, file.tags, file.semester, file.description, file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"), file.department)) return render_template('notes.html', list_of_files=list_of_files, search_form=form) elif request.method == 'POST': if request.form.get('star'): print 'AHAHH' print '{0} is the form'.format(request.form) if request.form['star'] == '1': stars.add_star(request.form['file_id'], request.form['user_rno']) if request.form['star'] == '-1': stars.reduce_star(request.form['file_id'], request.form['user_rno']) return "F**K YEAH" if request.form.get('query'): query = request.form['query'] return redirect(url_for('shownotes', query=query))
def Upload(name, semester): form = MetaData() search_form = Search() if request.method == 'GET': return render_template("upload.html", dept=name, sem=semester, form=form, search_form=Search()) elif request.method == 'POST': if request.form.get('query'): query = request.form['query'] return redirect(url_for('shownotes', query=query)) if g.user.rollNo and g.user.dept == name: uploaded_files = request.files.getlist('pdf') picture_files = [] for file in uploaded_files: fileFormat = file.content_type if file and allowed_file(file.filename): filename = secure_filename(file.filename) checkformat = re.search(fileformat, filename) if checkformat: if checkformat.group(2) in [ 'png', 'jpg', 'jpeg', 'bmp', 'gif' ]: picture_files.append(filename) file.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) if len(picture_files) == 0: print ' this shouldnt happen' uploads = files(filename=filename, department=name, semester=semester, author=request.form['author'], tags=request.form['tags'], description=request.form['description'], downloads=0, uploader=g.user.rollNo, upload_date=datetime.datetime.now()) db.session.add(uploads) db.session.commit() #indexing.apply_async((filename,)) #indexer.index_it(filename, fileFormat) if picture_files: picture_files = [ app.config['UPLOAD_FOLDER'] + '/' + f for f in picture_files ] c = canvas.Canvas(app.config['UPLOAD_FOLDER'] + '/' + checkformat.group(1) + '.pdf', pagesize=(460.0, 820.0)) width, height = (460.0, 820.0) for pics in picture_files: c.drawImage(pics, 0, 0) c.showPage() c.save() uploads = files(filename=filename, department=name, semester=semester, author=request.form['author'], tags=request.form['tags'], description=request.form['description'], downloads=0, uploader=g.user.rollNo, upload_date=datetime.datetime.now()) db.session.add(uploads) db.session.commit() all_files = files.query.filter( and_(files.department.like(name), files.semester.like(int(semester)))) has_starred = False list_of_files = [] for file in all_files.all(): try: has_starred = stars.has_starred(file.id, g.user.rollNo) except: pass list_of_files.append( (file.filename, file.author, file.tags, file.semester, file.description, file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"), file.department)) return redirect( url_for('UploadOrView', name=name, semester=semester)) else: return redirect(url_for('navigate'))