Beispiel #1
0
def render_content(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, 'ui')._populate(_import_ns, ['bar'])
        ui = _mako_get_namespace(context, 'ui')
        crumbs = _import_ns.get('crumbs', context.get('crumbs', UNDEFINED))
        title = _import_ns.get('title', context.get('title', UNDEFINED))
        messages = _import_ns.get('messages',
                                  context.get('messages', UNDEFINED))
        code = _import_ns.get('code', context.get('code', UNDEFINED))

        def content():
            return render_content(context)

        files = _import_ns.get('files', context.get('files', UNDEFINED))
        source_link = _import_ns.get('source_link',
                                     context.get('source_link', UNDEFINED))
        folders = _import_ns.get('folders', context.get('folders', UNDEFINED))
        __M_writer = context.writer()
        __M_writer('\n')
        __M_writer(str(ui.bar(crumbs)))
        __M_writer('\n')
        if folders or files:
            __M_writer('<ul>\n')
            for name in folders:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer(
                    '"><i class="glyphicon glyphicon-folder-open"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            for name in files:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('.html"><i class="glyphicon glyphicon-file"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            __M_writer('</ul>\n')
        if code:
            __M_writer('<h1>')
            __M_writer(str(title))
            __M_writer('\n')
            if source_link:
                __M_writer('        <small><a href="')
                __M_writer(str(source_link))
                __M_writer('">(')
                __M_writer(str(messages("Source")))
                __M_writer(')</a></small>\n')
            __M_writer('    </h1>\n    ')
            __M_writer(str(code))
            __M_writer('\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #2
0
def render_content(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        crumbs = context.get('crumbs', UNDEFINED)
        source_link = context.get('source_link', UNDEFINED)
        messages = context.get('messages', UNDEFINED)
        ui = _mako_get_namespace(context, 'ui')
        title = context.get('title', UNDEFINED)
        code = context.get('code', UNDEFINED)
        folders = context.get('folders', UNDEFINED)

        def content():
            return render_content(context)

        files = context.get('files', UNDEFINED)
        __M_writer = context.writer()
        __M_writer('\n')
        __M_writer(str(ui.breadcrumbs(crumbs)))
        __M_writer('\n')
        if folders or files:
            __M_writer('<ul>\n')
            for name in folders:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('">📂&nbsp;')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            for name in files:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('.html">📄&nbsp;')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            __M_writer('</ul>\n')
        if code:
            __M_writer('<h1>')
            __M_writer(str(title))
            __M_writer('\n')
            if source_link:
                __M_writer('        <small><a href="')
                __M_writer(str(source_link))
                __M_writer('">(')
                __M_writer(str(messages("Source")))
                __M_writer(')</a></small>\n')
            __M_writer('    </h1>\n    ')
            __M_writer(str(code))
            __M_writer('\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #3
0
def query_string(dict):
    pairs = []
    for k, v in dict.iteritems():
        if v is not None:
            try:
                k = url_escape(unicode(k).encode("utf-8"))
                v = url_escape(unicode(v).encode("utf-8"))
                pairs.append(k + "=" + v)
            except UnicodeDecodeError:
                continue
    if pairs:
        return "?" + "&".join(pairs)
    else:
        return ""
Beispiel #4
0
def query_string(dict):
    pairs = []
    for k, v in dict.iteritems():
        if v is not None:
            try:
                k = url_escape(unicode(k).encode('utf-8'))
                v = url_escape(unicode(v).encode('utf-8'))
                pairs.append(k + '=' + v)
            except UnicodeDecodeError:
                continue
    if pairs:
        return '?' + '&'.join(pairs)
    else:
        return ''
Beispiel #5
0
def render_content(context,**pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, 'ui')._populate(_import_ns, ['bar'])
        messages = _import_ns.get('messages', context.get('messages', UNDEFINED))
        crumbs = _import_ns.get('crumbs', context.get('crumbs', UNDEFINED))
        ui = _mako_get_namespace(context, 'ui')
        source_link = _import_ns.get('source_link', context.get('source_link', UNDEFINED))
        code = _import_ns.get('code', context.get('code', UNDEFINED))
        title = _import_ns.get('title', context.get('title', UNDEFINED))
        def content():
            return render_content(context)
        files = _import_ns.get('files', context.get('files', UNDEFINED))
        folders = _import_ns.get('folders', context.get('folders', UNDEFINED))
        __M_writer = context.writer()
        __M_writer('\n')
        __M_writer(str(ui.bar(crumbs)))
        __M_writer('\n')
        if folders or files:
            __M_writer('<ul>\n')
            for name in folders:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('"><i class="glyphicon glyphicon-folder-open"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            for name in files:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('.html"><i class="glyphicon glyphicon-file"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            __M_writer('</ul>\n')
        if code:
            __M_writer('<h1>')
            __M_writer(str(title))
            __M_writer('\n')
            if source_link:
                __M_writer('        <small><a href="')
                __M_writer(str(source_link))
                __M_writer('">(')
                __M_writer(str(messages("Source")))
                __M_writer(')</a></small>\n')
            __M_writer('    </h1>\n    ')
            __M_writer(str(code))
            __M_writer('\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #6
0
def query_string(dict):
    pairs = []
    for k,v in dict.iteritems():
        if v is not None:
            try:
                k = url_escape(_force_unicode(k))
                v = url_escape(_force_unicode(v))
                pairs.append(k + '=' + v)
            except UnicodeDecodeError:
                continue
    if pairs:
        return '?' + '&'.join(pairs)
    else:
        return ''
Beispiel #7
0
def render_content(context,**pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        STATIC_URL = context.get('STATIC_URL', UNDEFINED)
        def content():
            return render_content(context)
        enumerate = context.get('enumerate', UNDEFINED)
        languages = context.get('languages', UNDEFINED)
        __M_writer = context.writer()
        __M_writer('\n  <div class="content">\n    <div class="banner">\n      <div class="container">\n        <div class="row">\n          <div class="col-md-12">\n            <img src="')
        __M_writer(str( STATIC_URL ))
        __M_writer('homepage/media/lexicity_logo.png" alt="Lexicity logo"/>\n          </div>\n        </div>\n        <div class="row">\n          <div class="col-md-12 subtitles">\n            <h2>The first and only comprehensive index for ancient language resources on the internet.</h2>\n          </div>\n        </div>\n      </div>\n    </div>\n  </div>\n  <div class="middle">\n    <div class="container text-center">\n      <div class="row">\n        <div class="col-md-12 content">\n          <h2>Choose Your Language</h2>\n        </div>\n      </div>\n        \n')
        for i, language in enumerate(languages):
            __M_writer('      \n        <a href="/language/')
            __M_writer(filters.url_escape(str( language.name)))
            __M_writer('/">\n          <div class="tile">\n            <img src="')
            __M_writer(str( STATIC_URL ))
            __M_writer('homepage/media/')
            __M_writer(str( language.img_name ))
            __M_writer('"/>\n            <h3>')
            __M_writer(str( language ))
            __M_writer('</h3>\n          </div>\n        </a>\n\n')
        __M_writer('      \n    </div>\n  </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #8
0
def render_body(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        course = context.get('course', UNDEFINED)
        xqa_server = context.get('xqa_server', UNDEFINED)
        static = _mako_get_namespace(context, 'static')
        unicode = context.get('unicode', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(u'\n\n<script type="text/javascript" src="')
        __M_writer(
            filters.decode.utf8(static.url('js/vendor/jquery.leanModal.js')))
        __M_writer(u'"></script>\n<script type="text/javascript" src="')
        __M_writer(filters.decode.utf8(
            static.url('js/staff_debug_actions.js')))
        __M_writer(
            u'"></script>\n<script type="text/javascript">\n\nfunction setup_debug(element_id, edit_link, staff_context){\n    var staffDebugTrigger = $(\'#\' + element_id + \'_trig\'),\n        xqaLogTrigger = $(\'#\' + element_id + \'_xqa_log\'),\n        historyTrigger = $("#" + element_id + "_history_trig"),\n        debugModalSelector = \'#\' + element_id + \'_debug\',\n        historyModalSelector = \'#\' + element_id + \'_history\',\n        xqaModalSelector = \'#\' + element_id + \'_xqa-modal\',\n        leanOverlaySelector = $(\'#lean_overlay\');\n\n    staffDebugTrigger.leanModal();\n    xqaLogTrigger.leanModal();\n    $(\'#\' + element_id + \'_xqa_form\').submit(function () {sendlog(element_id, edit_link, staff_context);});\n\n    historyTrigger.leanModal();\n\n    $(\'#\' + element_id + \'_history_form\').submit(\n        function () {\n            var username = $("#" + element_id + "_history_student_username").val();\n            var location = $("#" + element_id + "_history_location").val();\n\n            $("#" + element_id + "_history_text").load(\'/courses/\' + "'
        )
        __M_writer(filters.url_escape(filters.decode.utf8(unicode(course.id))))
        __M_writer(
            u'" +\n                "/submission_history/" + username + "/" + location);\n            return false;\n        }\n    );\n\n    DialogTabControls.setKeydownListener($(debugModalSelector), leanOverlaySelector);\n    DialogTabControls.setKeydownListener($(historyModalSelector), leanOverlaySelector);\n    DialogTabControls.setKeydownListener($(xqaModalSelector), leanOverlaySelector);\n\n    staffDebugTrigger.on(\'click\', function() {\n        DialogTabControls.initializeTabKeyValues(debugModalSelector);\n        $(debugModalSelector).attr("aria-hidden", "false");\n    });\n\n    historyTrigger.on(\'click\', function() {\n        DialogTabControls.initializeTabKeyValues(historyModalSelector);\n        $(historyModalSelector).attr("aria-hidden", "false");\n    });\n\n    xqaLogTrigger.on(\'click\', function() {\n        DialogTabControls.initializeTabKeyValues(xqaModalSelector);\n        $(xqaModalSelector).attr("aria-hidden", "false");\n    });\n\n    leanOverlaySelector.click(function () {\n        $(xqaModalSelector).attr("aria-hidden", "true");\n        $(historyModalSelector).attr("aria-hidden", "true");\n        $(debugModalSelector).attr("aria-hidden", "true");\n      })\n}\n\nfunction sendlog(element_id, edit_link, staff_context){\n\n    var xqaLog = {\n            authkey: staff_context.xqa_key,\n            location: staff_context.location,\n            category : staff_context.category,\n            \'username\' : staff_context.user.username,\n            \'return\' : \'query\',\n            format : \'html\',\n            email : staff_context.user.email,\n            tag:$(\'#\' + element_id + \'_xqa_tag\').val(),\n            entry: $(\'#\' + element_id + \'_xqa_entry\').val()\n        };\n\n    $.ajax({\n        url: \''
        )
        __M_writer(filters.decode.utf8(xqa_server))
        __M_writer(
            u'/log\',\n        type: \'GET\',\n        contentType: \'application/json\',\n        data: JSON.stringify(xqaLog),\n        crossDomain: true,\n        dataType: \'jsonp\',\n        beforeSend: function (xhr) {\n            xhr.setRequestHeader ("Authorization", "Basic eHFhOmFnYXJ3YWw="); },\n        timeout : 1000,\n        success: function(result) {\n                $(\'#\' + element_id + \'_xqa_log_data\').html(result);\n        },\n        error: function() {\n            alert(\'Error: cannot connect to XQA server. Check the value of the XQA_SERVER setting.\');\n            console.log(\'error!\');\n        }\n    });\n    return false;\n};\n\nfunction getlog(element_id, staff_context){\n\n    var xqaQuery = {\n        authkey: staff_context.xqa_key,\n        location: staff_context.location,\n        format: \'html\'\n    };\n\n    $.ajax({\n        url: \''
        )
        __M_writer(filters.decode.utf8(xqa_server))
        __M_writer(
            u"/query',\n        type: 'GET',\n        contentType: 'application/json',\n        data: JSON.stringify(xqaQuery),\n        crossDomain: true,\n        dataType: 'jsonp',\n        timeout : 1000,\n        success: function(result) {\n            $('#' + element_id + '_xqa_log_data').html(result);\n        },\n        error: function() {\n            alert('Error: cannot connect to XQA server. Check the value of the XQA_SERVER setting.');\n        }\n    });\n\n\n};\n</script>\n"
        )
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #9
0
def render_content(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        STATIC_URL = context.get('STATIC_URL', UNDEFINED)

        def content():
            return render_content(context)

        enumerate = context.get('enumerate', UNDEFINED)
        languages = context.get('languages', UNDEFINED)
        __M_writer = context.writer()
        __M_writer(
            '\n  <div class="content">\n    <div class="banner">\n      <div class="container">\n        <div class="row">\n          <div class="col-md-12">\n            <img src="'
        )
        __M_writer(str(STATIC_URL))
        __M_writer(
            'homepage/media/lexicity_logo.png" alt="Lexicity logo"/>\n          </div>\n        </div>\n        <div class="row">\n          <div class="col-md-12 subtitles">\n            <h2>The first and only comprehensive index for ancient language resources on the internet.</h2>\n          </div>\n        </div>\n      </div>\n    </div>\n  </div>\n  <div class="middle">\n    <div class="container text-center">\n      <div class="row">\n        <div class="col-md-12 content">\n          <h2>Choose Your Language</h2>\n        </div>\n      </div>\n        \n'
        )
        for i, language in enumerate(languages):
            __M_writer('      \n        <a href="/language/')
            __M_writer(filters.url_escape(str(language.name)))
            __M_writer(
                '/">\n          <div class="tile">\n            <img src="')
            __M_writer(str(STATIC_URL))
            __M_writer('homepage/media/')
            __M_writer(str(language.img_name))
            __M_writer('"/>\n            <h3>')
            __M_writer(str(language))
            __M_writer('</h3>\n          </div>\n        </a>\n\n')
        __M_writer('      \n    </div>\n  </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #10
0
    def submit_link(self):
        from r2.lib.template_helpers import get_domain
        from mako.filters import url_escape

        d = get_domain(subreddit=False)
        u = self.url()

        return "http://%s/r/ads/submit?url=%s" % (d, url_escape(u))
Beispiel #11
0
    def submit_link(self):
        from r2.lib.template_helpers import get_domain
        from mako.filters import url_escape

        d = get_domain(subreddit=False)
        u = self.url()

        return "http://%s/r/ads/submit?url=%s" % (d, url_escape(u))
Beispiel #12
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site._spam and not c.user_is_admin:
            subject = ("the subreddit /r/%s has been incorrectly banned" %
                       c.site.name)
            message = (strings.banned_subreddit %
                       dict(link = '/message/compose?to=%s&subject=%s' %
                            (url_escape(g.admin_message_acct),
                             url_escape(subject))))

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Beispiel #13
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site._spam and not c.user_is_admin:
            subject = ("the subreddit /r/%s has been incorrectly banned" %
                       c.site.name)
            message = (
                strings.banned_subreddit %
                dict(link='/message/compose?to=%s&subject=%s' %
                     (url_escape(g.admin_message_acct), url_escape(subject))))

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Beispiel #14
0
def render_content(context,**pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, 'ui')._populate(_import_ns, ['bar'])
        photo_array = _import_ns.get('photo_array', context.get('photo_array', UNDEFINED))
        permalink = _import_ns.get('permalink', context.get('permalink', UNDEFINED))
        enable_comments = _import_ns.get('enable_comments', context.get('enable_comments', UNDEFINED))
        site_has_comments = _import_ns.get('site_has_comments', context.get('site_has_comments', UNDEFINED))
        comments = _mako_get_namespace(context, 'comments')
        def content():
            return render_content(context)
        folders = _import_ns.get('folders', context.get('folders', UNDEFINED))
        title = _import_ns.get('title', context.get('title', UNDEFINED))
        post = _import_ns.get('post', context.get('post', UNDEFINED))
        crumbs = _import_ns.get('crumbs', context.get('crumbs', UNDEFINED))
        ui = _mako_get_namespace(context, 'ui')
        __M_writer = context.writer()
        __M_writer('\n    ')
        __M_writer(str(ui.bar(crumbs)))
        __M_writer('\n')
        if title:
            __M_writer('    <h1>')
            __M_writer(filters.html_escape(str(title)))
            __M_writer('</h1>\n')
        if post:
            __M_writer('    <p>\n        ')
            __M_writer(str(post.text()))
            __M_writer('\n    </p>\n')
        if folders:
            __M_writer('    <ul>\n')
            for folder, ftitle in folders:
                __M_writer('        <li><a href="')
                __M_writer(filters.url_escape(str(folder)))
                __M_writer('"><i\n        class="icon-folder-open"></i>&nbsp;')
                __M_writer(filters.html_escape(str(ftitle)))
                __M_writer('</a></li>\n')
            __M_writer('    </ul>\n')
        if photo_array:
            __M_writer('    <ul class="thumbnails">\n')
            for image in photo_array:
                __M_writer('            <li><a href="')
                __M_writer(str(image['url']))
                __M_writer('" class="thumbnail image-reference" title="')
                __M_writer(str(image['title']))
                __M_writer('">\n                <img src="')
                __M_writer(str(image['url_thumb']))
                __M_writer('" alt="')
                __M_writer(filters.html_escape(str(image['title'])))
                __M_writer('" /></a>\n')
            __M_writer('    </ul>\n')
        if site_has_comments and enable_comments:
            __M_writer('    ')
            __M_writer(str(comments.comment_form(None, permalink, title)))
            __M_writer('\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #15
0
def render_content(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, 'ui')._populate(_import_ns, ['bar'])
        folders = _import_ns.get('folders', context.get('folders', UNDEFINED))

        def content():
            return render_content(context)

        crumbs = _import_ns.get('crumbs', context.get('crumbs', UNDEFINED))
        code = _import_ns.get('code', context.get('code', UNDEFINED))
        files = _import_ns.get('files', context.get('files', UNDEFINED))
        ui = _mako_get_namespace(context, 'ui')
        __M_writer = context.writer()
        __M_writer('\n')
        __M_writer(str(ui.bar(crumbs)))
        __M_writer('\n')
        if folders or files:
            __M_writer('<ul class="list-unstyled">\n')
            for name in folders:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer(
                    '"><i class="glyphicon glyphicon-folder-open"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            for name in files:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('.html"><i class="glyphicon glyphicon-file"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer('</a>\n')
            __M_writer('</ul>\n')
        if code:
            __M_writer('    ')
            __M_writer(str(code))
            __M_writer('\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #16
0
def render_content(context, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        _import_ns = {}
        _mako_get_namespace(context, "ui")._populate(_import_ns, ["bar"])
        folders = _import_ns.get("folders", context.get("folders", UNDEFINED))

        def content():
            return render_content(context)

        crumbs = _import_ns.get("crumbs", context.get("crumbs", UNDEFINED))
        code = _import_ns.get("code", context.get("code", UNDEFINED))
        files = _import_ns.get("files", context.get("files", UNDEFINED))
        ui = _mako_get_namespace(context, "ui")
        __M_writer = context.writer()
        __M_writer("\n")
        __M_writer(str(ui.bar(crumbs)))
        __M_writer("\n")
        if folders or files:
            __M_writer('<ul class="list-unstyled">\n')
            for name in folders:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('"><i class="glyphicon glyphicon-folder-open"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer("</a>\n")
            for name in files:
                __M_writer('    <li><a href="')
                __M_writer(filters.url_escape(str(name)))
                __M_writer('.html"><i class="glyphicon glyphicon-file"></i> ')
                __M_writer(filters.html_escape(str(name)))
                __M_writer("</a>\n")
            __M_writer("</ul>\n")
        if code:
            __M_writer("    ")
            __M_writer(str(code))
            __M_writer("\n")
        return ""
    finally:
        context.caller_stack._pop_frame()
Beispiel #17
0
    def send404(self):
        c.response.status_code = 404
        if "usable_error_content" in request.environ:
            return request.environ["usable_error_content"]
        if c.site.spammy() and not c.user_is_admin:
            subject = "the subreddit /r/%s has been incorrectly banned" % c.site.name
            lnk = "/r/redditrequest/submit?url=%s&title=%s" % (
                url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                ("the subreddit /r/%s has been incorrectly banned" % c.site.name),
            )
            message = strings.banned_subreddit % dict(link=lnk)

            res = pages.RedditError(_("this reddit has been banned"), unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
def render_comment_form(context,url,title,identifier):
    __M_caller = context.caller_stack._push_frame()
    try:
        comment_system_id = context.get('comment_system_id', UNDEFINED)
        __M_writer = context.writer()
        __M_writer('\n')
        if comment_system_id:
            __M_writer('        <div data-title="')
            __M_writer(filters.url_escape(str(title)))
            __M_writer('" id="isso-thread"></div>\n        <script src="')
            __M_writer(str(comment_system_id))
            __M_writer('js/embed.min.js" data-isso="')
            __M_writer(str(comment_system_id))
            __M_writer('"></script>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #19
0
def reddit_link(path, url = False, get = False):
    if url or get:
        (scheme, netloc, path, params, query, fragment) = urlparse(path)
        if url:
            #noslash fixes /reddits/
            noslash = c.site.path.rstrip('/')
            #if it's a relative path, don't include the sitename
            if path.startswith('/') and not path.startswith(noslash):
                path = c.site.path + path[1:]
        else:
            newparam = "r=" + url_escape(c.site.name)
            if query:
                query += "&" + newparam
            else:
                query = newparam
        return urlunparse((scheme, netloc, path, params, query, fragment))
    return path
Beispiel #20
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site.spammy() and not c.user_is_admin:
            subject = ("the subreddit /r/%s has been incorrectly banned" %
                       c.site.name)
            lnk = ("/r/redditrequest/submit?url=%s&title=%s" %
                   (url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                    ("the subreddit /r/%s has been incorrectly banned" %
                     c.site.name)))
            message = strings.banned_subreddit % dict(link=lnk)

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Beispiel #21
0
def find_links(text):
    print "HERE", text
    links = domain_re.findall(text)
    for link in links:
        m = reddit_re.match(link)
        if m:
            m = reddituser_re.match(link)
            if m:
                d = m.groupdict()
                res = reddit.API_GET("/user/%s/about.json" % d['username'])
                d = res.get("data")
                if d:
                    yield ("User '%(name)s' has karma %(link_karma)s" % d)
        else:
            res = reddit.API_GET("/api/info.json?limit=1&url=%s" %
                                 url_escape(link))
            d = res.get("data", {}).get("children", [{}])[0].get("data",{}) 
            if d:
                d['link'] = link
                yield ("%(url)s ==> http://www.reddit.com/r/%(subreddit)s/comments/%(id)s/ which has %(ups)s ups and %(downs)s downs." % d)
Beispiel #22
0
    def send404(self):
        c.response.status_code = 404
        if 'usable_error_content' in request.environ:
            return request.environ['usable_error_content']
        if c.site.spammy() and not c.user_is_admin:
            ban_info = getattr(c.site, "ban_info", {})
            if "message" in ban_info:
                message = ban_info["message"]
            else:
                subject = ("the subreddit /r/%s has been incorrectly banned" %
                           c.site.name)
                lnk = ("/r/redditrequest/submit?url=%s&title=%s"
                       % (url_escape("http://%s/r/%s" % (g.domain, c.site.name)),
                          ("the subreddit /r/%s has been incorrectly banned" %
                           c.site.name)))
                message = strings.banned_subreddit % dict(link = lnk)

            res = pages.RedditError(_('this reddit has been banned'),
                                    unsafe(safemarkdown(message)))
            return res.render()
        else:
            return pages.Reddit404().render()
Beispiel #23
0
def generateurl(context, path, **kw):
    if kw:
        return path + '?' + '&'.join(["%s=%s"%(k, url_escape(v)) \
                                      for k, v in kw.iteritems() if v])
    return path
Beispiel #24
0
def edit_comment_filter(text = ''):
    try:
        text = unicode(text, 'utf-8')
    except TypeError:
        text = unicode(text)
    return url_escape(text)
Beispiel #25
0
    def pre(self):
        c.response_wrappers = []
        MinimalController.pre(self)

        set_cnameframe()

        # populate c.cookies unless we're on the unsafe media_domain
        if request.host != g.media_domain or g.media_domain == g.domain:
            try:
                for k,v in request.cookies.iteritems():
                    # minimalcontroller can still set cookies
                    if k not in c.cookies:
                        # we can unquote even if it's not quoted
                        c.cookies[k] = Cookie(value=unquote(v), dirty=False)
            except CookieError:
                #pylons or one of the associated retarded libraries
                #can't handle broken cookies
                request.environ['HTTP_COOKIE'] = ''

        c.firsttime = firsttime()

        # the user could have been logged in via one of the feeds 
        maybe_admin = False

        # no logins for RSS feed unless valid_feed has already been called
        if not c.user:
            if c.extension != "rss":
                session_cookie = c.cookies.get(g.login_cookie)
                if session_cookie:
                    c.user = valid_cookie(session_cookie.value)
                    if c.user:
                        c.user_is_loggedin = True

                admin_cookie = c.cookies.get(g.admin_cookie)
                if c.user_is_loggedin and admin_cookie:
                    maybe_admin, first_login = valid_admin_cookie(admin_cookie.value)

                    if maybe_admin:
                        self.enable_admin_mode(c.user, first_login=first_login)
                    else:
                        self.disable_admin_mode(c.user)

            if not c.user:
                c.user = UnloggedUser(get_browser_langs())
                # patch for fixing mangled language preferences
                if (not isinstance(c.user.pref_lang, basestring) or
                    not all(isinstance(x, basestring)
                            for x in c.user.pref_content_langs)):
                    c.user.pref_lang = g.lang
                    c.user.pref_content_langs = [g.lang]
                    c.user._commit()
        if c.user_is_loggedin:
            if not c.user._loaded:
                c.user._load()
            c.modhash = c.user.modhash()
            if request.method.upper() == 'GET':
                read_mod_cookie()
            if hasattr(c.user, 'msgtime') and c.user.msgtime:
                c.have_messages = c.user.msgtime
            c.show_mod_mail = Subreddit.reverse_moderator_ids(c.user)
            c.have_mod_messages = getattr(c.user, "modmsgtime", False)
            c.user_is_admin = maybe_admin and c.user.name in g.admins
            c.user_special_distinguish = c.user.special_distinguish()
            c.user_is_sponsor = c.user_is_admin or c.user.name in g.sponsors
            if request.path != '/validuser' and not g.disallow_db_writes:
                c.user.update_last_visit(c.start_time)

        c.over18 = over18()

        #set_browser_langs()
        set_host_lang()
        set_iface_lang()
        set_content_lang()
        set_recent_clicks()
        # used for HTML-lite templates
        set_colors()

        # set some environmental variables in case we hit an abort
        if not isinstance(c.site, FakeSubreddit):
            request.environ['REDDIT_NAME'] = c.site.name

        # random reddit trickery -- have to do this after the content lang is set
        if c.site == Random:
            c.site = Subreddit.random_reddit()
            redirect_to("/" + c.site.path.strip('/') + request.path)
        elif c.site == RandomNSFW:
            c.site = Subreddit.random_reddit(over18 = True)
            redirect_to("/" + c.site.path.strip('/') + request.path)
        
        if not request.path.startswith("/api/login/"):
            # is the subreddit banned?
            if c.site.spammy() and not c.user_is_admin and not c.error_page:
                ban_info = getattr(c.site, "ban_info", {})
                if "message" in ban_info:
                    message = ban_info['message']
                else:
                    sitelink = url_escape(add_sr("/"))
                    subject = ("/r/%s has been incorrectly banned" %
                                   c.site.name)
                    link = ("/r/redditrequest/submit?url=%s&title=%s" %
                                (sitelink, subject))
                    message = strings.banned_subreddit_message % dict(
                                                                    link=link)
                errpage = pages.RedditError(strings.banned_subreddit_title,
                                            message,
                                            image="subreddit-banned.png")
                request.environ['usable_error_content'] = errpage.render()
                self.abort404()

            # check if the user has access to this subreddit
            if not c.site.can_view(c.user) and not c.error_page:
                errpage = pages.RedditError(strings.private_subreddit_title,
                                            strings.private_subreddit_message,
                                            image="subreddit-private.png")
                request.environ['usable_error_content'] = errpage.render()
                self.abort403()

            #check over 18
            if (c.site.over_18 and not c.over18 and
                request.path not in ("/frame", "/over18")
                and c.render_style == 'html'):
                return self.intermediate_redirect("/over18")

        #check whether to allow custom styles
        c.allow_styles = True
        c.can_apply_styles = self.allow_stylesheets
        if g.css_killswitch:
            c.can_apply_styles = False
        #if the preference is set and we're not at a cname
        elif not c.user.pref_show_stylesheets and not c.cname:
            c.can_apply_styles = False
        #if the site has a cname, but we're not using it
        elif c.site.domain and c.site.css_on_cname and not c.cname:
            c.can_apply_styles = False
Beispiel #26
0
    def pre(self):
        record_timings = g.admin_cookie in request.cookies or g.debug
        admin_bar_eligible = response.content_type == 'text/html'
        if admin_bar_eligible and record_timings:
            g.stats.start_logging_timings()

        # set up stuff needed in base templates at error time here.
        c.js_preload = JSPreload()

        MinimalController.pre(self)

        set_cnameframe()

        # populate c.cookies unless we're on the unsafe media_domain
        if request.host != g.media_domain or g.media_domain == g.domain:
            cookie_counts = collections.Counter()
            try:
                for k, v in request.cookies.iteritems():
                    # minimalcontroller can still set cookies
                    if k not in c.cookies:
                        # we can unquote even if it's not quoted
                        c.cookies[k] = Cookie(value=unquote(v), dirty=False)
                        cookie_counts[Cookie.classify(k)] += 1
            except CookieError:
                #pylons or one of the associated retarded libraries
                #can't handle broken cookies
                request.environ['HTTP_COOKIE'] = ''

            for cookietype, count in cookie_counts.iteritems():
                g.stats.simple_event("cookie.%s" % cookietype, count)

        delete_obsolete_cookies()

        # the user could have been logged in via one of the feeds 
        maybe_admin = False
        is_otpcookie_valid = False

        # no logins for RSS feed unless valid_feed has already been called
        if not c.user:
            if c.extension != "rss":
                authenticate_user()

                admin_cookie = c.cookies.get(g.admin_cookie)
                if c.user_is_loggedin and admin_cookie:
                    maybe_admin, first_login = valid_admin_cookie(admin_cookie.value)

                    if maybe_admin:
                        self.enable_admin_mode(c.user, first_login=first_login)
                    else:
                        self.disable_admin_mode(c.user)

                otp_cookie = read_user_cookie(g.otp_cookie)
                if c.user_is_loggedin and otp_cookie:
                    is_otpcookie_valid = valid_otp_cookie(otp_cookie)

            if not c.user:
                c.user = UnloggedUser(get_browser_langs())
                # patch for fixing mangled language preferences
                if (not isinstance(c.user.pref_lang, basestring) or
                    not all(isinstance(x, basestring)
                            for x in c.user.pref_content_langs)):
                    c.user.pref_lang = g.lang
                    c.user.pref_content_langs = [g.lang]
                    c.user._commit()
        if c.user_is_loggedin:
            if not c.user._loaded:
                c.user._load()
            c.modhash = c.user.modhash()
            if hasattr(c.user, 'msgtime') and c.user.msgtime:
                c.have_messages = c.user.msgtime
            c.show_mod_mail = Subreddit.reverse_moderator_ids(c.user)
            c.have_mod_messages = getattr(c.user, "modmsgtime", False)
            c.user_is_admin = maybe_admin and c.user.name in g.admins
            c.user_is_admin = c.user.name in g.admins
            c.user_special_distinguish = c.user.special_distinguish()
            c.user_is_sponsor = c.user_is_admin or c.user.name in g.sponsors
            c.otp_cached = is_otpcookie_valid
            if not isinstance(c.site, FakeSubreddit) and not g.disallow_db_writes:
                c.user.update_sr_activity(c.site)

        c.over18 = over18()
        set_obey_over18()

        #set_browser_langs()
        set_host_lang()
        set_iface_lang()
        set_content_lang()
        set_recent_clicks()
        # used for HTML-lite templates
        set_colors()

        # set some environmental variables in case we hit an abort
        if not isinstance(c.site, FakeSubreddit):
            request.environ['REDDIT_NAME'] = c.site.name

        # random reddit trickery -- have to do this after the content lang is set
        if c.site == Random:
            c.site = Subreddit.random_reddit(user=c.user)
            redirect_to("/" + c.site.path.strip('/') + request.path)
        elif c.site == RandomSubscription:
            if c.user.gold:
                c.site = Subreddit.random_subscription(c.user)
                redirect_to('/' + c.site.path.strip('/') + request.path)
            else:
                redirect_to('/gold/about')
        elif c.site == RandomNSFW:
            c.site = Subreddit.random_reddit(over18=True, user=c.user)
            redirect_to("/" + c.site.path.strip('/') + request.path)

        if not request.path.startswith("/api/login/"):
            # is the subreddit banned?
            if c.site.spammy() and not c.user_is_admin and not c.error_page:
                ban_info = getattr(c.site, "ban_info", {})
                if "message" in ban_info:
                    message = ban_info['message']
                else:
                    sitelink = url_escape(add_sr("/"))
                    subject = ("/r/%s has been incorrectly banned" %
                                   c.site.name)
                    link = ("/r/redditrequest/submit?url=%s&title=%s" %
                                (sitelink, subject))
                    message = strings.banned_subreddit_message % dict(
                                                                    link=link)
                errpage = pages.RedditError(strings.banned_subreddit_title,
                                            message,
                                            image="subreddit-banned.png")
                request.environ['usable_error_content'] = errpage.render()
                self.abort404()

            # check if the user has access to this subreddit
            if not c.site.can_view(c.user) and not c.error_page:
                public_description = c.site.public_description
                errpage = pages.RedditError(strings.private_subreddit_title,
                                            strings.private_subreddit_message,
                                            image="subreddit-private.png",
                                            sr_description=public_description)
                request.environ['usable_error_content'] = errpage.render()
                self.abort403()

            #check over 18
            if (c.site.over_18 and not c.over18 and
                request.path not in ("/frame", "/over18")
                and c.render_style == 'html'):
                return self.intermediate_redirect("/over18")

        #check whether to allow custom styles
        c.allow_styles = True
        c.can_apply_styles = self.allow_stylesheets
        if g.css_killswitch:
            c.can_apply_styles = False
        #if the preference is set and we're not at a cname
        elif not c.user.pref_show_stylesheets and not c.cname:
            c.can_apply_styles = False
        #if the site has a cname, but we're not using it
        elif c.site.domain and c.site.css_on_cname and not c.cname:
            c.can_apply_styles = False

        c.show_admin_bar = admin_bar_eligible and (c.user_is_admin or g.debug)
        if not c.show_admin_bar:
            g.stats.end_logging_timings()

        hooks.get_hook("reddit.request.begin").call()

        c.request_timer.intermediate("base-pre")
def render_body(context, curListType, myShowList, **pageargs):
    __M_caller = context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(curListType=curListType,
                                      pageargs=pageargs,
                                      myShowList=myShowList)
        _import_ns = {}
        _mako_get_namespace(context, '__anon_0x7f617e93e310')._populate(
            _import_ns, [u'renderQualityPill'])
        show_stat = _import_ns.get('show_stat',
                                   context.get('show_stat', UNDEFINED))
        renderQualityPill = _import_ns.get(
            'renderQualityPill', context.get('renderQualityPill', UNDEFINED))
        static_url = _import_ns.get('static_url',
                                    context.get('static_url', UNDEFINED))
        bool = _import_ns.get('bool', context.get('bool', UNDEFINED))
        srRoot = _import_ns.get('srRoot', context.get('srRoot', UNDEFINED))
        str = _import_ns.get('str', context.get('str', UNDEFINED))
        ValueError = _import_ns.get('ValueError',
                                    context.get('ValueError', UNDEFINED))
        _ = _import_ns.get('_', context.get('_', UNDEFINED))
        __M_writer = context.writer()
        __M_writer(u'\n')
        __M_writer(u'\n')
        __M_writer(u'\n\n')
        if sickbeard.HOME_LAYOUT == 'poster':
            __M_writer(u'    <div id="')
            __M_writer(
                unicode(
                    ('container', 'container-anime')[curListType == 'Anime']))
            __M_writer(
                u'" class="show-grid clearfix">\n        <div class="posterview">\n'
            )
            for curLoadingShow in sickbeard.showQueueScheduler.action.loading_show_list:
                __M_writer(u'                ')
                loading_show = curLoadingShow.info

                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(
                    __M_dict_builtin([
                        (__M_key, __M_locals_builtin_stored[__M_key])
                        for __M_key in ['loading_show']
                        if __M_key in __M_locals_builtin_stored
                    ]))
                __M_writer(
                    u'\n                <div class="show-container" data-name="'
                )
                __M_writer(unicode(loading_show.sort_name))
                __M_writer(
                    u'" data-date="1" data-network="0" data-progress="0">\n                    <div class="show-image">\n                        <img alt="" title="'
                )
                __M_writer(unicode(loading_show.name))
                __M_writer(
                    u'" class="show-image" style="border-bottom: 1px solid #111;" src="" data-src="'
                )
                __M_writer(unicode(srRoot))
                __M_writer(u'/showPoster/?show=')
                __M_writer(filters.url_escape(unicode(loading_show.id)))
                __M_writer(
                    u'&amp;which=poster_thumb" />\n                    </div>\n                    <div class="show-information">\n                        <div class="progressbar hidden-print" style="position:relative;" data-show-id="'
                )
                __M_writer(filters.url_escape(unicode(loading_show.id)))
                __M_writer(
                    u'" data-progress-percentage="0"></div>\n                        <div class="show-title">'
                )
                __M_writer(unicode(_('Loading')))
                __M_writer(u' (')
                __M_writer(unicode(loading_show.name))
                __M_writer(
                    u')</div>\n                        <div class="show-date">&nbsp;</div>\n                        <div class="show-details">\n                            <table class="show-details" width="100%" cellspacing="1" border="0" cellpadding="0">\n                                <tr>\n                                    <td class="show-table">\n                                        <span class="show-dlstats" title="'
                )
                __M_writer(unicode('Loading'))
                __M_writer(u'">')
                __M_writer(unicode('Loading'))
                __M_writer(
                    u'</span>\n                                    </td>\n                                    <td class="show-table">\n                                        <span title="'
                )
                __M_writer(unicode(loading_show.network))
                __M_writer(
                    u'"><img class="show-network-image" src="" data-src="')
                __M_writer(unicode(srRoot))
                __M_writer(u'/showPoster/?show=')
                __M_writer(filters.url_escape(unicode(loading_show.id)))
                __M_writer(u'&amp;which=network" alt="')
                __M_writer(unicode(loading_show.network))
                __M_writer(u'" title="')
                __M_writer(unicode(loading_show.network))
                __M_writer(
                    u'" /></span>\n                                    </td>\n                                    <td class="show-table">\n                                        '
                )
                __M_writer(
                    unicode(
                        renderQualityPill(loading_show.quality,
                                          showTitle=True,
                                          overrideClass="show-quality")))
                __M_writer(
                    u'\n                                    </td>\n                                </tr>\n                            </table>\n                        </div>\n                    </div>\n                </div>\n'
                )
            for curShow in myShowList:
                __M_writer(u'                ')

                if sickbeard.showQueueScheduler.action.is_in_remove_queue(
                        curShow
                ) or sickbeard.showQueueScheduler.action.is_being_removed(
                        curShow):
                    continue

                cur_airs_next = ''
                cur_snatched = 0
                cur_downloaded = 0
                cur_total = 0
                download_stat_tip = ''
                display_status = curShow.status

                if display_status:
                    if re.search(r'(?i)(?:new|returning)\s*series',
                                 curShow.status):
                        display_status = 'Continuing'
                    elif re.search(r'(?i)(?:nded)', curShow.status):
                        display_status = 'Ended'

                if curShow.indexerid in show_stat:
                    cur_airs_next = show_stat[
                        curShow.indexerid]['ep_airs_next']

                    cur_snatched = show_stat[
                        curShow.indexerid]['ep_snatched'] or 0
                    cur_downloaded = show_stat[
                        curShow.indexerid]['ep_downloaded'] or 0
                    cur_total = show_stat[curShow.indexerid]['ep_total'] or 0

                download_stat = str(cur_downloaded)
                download_stat_tip = _('Downloaded') + ": " + str(
                    cur_downloaded)

                if cur_snatched:
                    download_stat = download_stat + "+" + str(cur_snatched)
                    download_stat_tip = download_stat_tip + "&#013;" + _(
                        'Snatched') + ": " + str(cur_snatched)

                download_stat = download_stat + " / " + str(cur_total)
                download_stat_tip = download_stat_tip + "&#013;" + _(
                    'Total') + ": " + str(cur_total)

                nom = cur_downloaded
                if cur_total:
                    den = cur_total
                else:
                    den = 1
                    download_stat_tip = _('Unaired')

                progressbar_percent = nom * 100 / den

                data_date = '6000000000.0'
                if cur_airs_next:
                    data_date = calendar.timegm(
                        sbdatetime.sbdatetime.convert_to_setting(
                            network_timezones.parse_date_time(
                                cur_airs_next, curShow.airs,
                                curShow.network)).timetuple())
                elif display_status:
                    if display_status != 'Ended' and curShow.paused:
                        data_date = '5000000500.0'
                    elif display_status == 'Continuing':
                        data_date = '5000000000.0'
                    elif display_status == 'Ended':
                        data_date = '5000000100.0'

                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(
                    __M_dict_builtin([
                        (__M_key, __M_locals_builtin_stored[__M_key])
                        for __M_key in [
                            'nom', 'cur_downloaded', 'display_status',
                            'cur_total', 'cur_snatched', 'progressbar_percent',
                            'cur_airs_next', 'den', 'download_stat',
                            'data_date', 'download_stat_tip'
                        ] if __M_key in __M_locals_builtin_stored
                    ]))
                __M_writer(
                    u'\n                <div class="show-container" id="show')
                __M_writer(unicode(curShow.indexerid))
                __M_writer(u'" data-name="')
                __M_writer(unicode(curShow.sort_name))
                __M_writer(u'" data-date="')
                __M_writer(unicode(data_date))
                __M_writer(u'" data-network="')
                __M_writer(unicode(curShow.network))
                __M_writer(u'" data-progress="')
                __M_writer(unicode(progressbar_percent))
                __M_writer(
                    u'">\n                    <div class="show-image">\n                        <a href="'
                )
                __M_writer(unicode(srRoot))
                __M_writer(u'/home/displayShow?show=')
                __M_writer(unicode(curShow.indexerid))
                __M_writer(
                    u'"><img alt="" class="show-image" src="" data-src="')
                __M_writer(unicode(srRoot))
                __M_writer(u'/showPoster/?show=')
                __M_writer(unicode(curShow.indexerid))
                __M_writer(
                    u'&amp;which=poster_thumb" /></a>\n                    </div>\n\n                    <div class="show-information">\n                        <div class="progressbar hidden-print" style="position:relative;" data-show-id="'
                )
                __M_writer(unicode(curShow.indexerid))
                __M_writer(u'" data-progress-percentage="')
                __M_writer(unicode(progressbar_percent))
                __M_writer(
                    u'"></div>\n\n                        <div class="show-title">\n                            '
                )
                __M_writer(unicode(curShow.name))
                __M_writer(
                    u'\n                        </div>\n\n                        <div class="show-date">\n'
                )
                if cur_airs_next:
                    __M_writer(u'                            ')
                    ldatetime = sbdatetime.sbdatetime.convert_to_setting(
                        network_timezones.parse_date_time(
                            cur_airs_next, curShow.airs, curShow.network))

                    __M_locals_builtin_stored = __M_locals_builtin()
                    __M_locals.update(
                        __M_dict_builtin([
                            (__M_key, __M_locals_builtin_stored[__M_key])
                            for __M_key in ['ldatetime']
                            if __M_key in __M_locals_builtin_stored
                        ]))
                    __M_writer(u'\n                            ')

                    try:
                        out = str(sbdatetime.sbdatetime.sbfdate(ldatetime))
                    except ValueError:
                        out = _('Invalid date')
                        pass

                    __M_locals_builtin_stored = __M_locals_builtin()
                    __M_locals.update(
                        __M_dict_builtin([
                            (__M_key, __M_locals_builtin_stored[__M_key])
                            for __M_key in ['out']
                            if __M_key in __M_locals_builtin_stored
                        ]))
                    __M_writer(u'\n                            ')
                    __M_writer(unicode(out))
                    __M_writer(u'\n')
                else:
                    __M_writer(u'                            ')

                    output_html = '?'
                    display_status = curShow.status
                    if display_status:
                        if display_status != 'Ended' and curShow.paused:
                            output_html = 'Paused'
                        elif display_status:
                            output_html = display_status

                    __M_locals_builtin_stored = __M_locals_builtin()
                    __M_locals.update(
                        __M_dict_builtin([
                            (__M_key, __M_locals_builtin_stored[__M_key])
                            for __M_key in ['display_status', 'output_html']
                            if __M_key in __M_locals_builtin_stored
                        ]))
                    __M_writer(u'\n                            ')
                    __M_writer(unicode(_(output_html)))
                    __M_writer(u'\n')
                __M_writer(
                    u'                        </div>\n\n                        <div class="show-details">\n                            <table class="show-details" width="100%" cellspacing="1" border="0" cellpadding="0">\n                                <tr>\n                                    <td class="show-table">\n                                        <span class="show-dlstats" title="'
                )
                __M_writer(unicode(download_stat_tip))
                __M_writer(u'">')
                __M_writer(unicode(download_stat))
                __M_writer(
                    u'</span>\n                                    </td>\n\n                                    <td class="show-table">\n'
                )
                if curShow.network:
                    __M_writer(
                        u'                                            <span title="'
                    )
                    __M_writer(unicode(curShow.network))
                    __M_writer(
                        u'"><img class="show-network-image" src="" data-src="')
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/showPoster/?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'&amp;which=network" alt="')
                    __M_writer(unicode(curShow.network))
                    __M_writer(u'" title="')
                    __M_writer(unicode(curShow.network))
                    __M_writer(u'" /></span>\n')
                else:
                    __M_writer(
                        u'                                            <span title="'
                    )
                    __M_writer(unicode(_('No Network')))
                    __M_writer(
                        u'"><img class="show-network-image" src="" data-src="')
                    __M_writer(
                        unicode(static_url('images/network/nonetwork.png')))
                    __M_writer(
                        u'" alt="No Network" title="No Network" /></span>\n')
                __M_writer(
                    u'                                    </td>\n                                    <td class="show-table">\n                                        '
                )
                __M_writer(
                    unicode(
                        renderQualityPill(curShow.quality,
                                          showTitle=True,
                                          overrideClass="show-quality")))
                __M_writer(
                    u'\n                                    </td>\n                                </tr>\n                            </table>\n                        </div>\n                    </div>\n                </div>\n'
                )
            __M_writer(u'        </div>\n    </div>\n')
        else:
            __M_writer(
                u'    <div class="horizontal-scroll">\n        <table id="showListTable'
            )
            __M_writer(unicode(curListType))
            __M_writer(
                u'" class="tablesorter" cellspacing="1" border="0" cellpadding="0">\n            <thead>\n                <tr>\n                    <th class="nowrap">'
            )
            __M_writer(unicode(_('Next Ep')))
            __M_writer(u'</th>\n                    <th class="nowrap">')
            __M_writer(unicode(_('Prev Ep')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Show')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Network')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Quality')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Downloads')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Size')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Active')))
            __M_writer(u'</th>\n                    <th>')
            __M_writer(unicode(_('Status')))
            __M_writer(
                u'</th>\n                </tr>\n            </thead>\n            <tfoot class="hidden-print">\n                <tr>\n                    <th rowspan="1" colspan="1" align="center"><a href="'
            )
            __M_writer(unicode(static_url("addShows/", include_version=False)))
            __M_writer(u'">')
            __M_writer(unicode(_('Add')))
            __M_writer(u' ')
            __M_writer(unicode(
                (_('Show'), _('Anime'))[curListType == 'Anime']))
            __M_writer(
                u'</a></th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                    <th>&nbsp;</th>\n                </tr>\n            </tfoot>\n            <tbody>\n'
            )
            for curLoadingShow in sickbeard.showQueueScheduler.action.loading_show_list:
                __M_writer(u'                    ')
                loading_show = curLoadingShow.info

                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(
                    __M_dict_builtin([
                        (__M_key, __M_locals_builtin_stored[__M_key])
                        for __M_key in ['loading_show']
                        if __M_key in __M_locals_builtin_stored
                    ]))
                __M_writer(
                    u'\n                    <tr>\n                        <td align="center">('
                )
                __M_writer(unicode(_('loading')))
                __M_writer(u')</td><td align="center"></td>\n')
                if sickbeard.HOME_LAYOUT == 'small':
                    __M_writer(
                        u'                            <td class="tvShow">\n                                <div class="imgsmallposter '
                    )
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(u'">\n')
                    if curLoadingShow.show:
                        __M_writer(
                            u'                                        <a href="'
                        )
                        __M_writer(unicode(srRoot))
                        __M_writer(u'/home/displayShow?show=')
                        __M_writer(filters.url_escape(unicode(
                            loading_show.id)))
                        __M_writer(u'" title="')
                        __M_writer(unicode(loading_show.name))
                        __M_writer(u'">\n')
                    else:
                        __M_writer(
                            u'                                        <span title="'
                        )
                        __M_writer(unicode(loading_show.name))
                        __M_writer(u'">\n')
                    __M_writer(
                        u'                                    <img src="" data-src="'
                    )
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/showPoster/?show=')
                    __M_writer(filters.url_escape(unicode(loading_show.id)))
                    __M_writer(u'&amp;which=poster_thumb" class="')
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(u'" alt="')
                    __M_writer(unicode(loading_show.name))
                    __M_writer(u'"/>\n')
                    if curLoadingShow.show:
                        __M_writer(
                            u'                                        </a>\n                                        <a href="'
                        )
                        __M_writer(unicode(srRoot))
                        __M_writer(u'/home/displayShow?show=')
                        __M_writer(filters.url_escape(unicode(
                            loading_show.id)))
                        __M_writer(u'" style="vertical-align: middle;">')
                        __M_writer(unicode(loading_show.name))
                        __M_writer(u'</a>\n')
                    else:
                        __M_writer(
                            u'                                        </span>\n                                        <span style="vertical-align: middle;">'
                        )
                        __M_writer(unicode(_('Loading...')))
                        __M_writer(u' (')
                        __M_writer(unicode(loading_show.name))
                        __M_writer(u')</span>\n')
                    __M_writer(
                        u'                                </div>\n                            </td>\n'
                    )
                elif sickbeard.HOME_LAYOUT == 'banner':
                    __M_writer(
                        u'                            <td>\n                                <span style="display: none;">'
                    )
                    __M_writer(unicode(_('Loading...')))
                    __M_writer(u' (')
                    __M_writer(unicode(loading_show.name))
                    __M_writer(
                        u')</span>\n                                <div class="imgbanner '
                    )
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(u'">\n')
                    if curLoadingShow.show:
                        __M_writer(
                            u'                                        <a href="'
                        )
                        __M_writer(unicode(srRoot))
                        __M_writer(u'/home/displayShow?show=')
                        __M_writer(filters.url_escape(unicode(
                            loading_show.id)))
                        __M_writer(u'">\n')
                    __M_writer(
                        u'                                    <img src="" data-src="'
                    )
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/showPoster/?show=')
                    __M_writer(filters.url_escape(unicode(loading_show.id)))
                    __M_writer(u'&amp;which=banner" class="')
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(u'" alt="')
                    __M_writer(unicode(loading_show.name))
                    __M_writer(u'" title="')
                    __M_writer(unicode(loading_show.name))
                    __M_writer(u'"/>\n')
                    if curLoadingShow.show:
                        __M_writer(
                            u'                                        </a>\n')
                    __M_writer(
                        u'                                </div>\n                            </td>\n'
                    )
                elif sickbeard.HOME_LAYOUT == 'simple':
                    __M_writer(
                        u'                            <td class="tvShow">\n')
                    if curLoadingShow.show:
                        __M_writer(
                            u'                                    <a href="')
                        __M_writer(unicode(srRoot))
                        __M_writer(u'/home/displayShow?show=')
                        __M_writer(filters.url_escape(unicode(
                            loading_show.id)))
                        __M_writer(u'">')
                        __M_writer(unicode(loading_show.name))
                        __M_writer(u'</a>\n')
                    else:
                        __M_writer(
                            u'                                    <span title="">'
                        )
                        __M_writer(unicode(_('Loading...')))
                        __M_writer(u' (')
                        __M_writer(unicode(loading_show.name))
                        __M_writer(u')</span>\n')
                    __M_writer(u'                            </td>\n')
                __M_writer(
                    u'                        <td></td>\n                        <td></td>\n                        <td></td>\n                        <td></td>\n                        <td></td>\n                        <td></td>\n                    </tr>\n'
                )
            for curShow in myShowList:
                __M_writer(u'                    ')

                if sickbeard.showQueueScheduler.action.is_in_remove_queue(
                        curShow
                ) or sickbeard.showQueueScheduler.action.is_being_removed(
                        curShow):
                    continue

                cur_airs_next = ''
                cur_airs_prev = ''
                cur_snatched = 0
                cur_downloaded = 0
                cur_total = 0
                show_size = 0
                download_stat_tip = ''

                if curShow.indexerid in show_stat:
                    cur_airs_next = show_stat[
                        curShow.indexerid]['ep_airs_next']
                    cur_airs_prev = show_stat[
                        curShow.indexerid]['ep_airs_prev']

                    cur_snatched = show_stat[curShow.indexerid]['ep_snatched']
                    if not cur_snatched:
                        cur_snatched = 0

                    cur_downloaded = show_stat[
                        curShow.indexerid]['ep_downloaded']
                    if not cur_downloaded:
                        cur_downloaded = 0

                    cur_total = show_stat[curShow.indexerid]['ep_total']
                    if not cur_total:
                        cur_total = 0

                    show_size = show_stat[curShow.indexerid]['show_size']

                download_stat = str(cur_downloaded)
                download_stat_tip = _('Downloaded') + ": " + str(
                    cur_downloaded)

                if cur_snatched:
                    download_stat = download_stat + "+" + str(cur_snatched)
                    download_stat_tip = download_stat_tip + "&#013;" + _(
                        'Snatched') + ": " + str(cur_snatched)

                download_stat = download_stat + " / " + str(cur_total)
                download_stat_tip = download_stat_tip + "&#013;" + _(
                    'Total') + ": " + str(cur_total)

                nom = cur_downloaded
                if cur_total:
                    den = cur_total
                else:
                    den = 1
                    download_stat_tip = _('Unaired')

                progressbar_percent = nom * 100 / den

                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(
                    __M_dict_builtin([
                        (__M_key, __M_locals_builtin_stored[__M_key])
                        for __M_key in [
                            'nom', 'cur_airs_prev', 'cur_downloaded',
                            'cur_total', 'cur_snatched', 'show_size',
                            'progressbar_percent', 'cur_airs_next', 'den',
                            'download_stat', 'download_stat_tip'
                        ] if __M_key in __M_locals_builtin_stored
                    ]))
                __M_writer(u'\n                    <tr>\n')
                if cur_airs_next:
                    __M_writer(u'                            ')
                    airDate = sbdatetime.sbdatetime.convert_to_setting(
                        network_timezones.parse_date_time(
                            cur_airs_next, curShow.airs, curShow.network))

                    __M_locals_builtin_stored = __M_locals_builtin()
                    __M_locals.update(
                        __M_dict_builtin([
                            (__M_key, __M_locals_builtin_stored[__M_key])
                            for __M_key in ['airDate']
                            if __M_key in __M_locals_builtin_stored
                        ]))
                    __M_writer(u'\n')
                    try:
                        __M_writer(
                            u'                                <td align="center" class="nowrap">\n                                    <time datetime="'
                        )
                        __M_writer(unicode(airDate.isoformat('T')))
                        __M_writer(u'" class="date">')
                        __M_writer(
                            unicode(sbdatetime.sbdatetime.sbfdate(airDate)))
                        __M_writer(
                            u'</time>\n                                </td>\n'
                        )
                    except ValueError:
                        __M_writer(
                            u'                                <td align="center" class="nowrap"></td>\n'
                        )
                else:
                    __M_writer(
                        u'                            <td align="center" class="nowrap"></td>\n'
                    )
                __M_writer(u'\n')
                if cur_airs_prev:
                    __M_writer(u'                            ')
                    airDate = sbdatetime.sbdatetime.convert_to_setting(
                        network_timezones.parse_date_time(
                            cur_airs_prev, curShow.airs, curShow.network))

                    __M_locals_builtin_stored = __M_locals_builtin()
                    __M_locals.update(
                        __M_dict_builtin([
                            (__M_key, __M_locals_builtin_stored[__M_key])
                            for __M_key in ['airDate']
                            if __M_key in __M_locals_builtin_stored
                        ]))
                    __M_writer(u'\n')
                    try:
                        __M_writer(
                            u'                                <td align="center" class="nowrap">\n                                    <time datetime="'
                        )
                        __M_writer(unicode(airDate.isoformat('T')))
                        __M_writer(u'" class="date">')
                        __M_writer(
                            unicode(sbdatetime.sbdatetime.sbfdate(airDate)))
                        __M_writer(
                            u'</time>\n                                </td>\n'
                        )
                    except ValueError:
                        __M_writer(
                            u'                                <td align="center" class="nowrap"></td>\n'
                        )
                else:
                    __M_writer(
                        u'                            <td align="center" class="nowrap"></td>\n'
                    )
                __M_writer(u'\n')
                if sickbeard.HOME_LAYOUT == 'small':
                    __M_writer(
                        u'                            <td class="tvShow">\n                                <div class="imgsmallposter '
                    )
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(
                        u'">\n                                    <a href="')
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/home/displayShow?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'" title="')
                    __M_writer(unicode(curShow.name))
                    __M_writer(
                        u'">\n                                        <img src="" data-src="'
                    )
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/showPoster/?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'&amp;which=poster_thumb" class="')
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(u'" alt="')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(
                        u'"/>\n                                    </a>\n                                    <a href="'
                    )
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/home/displayShow?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'" style="vertical-align: middle;">')
                    __M_writer(unicode(curShow.name))
                    __M_writer(
                        u'</a>\n                                </div>\n                            </td>\n'
                    )
                elif sickbeard.HOME_LAYOUT == 'banner':
                    __M_writer(
                        u'                            <td>\n                                <span style="display: none;">'
                    )
                    __M_writer(unicode(curShow.name))
                    __M_writer(
                        u'</span>\n                                <div class="imgbanner '
                    )
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(
                        u'">\n                                    <a href="')
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/home/displayShow?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(
                        u'">\n                                        <img src="" data-src="'
                    )
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/showPoster/?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'&amp;which=banner" class="')
                    __M_writer(unicode(sickbeard.HOME_LAYOUT))
                    __M_writer(u'" alt="')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'" title="')
                    __M_writer(unicode(curShow.name))
                    __M_writer(
                        u'"/>\n                                    </a>\n                                </div>\n                            </td>\n'
                    )
                elif sickbeard.HOME_LAYOUT == 'simple':
                    __M_writer(
                        u'                            <td class="tvShow"><a href="'
                    )
                    __M_writer(unicode(srRoot))
                    __M_writer(u'/home/displayShow?show=')
                    __M_writer(unicode(curShow.indexerid))
                    __M_writer(u'">')
                    __M_writer(unicode(curShow.name))
                    __M_writer(u'</a></td>\n')
                __M_writer(u'\n')
                if sickbeard.HOME_LAYOUT != 'simple':
                    __M_writer(
                        u'                            <td align="center">\n')
                    if curShow.network:
                        __M_writer(
                            u'                                    <span title="'
                        )
                        __M_writer(unicode(curShow.network))
                        __M_writer(
                            u'" class="hidden-print"><img id="network" width="54" height="27" src="" data-src="'
                        )
                        __M_writer(unicode(srRoot))
                        __M_writer(u'/showPoster/?show=')
                        __M_writer(unicode(curShow.indexerid))
                        __M_writer(u'&amp;which=network" alt="')
                        __M_writer(unicode(curShow.network))
                        __M_writer(u'" title="')
                        __M_writer(unicode(curShow.network))
                        __M_writer(
                            u'" /></span>\n                                    <span class="visible-print-inline">'
                        )
                        __M_writer(unicode(curShow.network))
                        __M_writer(u'</span>\n')
                    else:
                        __M_writer(
                            u'                                    <span title="No Network" class="hidden-print"><img id="network" width="54" height="27" src="" data-src="'
                        )
                        __M_writer(
                            unicode(
                                static_url('images/network/nonetwork.png')))
                        __M_writer(
                            u'" alt="No Network" title="No Network" /></span>\n                                    <span class="visible-print-inline">'
                        )
                        __M_writer(unicode(_('No Network')))
                        __M_writer(u'</span>\n')
                    __M_writer(u'                            </td>\n')
                else:
                    __M_writer(
                        u'                            <td>\n                                <span title="'
                    )
                    __M_writer(unicode(curShow.network))
                    __M_writer(u'">')
                    __M_writer(unicode(curShow.network))
                    __M_writer(u'</span>\n                            </td>\n')
                __M_writer(u'\n                        <td align="center">')
                __M_writer(
                    unicode(renderQualityPill(curShow.quality,
                                              showTitle=True)))
                __M_writer(
                    u'</td>\n\n                        <td align="center">\n')
                __M_writer(
                    u'                            <span style="display: none;">'
                )
                __M_writer(unicode(download_stat))
                __M_writer(
                    u'</span>\n                            <div class="progressbar hidden-print" style="position:relative;" data-show-id="'
                )
                __M_writer(unicode(curShow.indexerid))
                __M_writer(u'" data-progress-percentage="')
                __M_writer(unicode(progressbar_percent))
                __M_writer(u'" data-progress-text="')
                __M_writer(unicode(download_stat))
                __M_writer(u'" data-progress-tip="')
                __M_writer(unicode(download_stat_tip))
                __M_writer(
                    u'"></div>\n                            <span class="visible-print-inline">'
                )
                __M_writer(unicode(download_stat))
                __M_writer(
                    u'</span>\n                        </td>\n\n                        <td align="center" data-show-size="'
                )
                __M_writer(unicode(show_size))
                __M_writer(u'">')
                __M_writer(unicode(pretty_file_size(show_size)))
                __M_writer(
                    u'</td>\n\n                        <td align="center">\n                            <span class="displayshow-icon-'
                )
                __M_writer(
                    unicode(("disable", "enable")[not bool(curShow.paused)]))
                __M_writer(u'" title="')
                __M_writer(unicode(('No', 'Yes')[not bool(curShow.paused)]))
                __M_writer(
                    u'"></span>\n                        </td>\n\n                        <td align="center">\n                            '
                )

                display_status = curShow.status
                if display_status:
                    if re.search(r'(?i)(?:new|returning)\s*series',
                                 curShow.status):
                        display_status = 'Continuing'
                    elif re.search('(?i)(?:nded)', curShow.status):
                        display_status = 'Ended'

                __M_locals_builtin_stored = __M_locals_builtin()
                __M_locals.update(
                    __M_dict_builtin([
                        (__M_key, __M_locals_builtin_stored[__M_key])
                        for __M_key in ['display_status']
                        if __M_key in __M_locals_builtin_stored
                    ]))
                __M_writer(u'\n                            ')
                __M_writer(unicode(_(display_status)))
                __M_writer(
                    u'\n                        </td>\n                    </tr>\n'
                )
            __M_writer(u'            </tbody>\n        </table>\n    </div>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()
Beispiel #28
0
def edit_comment_filter(text=''):
    try:
        text = unicode(text, 'utf-8')
    except TypeError:
        text = unicode(text)
    return url_escape(text)
Beispiel #29
0
def generateurl(context, path, **kw):
    if kw:
        return path + '?' + '&'.join(["%s=%s"%(k, url_escape(v)) \
                                      for k, v in kw.iteritems() if v])
    return path
Beispiel #30
0
    def pre(self):
        c.response_wrappers = []
        MinimalController.pre(self)

        set_cnameframe()

        # populate c.cookies unless we're on the unsafe media_domain
        if request.host != g.media_domain or g.media_domain == g.domain:
            try:
                for k, v in request.cookies.iteritems():
                    # minimalcontroller can still set cookies
                    if k not in c.cookies:
                        # we can unquote even if it's not quoted
                        c.cookies[k] = Cookie(value=unquote(v), dirty=False)
            except CookieError:
                #pylons or one of the associated retarded libraries
                #can't handle broken cookies
                request.environ['HTTP_COOKIE'] = ''

        c.firsttime = firsttime()

        # the user could have been logged in via one of the feeds
        maybe_admin = False

        # no logins for RSS feed unless valid_feed has already been called
        if not c.user:
            if c.extension != "rss":
                session_cookie = c.cookies.get(g.login_cookie)
                if session_cookie:
                    c.user = valid_cookie(session_cookie.value)
                    if c.user:
                        c.user_is_loggedin = True

                admin_cookie = c.cookies.get(g.admin_cookie)
                if c.user_is_loggedin and admin_cookie:
                    maybe_admin, first_login = valid_admin_cookie(
                        admin_cookie.value)

                    if maybe_admin:
                        self.enable_admin_mode(c.user, first_login=first_login)
                    else:
                        self.disable_admin_mode(c.user)

            if not c.user:
                c.user = UnloggedUser(get_browser_langs())
                # patch for fixing mangled language preferences
                if (not isinstance(c.user.pref_lang, basestring) or not all(
                        isinstance(x, basestring)
                        for x in c.user.pref_content_langs)):
                    c.user.pref_lang = g.lang
                    c.user.pref_content_langs = [g.lang]
                    c.user._commit()
        if c.user_is_loggedin:
            if not c.user._loaded:
                c.user._load()
            c.modhash = c.user.modhash()
            if request.method.upper() == 'GET':
                read_mod_cookie()
            if hasattr(c.user, 'msgtime') and c.user.msgtime:
                c.have_messages = c.user.msgtime
            c.show_mod_mail = Subreddit.reverse_moderator_ids(c.user)
            c.have_mod_messages = getattr(c.user, "modmsgtime", False)
            c.user_is_admin = maybe_admin and c.user.name in g.admins
            c.user_special_distinguish = c.user.special_distinguish()
            c.user_is_sponsor = c.user_is_admin or c.user.name in g.sponsors
            if request.path != '/validuser' and not g.disallow_db_writes:
                c.user.update_last_visit(c.start_time)

        c.over18 = over18()

        #set_browser_langs()
        set_host_lang()
        set_iface_lang()
        set_content_lang()
        set_recent_clicks()
        # used for HTML-lite templates
        set_colors()

        # set some environmental variables in case we hit an abort
        if not isinstance(c.site, FakeSubreddit):
            request.environ['REDDIT_NAME'] = c.site.name

        # random reddit trickery -- have to do this after the content lang is set
        if c.site == Random:
            c.site = Subreddit.random_reddit()
            redirect_to("/" + c.site.path.strip('/') + request.path)
        elif c.site == RandomNSFW:
            c.site = Subreddit.random_reddit(over18=True)
            redirect_to("/" + c.site.path.strip('/') + request.path)

        if not request.path.startswith("/api/login/"):
            # is the subreddit banned?
            if c.site.spammy() and not c.user_is_admin and not c.error_page:
                ban_info = getattr(c.site, "ban_info", {})
                if "message" in ban_info:
                    message = ban_info['message']
                else:
                    sitelink = url_escape(add_sr("/"))
                    subject = ("/r/%s has been incorrectly banned" %
                               c.site.name)
                    link = ("/r/redditrequest/submit?url=%s&title=%s" %
                            (sitelink, subject))
                    message = strings.banned_subreddit_message % dict(
                        link=link)
                errpage = pages.RedditError(strings.banned_subreddit_title,
                                            message,
                                            image="subreddit-banned.png")
                request.environ['usable_error_content'] = errpage.render()
                self.abort404()

            # check if the user has access to this subreddit
            if not c.site.can_view(c.user) and not c.error_page:
                errpage = pages.RedditError(strings.private_subreddit_title,
                                            strings.private_subreddit_message,
                                            image="subreddit-private.png")
                request.environ['usable_error_content'] = errpage.render()
                self.abort403()

            #check over 18
            if (c.site.over_18 and not c.over18
                    and request.path not in ("/frame", "/over18")
                    and c.render_style == 'html'):
                return self.intermediate_redirect("/over18")

        #check whether to allow custom styles
        c.allow_styles = True
        c.can_apply_styles = self.allow_stylesheets
        if g.css_killswitch:
            c.can_apply_styles = False
        #if the preference is set and we're not at a cname
        elif not c.user.pref_show_stylesheets and not c.cname:
            c.can_apply_styles = False
        #if the site has a cname, but we're not using it
        elif c.site.domain and c.site.css_on_cname and not c.cname:
            c.can_apply_styles = False
Beispiel #31
0
 def resubmit_link(self, sr_url = False):
     submit_url  = self.subreddit_slow.path if sr_url else '/'
     submit_url += 'submit?resubmit=true&url=' + url_escape(self.url)
     return submit_url
Beispiel #32
0
    def pre(self):
        record_timings = g.admin_cookie in request.cookies or g.debug
        admin_bar_eligible = response.content_type == 'text/html'
        if admin_bar_eligible and record_timings:
            g.stats.start_logging_timings()

        # set up stuff needed in base templates at error time here.
        c.js_preload = JSPreload()

        MinimalController.pre(self)

        set_cnameframe()

        # populate c.cookies unless we're on the unsafe media_domain
        if request.host != g.media_domain or g.media_domain == g.domain:
            cookie_counts = collections.Counter()
            try:
                for k, v in request.cookies.iteritems():
                    # minimalcontroller can still set cookies
                    if k not in c.cookies:
                        # we can unquote even if it's not quoted
                        c.cookies[k] = Cookie(value=unquote(v), dirty=False)
                        cookie_counts[Cookie.classify(k)] += 1
            except CookieError:
                #pylons or one of the associated retarded libraries
                #can't handle broken cookies
                request.environ['HTTP_COOKIE'] = ''

            for cookietype, count in cookie_counts.iteritems():
                g.stats.simple_event("cookie.%s" % cookietype, count)

        delete_obsolete_cookies()

        # the user could have been logged in via one of the feeds
        maybe_admin = False
        is_otpcookie_valid = False

        # no logins for RSS feed unless valid_feed has already been called
        if not c.user:
            if c.extension != "rss":
                authenticate_user()

                admin_cookie = c.cookies.get(g.admin_cookie)
                if c.user_is_loggedin and admin_cookie:
                    maybe_admin, first_login = valid_admin_cookie(
                        admin_cookie.value)

                    if maybe_admin:
                        self.enable_admin_mode(c.user, first_login=first_login)
                    else:
                        self.disable_admin_mode(c.user)

                otp_cookie = read_user_cookie(g.otp_cookie)
                if c.user_is_loggedin and otp_cookie:
                    is_otpcookie_valid = valid_otp_cookie(otp_cookie)

            if not c.user:
                c.user = UnloggedUser(get_browser_langs())
                # patch for fixing mangled language preferences
                if (not isinstance(c.user.pref_lang, basestring) or not all(
                        isinstance(x, basestring)
                        for x in c.user.pref_content_langs)):
                    c.user.pref_lang = g.lang
                    c.user.pref_content_langs = [g.lang]
                    c.user._commit()
        if c.user_is_loggedin:
            if not c.user._loaded:
                c.user._load()
            c.modhash = c.user.modhash()
            if hasattr(c.user, 'msgtime') and c.user.msgtime:
                c.have_messages = c.user.msgtime
            c.show_mod_mail = Subreddit.reverse_moderator_ids(c.user)
            c.have_mod_messages = getattr(c.user, "modmsgtime", False)
            c.user_is_admin = maybe_admin and c.user.name in g.admins
            c.user_special_distinguish = c.user.special_distinguish()
            c.user_is_sponsor = c.user_is_admin or c.user.name in g.sponsors
            c.otp_cached = is_otpcookie_valid
            if not isinstance(c.site,
                              FakeSubreddit) and not g.disallow_db_writes:
                c.user.update_sr_activity(c.site)

        c.over18 = over18()
        set_obey_over18()

        # looking up the multireddit requires c.user.
        set_multireddit()

        #set_browser_langs()
        set_host_lang()
        set_iface_lang()
        set_content_lang()
        set_recent_clicks()
        # used for HTML-lite templates
        set_colors()

        # set some environmental variables in case we hit an abort
        if not isinstance(c.site, FakeSubreddit):
            request.environ['REDDIT_NAME'] = c.site.name

        # random reddit trickery -- have to do this after the content lang is set
        if c.site == Random:
            c.site = Subreddit.random_reddit(user=c.user)
            redirect_to("/" + c.site.path.strip('/') + request.path_qs)
        elif c.site == RandomSubscription:
            if c.user.gold:
                c.site = Subreddit.random_subscription(c.user)
                redirect_to('/' + c.site.path.strip('/') + request.path_qs)
            else:
                redirect_to('/gold/about')
        elif c.site == RandomNSFW:
            c.site = Subreddit.random_reddit(over18=True, user=c.user)
            redirect_to("/" + c.site.path.strip('/') + request.path_qs)

        if not request.path.startswith("/api/login/"):
            # is the subreddit banned?
            if c.site.spammy() and not c.user_is_admin and not c.error_page:
                ban_info = getattr(c.site, "ban_info", {})
                if "message" in ban_info:
                    message = ban_info['message']
                else:
                    sitelink = url_escape(add_sr("/"))
                    subject = ("/r/%s has been incorrectly banned" %
                               c.site.name)
                    link = ("/r/redditrequest/submit?url=%s&title=%s" %
                            (sitelink, subject))
                    message = strings.banned_subreddit_message % dict(
                        link=link)
                errpage = pages.RedditError(strings.banned_subreddit_title,
                                            message,
                                            image="subreddit-banned.png")
                request.environ['usable_error_content'] = errpage.render()
                self.abort404()

            # check if the user has access to this subreddit
            if not c.site.can_view(c.user) and not c.error_page:
                if isinstance(c.site, LabeledMulti):
                    # do not leak the existence of multis via 403.
                    self.abort404()
                else:
                    public_description = c.site.public_description
                    errpage = pages.RedditError(
                        strings.private_subreddit_title,
                        strings.private_subreddit_message,
                        image="subreddit-private.png",
                        sr_description=public_description,
                    )
                    request.environ['usable_error_content'] = errpage.render()
                    self.abort403()

            #check over 18
            if (c.site.over_18 and not c.over18
                    and request.path not in ("/frame", "/over18")
                    and c.render_style == 'html'):
                return self.intermediate_redirect("/over18")

        #check whether to allow custom styles
        c.allow_styles = True
        c.can_apply_styles = self.allow_stylesheets
        if g.css_killswitch:
            c.can_apply_styles = False
        #if the preference is set and we're not at a cname
        elif not c.user.pref_show_stylesheets and not c.cname:
            c.can_apply_styles = False
        #if the site has a cname, but we're not using it
        elif c.site.domain and c.site.css_on_cname and not c.cname:
            c.can_apply_styles = False

        c.bare_content = request.GET.pop('bare', False)

        c.show_admin_bar = admin_bar_eligible and (c.user_is_admin or g.debug)
        if not c.show_admin_bar:
            g.stats.end_logging_timings()

        hooks.get_hook("reddit.request.begin").call()

        c.request_timer.intermediate("base-pre")
Beispiel #33
0
 def resubmit_link(self, sr_url=False):
     submit_url = self.subreddit_slow.path if sr_url else '/'
     submit_url += 'submit?resubmit=true&url=' + url_escape(self.url)
     return submit_url