def add_recipient(thread_id): try: g.user.username if str(thread_id) not in g.user.get_threads(): abort(401) except AttributeError: abort(401) username = request.form['username'] if request.form['confirm'] == '1': try: t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.parse_recipients(username) t.save() flash('Added recipient.', 'success') except InvalidRecipients: flash(u'Invalid recipient.', 'error') return redirect(url_for('frontend.view_thread', thread_id=thread_id)) else: return render_template('confirm.html', _message='Are you sure you wish to add recipient %s to\ this thread?' % username, _ok=url_for('frontend.add_recipient', thread_id=thread_id), _cancel=url_for('frontend.view_thread', thread_id=thread_id), _hiddens=[('username', username)] )
def add_recipient(thread_id): try: g.user.username if str(thread_id) not in g.user.get_threads(): abort(401) except AttributeError: abort(401) username = request.form['username'] if request.form['confirm'] == '1': try: t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.parse_recipients(username) t.save() flash('Added recipient.', 'success') except InvalidRecipients: flash(u'Invalid recipient.', 'error') return redirect(url_for('frontend.view_thread', thread_id=thread_id)) else: return render_template( 'confirm.html', _message='Are you sure you wish to add recipient %s to\ this thread?' % username, _ok=url_for('frontend.add_recipient', thread_id=thread_id), _cancel=url_for('frontend.view_thread', thread_id=thread_id), _hiddens=[('username', username)])
def mark_thread_read(thread_id): try: if str(thread_id) not in g.user.get_threads(): abort(401) except AttributeError: abort(401) t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.reset_unread_count() abort(200)
def unsubscribe_thread(thread_id): try: g.user.username except AttributeError: abort(401) if request.method == "POST": t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.unsubscribe() flash(u'Unsubscribed from thread.', 'success') return redirect(url_for('frontend.inbox')) else: return render_template('confirm.html', _message='Are you sure you wish to unsubscribe from this thread?', _ok=url_for('frontend.unsubscribe_thread', thread_id=thread_id), _cancel=url_for('frontend.inbox') )
def unsubscribe_thread(thread_id): try: g.user.username except AttributeError: abort(401) if request.method == "POST": t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.unsubscribe() flash(u'Unsubscribed from thread.', 'success') return redirect(url_for('frontend.inbox')) else: return render_template( 'confirm.html', _message='Are you sure you wish to unsubscribe from this thread?', _ok=url_for('frontend.unsubscribe_thread', thread_id=thread_id), _cancel=url_for('frontend.inbox'))
def delete_message(message_id, thread_id): if request.method == 'POST': t = Thread(redis=g.r, user=g.user) t.load(thread_id) m = Message(redis=g.r, user=g.user, key=message_id) m.load() if g.r.get('username:%s' % m.sender.username) != g.user.key: abort(401) t.delete_message(m) flash(u'Message deleted', 'success') return redirect(url_for('frontend.view_thread', thread_id=thread_id)) else: return render_template('confirm.html', _message='Are you sure you want to delete this message?', _ok=url_for('frontend.delete_message', thread_id=thread_id, message_id=message_id), _cancel=url_for('frontend.view_thread', thread_id=thread_id) )
def del_thread(thread_id): try: g.user.username if str(thread_id) not in g.user.get_threads(): abort(401) except AttributeError: abort(401) if request.method == "POST": t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.delete() flash(u'Deleted thread.', 'success') return redirect(url_for('frontend.inbox')) else: return render_template('confirm.html', _message='Are you sure you wish to DELETE this thread?', _ok=url_for('frontend.del_thread', thread_id=thread_id), _cancel=url_for('frontend.inbox') )
def del_thread(thread_id): try: g.user.username if str(thread_id) not in g.user.get_threads(): abort(401) except AttributeError: abort(401) if request.method == "POST": t = Thread(redis=g.r, user=g.user) t.load(thread_id) t.delete() flash(u'Deleted thread.', 'success') return redirect(url_for('frontend.inbox')) else: return render_template( 'confirm.html', _message='Are you sure you wish to DELETE this thread?', _ok=url_for('frontend.del_thread', thread_id=thread_id), _cancel=url_for('frontend.inbox'))
def delete_message(message_id, thread_id): if request.method == 'POST': t = Thread(redis=g.r, user=g.user) t.load(thread_id) m = Message(redis=g.r, user=g.user, key=message_id) m.load() if g.r.get('username:%s' % m.sender.username) != g.user.key: abort(401) t.delete_message(m) flash(u'Message deleted', 'success') return redirect(url_for('frontend.view_thread', thread_id=thread_id)) else: return render_template( 'confirm.html', _message='Are you sure you want to delete this message?', _ok=url_for('frontend.delete_message', thread_id=thread_id, message_id=message_id), _cancel=url_for('frontend.view_thread', thread_id=thread_id))
def view_thread(thread_id): if str(thread_id) not in g.user.get_threads(): abort(401) t = Thread(redis=g.r, user=g.user) try: t.load(thread_id) if request.method == "POST": if request.form['action'] == 'reply': m = Message(redis=g.r, key=False, user=g.user) m.update(request.form) t.save() t.add_message(m) m.send() t.load(thread_id) flash("Reply has been sent.", 'success') return redirect(url_for('frontend.view_thread', thread_id=t.key)) return render_template('thread.html', messages=t.messages, thread=t, subject=t.subject) except ThreadError: abort(404)
def view_thread(thread_id): if str(thread_id) not in g.user.get_threads(): abort(401) t = Thread(redis=g.r, user=g.user) try: t.load(thread_id) if request.method == "POST": if request.form['action'] == 'reply': m = Message(redis=g.r, key=False, user=g.user) m.update(request.form) t.save() t.add_message(m) m.send() t.load(thread_id) flash("Reply has been sent.", 'success') return redirect( url_for('frontend.view_thread', thread_id=t.key)) return render_template('thread.html', messages=t.messages, thread=t, subject=t.subject) except ThreadError: abort(404)