Esempio n. 1
0
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))
Esempio n. 2
0
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))
Esempio n. 3
0
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))
Esempio n. 4
0
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))