def ajax_messages(discussion_uuid): try: result = {} discussion = Discussion.get_by_uuid(discussion_uuid) if request.method == "GET": offset = request.values.get("offset", None, type=int) first_index = request.values.get("first_index", None, type=int) if offset is None or first_index is None: result["unread_count"] = 0 result["success"] = True return json.dumps(result) result = discussion.get_messages_json(offset=offset) messages = result.get("messages") if first_index is not None: messages = [message for message in messages if message.get("index", None) < first_index] result["messages"] = messages result["unread_count"] = discussion.unread_count() elif request.method == "POST": message = request.values.get("message", None, type=unicode) discussion.send_message(message) result = dict(discussion_uuid=discussion_uuid, message=message) result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_seen(discussion_uuid): try: result = {} discussion = Discussion.get_by_uuid(discussion_uuid) if request.method == "GET": result["unread_count"] = discussion.unread_count() elif request.method == "POST": seen_count = request.values.get("seen_count", None, type=int) if seen_count is not None and seen_count >= 0: result = Discussion.set_seen_count(discussion_uuid, seen_count) result["unread_count"] = 0 result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_attachments(discussion_uuid): try: filename = request.values.get("filename", None) location = request.values.get("location", None) result = Discussion.add_attachments(filename, location, discussion_uuid) result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_leave_panel(discussion_uuid): try: discussion = Discussion.get_by_uuid(discussion_uuid) result = discussion.delete_participants([g.user.uuid]) result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_new_panel(): try: result = dict() result = Discussion.create( title=request.values.get("title", None), description=request.values.get("description", None) ) result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_panel_update(discussion_uuid): try: discussion = Discussion.get_by_uuid(discussion_uuid) result = discussion.update( title=request.values.get("title", None), description=request.values.get("description", None) ) result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_unread_total(): try: result = {} discussion_list = Discussion.get_by_user_uuid(g.user.uuid, extras=["summary", "lastseen"]) unread_total = 0 for discussion in discussion_list: unread_total += discussion.unread_count() g.unread_total = unread_total result["unread_total"] = unread_total result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def panels(discussion_uuid=None): discussion = None discussions_list = [] friends = [] list_type = "own" query = request.args.get("q", None) offset = request.args.get("offset", None) to_json = request.args.get("to_json", None) try: if discussion_uuid is not None: discussion = Discussion.get_by_uuid(discussion_uuid) if query is not None: list_type = "search" discussions_list = Discussion.search(query) else: list_type = "own" discussions_list = Discussion.get_by_user_uuid(g.user.uuid, extras=["summary", "lastseen"]) if g.user.is_authenticated(): friends = g.user.get_friends() except HTTPError, e: flash(unicode(SERVER_ERRORS.get(e.code, e.msg)), "error")
def ajax_participants(discussion_uuid): try: result = dict() discussion = Discussion.get_by_uuid(discussion_uuid) if request.method == "POST": participants = request.values.get("participants", None) if participants is not None: participants = json.loads(participants) result = discussion.add_participants(participants) elif request.method == "DELETE": users = request.values.get("users", []) result = discussion.delete_participants(users) result["success"] = True return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})
def ajax_panel(discussion_uuid): try: result = dict() discussion = Discussion.get_by_uuid(discussion_uuid) if request.method == "GET": result = discussion.get_messages_json() result["participants"] = discussion.get_participants_json()["participants"] result["attachments"] = discussion.attachments result["unread_count"] = discussion.unread_count() result["discussion"] = discussion.to_json() elif request.method == "PATCH": result = discussion.update( title=request.values.get("title", None), description=request.values.get("description", None) ) result["success"] = True print result return json.dumps(result) except HTTPError, e: return json.dumps({"success": False, "msg": unicode(SERVER_ERRORS.get(e.code, e.msg))})