def suggestion_widget(context, type=None): request = context['request'] browser = request.META[ 'HTTP_USER_AGENT'] if 'HTTP_USER_AGENT' in request.META else '' user = request.user tags = get_suggested_tags(user)() users = get_most_stickered_unfollowed_users(user)() has_tags = len(tags) > 0 has_users = len(users) > 0 using_chrome = chrome.search(browser) is not None def get_type(): types = ['invite'] if has_users: types += ['people'] if has_tags: types += ['tags'] if using_chrome: types += ['chrome'] return random.choice(types) try: ttype = get_type() except IndexError: return Markup('') if ttype == 'tags': ctx = {'tags': tags, 'type': ttype} return Markup( render_jinja_to_string('suggest/suggest_tags_widget.html', update_context(context, ctx))) elif ttype == 'people': ctx = {'users': users, 'type': ttype} return Markup( render_jinja_to_string('suggest/suggest_people_widget.html', update_context(context, ctx))) elif ttype == 'invite': ctx = {'type': ttype} return Markup( render_jinja_to_string('suggest/suggest_invite_widget.html', update_context(context, ctx))) elif ttype == 'chrome': ctx = {'type': ttype} return Markup( render_jinja_to_string('suggest/suggest_extension_widget.html', update_context(context, ctx)))
def jinja_thread_preview(context, thread, admin_view=False): ctx = { 'thread': thread, 'admin_view': admin_view, 'show_curation_info': admin_view and bool(getattr(thread, 'curator', None)), } return Markup(render_jinja_to_string('logged_out_homepage/thread_preview.html', update_context(context, ctx)))
def post_thread_form(context, show_start_options=True): ctx = { 'show_start_options': bool(show_start_options), } return Markup( render_jinja_to_string('post_thread/_post_thread_form.html', update_context(context, ctx)))
def quest_preview(context, quest_preview, admin_view=False, already_saved=False): ctx = { 'quest_preview': quest_preview, 'admin_view': admin_view, 'show_curation_info': admin_view and bool(getattr(quest_preview, 'curator', None)), 'already_saved': already_saved, } return Markup(render_jinja_to_string('quests/quest_preview.html', update_context(context, ctx)))
def suggestion_widget(context, type=None): request = context['request'] browser = request.META['HTTP_USER_AGENT'] if 'HTTP_USER_AGENT' in request.META else '' user = request.user tags = get_suggested_tags(user)() users = get_most_stickered_unfollowed_users(user)() has_tags = len(tags) > 0 has_users = len(users) > 0 using_chrome = chrome.search(browser) is not None def get_type(): types = ['invite'] if has_users: types += ['people'] if has_tags: types += ['tags'] if using_chrome: types += ['chrome'] return random.choice(types) try: ttype = get_type() except IndexError: return Markup('') if ttype == 'tags': ctx = { 'tags': tags, 'type': ttype } return Markup(render_jinja_to_string('suggest/suggest_tags_widget.html', update_context(context, ctx))) elif ttype == 'people': ctx = { 'users': users, 'type': ttype } return Markup(render_jinja_to_string('suggest/suggest_people_widget.html', update_context(context, ctx))) elif ttype == 'invite': ctx = { 'type': ttype } return Markup(render_jinja_to_string('suggest/suggest_invite_widget.html', update_context(context, ctx))) elif ttype == 'chrome': ctx = { 'type': ttype } return Markup(render_jinja_to_string('suggest/suggest_extension_widget.html', update_context(context, ctx)))
def jinja_thread_reply(context, comment_details, template='threads/reply.html', is_expanded=False): opts = { 'reply': TemplateComment(comment_details, request_context=context), 'is_expanded': is_expanded, } return Markup( render_jinja_to_string(template, update_context(context, opts)))
def post_thread_form(context, show_start_options=True): ctx = { 'show_start_options': bool(show_start_options), } return Markup(render_jinja_to_string('post_thread/_post_thread_form.html', update_context(context, ctx)))
def submit_quest_form(context): ctx = {} return Markup(render_jinja_to_string('submit_quest/_submit_quest_form.html', update_context(context, ctx)))
def jinja_thread_reply(context, comment_details, template='threads/reply.html', is_expanded=False): opts = { 'reply': TemplateComment(comment_details, request_context=context), 'is_expanded': is_expanded, } return Markup(render_jinja_to_string(template, update_context(context, opts)))
def submit_quest_form(context): ctx = {} return Markup( render_jinja_to_string('submit_quest/_submit_quest_form.html', update_context(context, ctx)))