def add_comment(request,name=None,filename=None): """ Adds a comment to the html page for a given filename as part of a project @param name the assignment name @param filename the name of the file @param the request data """ db = get_db() title = sanitize(request.form['title']) text = sanitize(request.form['text']) db.execute('insert into entries (title, text) values (?, ?)', [title,text]) db.commit() flash('New entry was successfully posted') cur = db.execute('select * from entries order by id desc') entrylist = cur.fetchall() _file = p.find_file(assignments,filename) data = {'name': name, 'file': _file, 'filename': filename, 'entrylist': entrylist} return "test"
def reply_comment(request,name=None,filename=None): """ Replies to a given comment and adds the data to the database. @param name the name of the assignment @param filename the filename of the file @param request the request data from the user """ db = get_db() title = sanitize(request.form['title']) text = sanitize(request.form['text']) db.execute('insert into replies (title,text,reply) values (?, ?, ?)', [title,text,request.form['reply']]) db.commit() flash('New reply was successfully posted') cur = db.execute('select * from entries order by id desc') entrylist = cur.fetchall() cur = db.execute('select title,text,reply from replies order by id desc') replylist = cur.fetchall() _file = p.find_file(assignments,filename) return render_template('show_entries.html', name=name, file=_file, filename=filename, entrylist=entrylist, replylist=replylist)
def comment(name=None,filename=None): if (request.method == 'GET'): db = get_db() cur = db.execute('select title, text from entries order by id desc') entrylist = cur.fetchall() return render_template('show_entries.html', name=name, filename=filename, entrylist=entrylist) else: if (request.form['reply'] == "None"): return add_comment(request,name,filename) else: return reply_comment(request,name,filename)
def sanitize(text): """ Removes words that exist in the bad_words table from the text and replaces them with better words. @param text the comment text @return the sanitized text """ db = get_db() cur = db.execute('select * from bad_words') bad_words = cur.fetchall() for pairing in bad_words: if (pairing[0] in text): text = text.replace(pairing[0],pairing[1]) return text