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 render(user): if authbar.get_current_login() != user: return '' # We know the user is logged in d = db.get_user_data(user) return tempy.substitute('editor.template', d)
def get_privacy_pane (user): if authbar.get_current_login() != user: return '' states = dict() for field in matedb.privacy_fields: states[field + '_state'] = cb_state (user, field) return tempy.substitute ('privacy.template', states)
def render_results(results): full_string = ""; for result in results: data = dict( profile_picture = images.get_profile_picture(result), user_page = cgienv.get_URL() + "?who=" + result ) data.update(db.get_user_data (result)) full_string += tempy.substitute('search_result.template', data) return full_string
def get_news_pane(user): components = dict() login = authbar.get_current_login() if not privacy.permitted(user, 'news'): return '' if user in matedb.get_all_mates(login) or user == login: components['post_box'] = get_post_box(user) else: components['post_box'] = '' components['news_items'] = '' posts = matedb.get_news(user) # Sort by time. Could use a namedtuple, or a class. Could do lots of things... posts.sort(key=lambda item: item[4]) posts.reverse() for post in posts: components['news_items'] += item_format(post) return tempy.substitute ('news.template', components)
def render(user): if authbar.get_current_login() != user: return '' else: return tempy.substitute('upload.template', None)
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_comment_form(news_item_id): return tempy.substitute('news_item_comment_form.template', {'news_item_id':news_item_id});
def get_post_box(user): return tempy.substitute('news_post_box.template', {'user':user})