def get_messages(partner): # Check for new info check_db() all_messages = get_mail_db(current_user.name, partner) message_js = [] groupnames = names_n_group(current_user.name)[1] members = [] partner_id = "" if partner in groupnames: members = get_members(partner) partner_id = get_id(partner) for mess in all_messages: direction = "sent" if mess.sender == current_user.name else "replies" sender_id = get_id(mess.sender, string=True) message = {"sender": sender_id, "recipient": mess.recipient, "content": mess.content, "time": mess.time.time().strftime("%H:%M:%S"), "direction": direction, "imgURL": url_for('tree_bp.static', filename='/imag/' + mess.sender + '.png')} message_js += [message] return {'messages': message_js, 'members': members, 'id': partner_id}
def new_group(): names, groupnames = names_n_group(current_user.name) names_id = {name: 'user_' + str(get_id(name)) for name in names} return render_template('new_group.html', names=names, groupnames=groupnames, names_id=names_id)
def settings(partner): members_id, not_members_id = {}, {} names, groupnames = names_n_group(current_user.name) check_db() if partner in groupnames: members = get_members(partner) not_members = [name for name in names if name not in members] for not_member in not_members: not_members_id[not_member] = get_id(not_member, string=True) for member in members: members_id[member] = get_id(member, string=True) return render_template('settings.html', partner=partner, notmembersid=not_members_id, members=members, notmembers=not_members, membersid=members_id)
def messenger(): check_db() groupnames = names_n_group(current_user.name)[1] lastmails = get_last_messages(current_user.name) print('lastmails = ', lastmails) my_id = 'user_' + str(get_id(current_user.name)) message_js = [] for partner in lastmails: mail = lastmails[partner] partner_id = get_id(partner, string=True) try: if mail.sender == current_user.name: direction = "sent" else: direction = "received" message = {"sender": mail.sender, "recipient": mail.recipient, "content": mail.content, "time": mail.time.time().strftime("%H:%M:%S"), "direction": direction, "imgURL": url_for('tree_bp.static', filename='imag/' + partner_id + '.png'), "partner": partner} partner_id = get_id(partner, string=True) message_js += [message] except Exception: raise ValueError("Error") return render_template('messenger.html', lastmails=message_js, current=my_id, groupnames=groupnames)
def show_tree(groupname): tree = read_tree(groupname) all_index = get_all_index(tree) nodes = [] for index in all_index: anode = get_node(tree, index) unode = {"value": anode.value, "name": 'node'} if anode.parent: unode["parent"] = anode.parent.value if anode.isLeaf: unode['name'] = 'user_' + str(get_id(anode.value)) if anode.private_key: unode["secretK"] = anode.private_key else: unode["secretK"] = "" nodes += [unode] data = {'info': nodes} return render_template('show_tree.html', data=data)