def item_format(post): # Post format: (user, poster, message, image, time, id) data = {} data['poster_name'] = matedb.get_data(post[1], 'name') data['message'] = post[2] if post[3]: data['image'] = '<p><img src="' + post[3] + '"></img></p>'; else: data['image'] = '' login = authbar.get_current_login() if login in matedb.get_all_mates(post[0]) or post[0] == login: data['comment_form'] = get_comment_form(post[5]) else: data['comment_form'] = '' data['comments'] = '' comments = matedb.get_comments(post[5]) comments.sort(key=lambda item: item[2]) comments.reverse() for comment in comments: data['comments'] += comment_format(comment) return tempy.substitute('news_item.template', data)
def get_profile_picture(user): if not privacy.permitted (user, 'profile_picture'): return '' name = db.get_data(user, 'profile_picture') if name: return '<img src="' + config.data_dir + name + '">' return ''
def do_login(request): if 'username' in request and 'password' in request: username = request['username'].value password = request['password'].value if db.get_data(username, 'password_hash') == get_hash(username, password): # Successful login print head.get_head() f = open(config.template_dir + 'authbar_login.template', 'r') t = Template (f.read()) return t.safe_substitute(login=username, token = get_token(username), page=cgienv.get_full_URL()) return '<script>document.location.href=""</script>'
def do_mate(request): d = {} requester = authbar.get_current_login() if requester and'user' in request: user = request['user'].value if 'token' not in request: user_address = db.get_data(user, 'email') if user_address == '*****@*****.**': csemail.send(user_address, "UNSW Mate request", get_mate_message(user, requester)) d['message'] = 'Mate request sent. Stay tuned...'; d['link'] = '?who=' + user d['link_message'] = "Return to their page. Stalk mode engage!" else : # Make a mateship db.add_mate(user, requester) # This is a bit interesting. The order is actually reversed # because it's the other user loading the link d['message'] = 'Mate added!' d['link'] = '?who=' + user d['link_message'] = "Go to their page" else: d['message'] = 'User not found'; if requester: d['link'] = '?who=' + requester d['link_message'] = "Back to my page..." else: d['link'] = '' d['link_message'] = "Return to UNSWMate" return tempy.render('mate.template', d)
def render(users): result = ''; for i in xrange (0, len(users), 3): group = users[i:i+3] result += '<div class="row-fluid" id="userlist">' for user in group: result += '<div class="span4">' result += '<div class="span6"><a href="?who=' + user + '">' + images.get_profile_picture(user) + "</a></div>\n" result += '<div class="span6"><br /><a href="?who=' + user + '"><p><b>' + db.get_data(user, 'name') + "</b></p></a></div>\n" result += '</div>' result += '<br />' result += '</div>' return result
def comment_format(comment): data = {} data['image'] = images.get_profile_picture(comment[0]) data['user'] = matedb.get_data(comment[0], 'name') data['message'] = comment[1] return tempy.substitute('news_comment.template', data)
def get_hash(user, password): salt = db.get_data(user, 'salt') return hashlib.sha512(password + salt).hexdigest()
def get_auth_menu_label(): if get_current_login(): return db.get_data(get_current_login(), 'name') else: return "login"