Skip to content

Commit

Permalink
Reorganize and prettify error pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed Apr 24, 2012
1 parent 38ed72d commit 212d071
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 231 deletions.
31 changes: 9 additions & 22 deletions r2/r2/controllers/error.py
Expand Up @@ -20,7 +20,6 @@
# CondeNet, Inc. All Rights Reserved.
################################################################################
import os.path
from mako.filters import url_escape

import pylons
import paste.fileapp
Expand Down Expand Up @@ -111,32 +110,20 @@ def __call__(self, environ, start_response):
def send403(self):
c.response.status_code = 403
c.site = DefaultSR()
res = pages.RedditError(_("forbidden (%(domain)s)") %
dict(domain=g.domain))
return res.render()
if 'usable_error_content' in request.environ:
return request.environ['usable_error_content']
else:
res = pages.RedditError(
title=_("forbidden (%(domain)s)") % dict(domain=g.domain),
message=_("you are not allowed to do that"))
return res.render()

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()
return pages.RedditError(_("page not found"),
_("the page you requested does not exist")).render()

def send429(self):
c.response.status_code = 429
Expand Down
27 changes: 20 additions & 7 deletions r2/r2/controllers/reddit_base.py
Expand Up @@ -19,6 +19,7 @@
# All portions of the code written by CondeNet are Copyright (c) 2006-2010
# CondeNet, Inc. All Rights Reserved.
################################################################################
from mako.filters import url_escape
import r2.lib.helpers as h
from pylons import c, g, request
from pylons.controllers.util import abort, redirect_to
Expand Down Expand Up @@ -857,13 +858,27 @@ def pre(self):
redirect_to("/" + c.site.path.strip('/') + request.path)

if not request.path.startswith("/api/login/"):
# check that the site is available:
# is the subreddit banned?
if c.site.spammy() and not c.user_is_admin and not c.error_page:
abort(404, "not found")
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)
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:
abort(403, "forbidden")
self.abort403()

#check over 18
if (c.site.over_18 and not c.over18 and
Expand Down Expand Up @@ -917,11 +932,9 @@ def search_fail(self, exception):
elif isinstance(exception, (IndextankException, socket.error)):
g.log.error("IndexTank Error: %s" % repr(exception))

sf = pages.SearchFail()

us = filters.unsafe(sf.render())
errpage = pages.RedditError(_("search failed"),
strings.search_failed)

errpage = pages.RedditError(_('search failed'), us)
request.environ['usable_error_content'] = errpage.render()
request.environ['retry_after'] = 60
abort(503)
38 changes: 10 additions & 28 deletions r2/r2/lib/pages/pages.py
Expand Up @@ -1310,30 +1310,20 @@ def __init__(self, client, *args, **kwargs):

class RedditError(BoringPage):
site_tracking = False
def __init__(self, title, message = None):
if not message:
message = title
def __init__(self, title, message, image=None):
BoringPage.__init__(self, title, loginbox=False,
show_sidebar = False,
content=ErrorPage(message))
show_sidebar = False,
content=ErrorPage(title=title,
message=message,
image=image))

class Reddit404(BoringPage):
site_tracking = False
def __init__(self):
ch=random.choice(['a','b','c','d','e'])
BoringPage.__init__(self, _("page not found"), loginbox=False,
show_sidebar = False,
content=UnfoundPage(ch))

class UnfoundPage(Templated):
"""Wrapper for the 404 page"""
def __init__(self, choice):
Templated.__init__(self, choice = choice)

class ErrorPage(Templated):
"""Wrapper for an error message"""
def __init__(self, message = _("you aren't allowed to do that.")):
Templated.__init__(self, message = message)
def __init__(self, title, message, image=None):
if not image:
letter = random.choice(['a', 'b', 'c', 'd', 'e'])
image = 'reddit404' + letter + '.png'
Templated.__init__(self, title=title, message=message, image_url=image)

class Profiling(Templated):
"""Debugging template for code profiling using built in python
Expand Down Expand Up @@ -1739,14 +1729,6 @@ def __init__(self, num_results = 0, prev_search = '', elapsed_time = 0,
simple=simple, restrict_sr=restrict_sr,
site=site, subreddit_search=subreddit_search)

class SearchFail(Templated):
"""Search failure page."""
def __init__(self, **kw):
self.errmsg = strings.search_failed

Templated.__init__(self)


class Frame(Wrapped):
"""Frameset for the FrameToolbar used when a user hits /tb/. The
top 30px of the page are dedicated to the toolbar, while the rest
Expand Down
3 changes: 2 additions & 1 deletion r2/r2/lib/strings.py
Expand Up @@ -128,7 +128,8 @@
submit_box_archived_text = _('this subreddit is archived and no longer accepting submissions.'),
permalink_title = _("%(author)s comments on %(title)s"),
link_info_title = _("%(title)s : %(site)s"),
banned_subreddit = _("""**this reddit has been banned**\n\nmost likely this was done automatically by our spam filtering program. the program is still learning, and may even have some bugs, so if you feel the ban was a mistake, please submit a link to our [request a reddit listing](%(link)s) and be sure to include the **exact name of the reddit**."""),
banned_subreddit_title = _("this subreddit has been banned"),
banned_subreddit_message = _("most likely this was done automatically by our spam filtering program. the program is still learning, and may even have some bugs, so if you feel the ban was a mistake, please submit a link to our [request a subreddit listing](%(link)s) and be sure to include the **exact name of the subreddit**."),
comments_panel_text = _("""The following is a sample of what Reddit users had to say about this page. The full discussion is available [here](%(fd_link)s); you can also get there by clicking the link's title (in the middle of the toolbar, to the right of the comments button)."""),

submit_link = _("""You are submitting a link. The key to a successful submission is interesting content and a descriptive title."""),
Expand Down
8 changes: 8 additions & 0 deletions r2/r2/public/static/css/reddit.css
Expand Up @@ -5362,3 +5362,11 @@ tr.gold-accent + tr > td {
font-family: 'Courier New', monospace;
width: 50%;
}

#classy-error {
text-align: center;
}

#classy-error .md {
display: inline-block;
}
9 changes: 8 additions & 1 deletion r2/r2/templates/errorpage.compact
Expand Up @@ -20,4 +20,11 @@
## CondeNet, Inc. All Rights Reserved.
################################################################################

<%inherit file="errorpage.html" />
<%
from r2.lib.filters import unsafe, safemarkdown
%>

<div id="classy-error">
<h1>${thing.title}</h1>
${unsafe(safemarkdown(thing.message))}
</div>
12 changes: 11 additions & 1 deletion r2/r2/templates/errorpage.html
Expand Up @@ -20,4 +20,14 @@
## CondeNet, Inc. All Rights Reserved.
################################################################################

<p class="error">${thing.message}</p>
<%
from r2.lib.template_helpers import static
from r2.lib.filters import unsafe, safemarkdown
%>

<div id="classy-error" class="content">
<img src="${static(thing.image_url)}" alt="an unhappy alien" />

<h1>${thing.title}</h1>
${unsafe(safemarkdown(thing.message))}
</div>
File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions r2/r2/templates/searchfail.compact

This file was deleted.

25 changes: 0 additions & 25 deletions r2/r2/templates/searchfail.html

This file was deleted.

Empty file removed r2/r2/templates/searchfail.xml
Empty file.
25 changes: 0 additions & 25 deletions r2/r2/templates/unfoundpage.compact

This file was deleted.

28 changes: 0 additions & 28 deletions r2/r2/templates/unfoundpage.html

This file was deleted.

22 changes: 0 additions & 22 deletions r2/r2/templates/unfoundpage.htmllite

This file was deleted.

26 changes: 0 additions & 26 deletions r2/r2/templates/unfoundpage.mobile

This file was deleted.

22 changes: 0 additions & 22 deletions r2/r2/templates/unfoundpage.xml

This file was deleted.

0 comments on commit 212d071

Please sign in to comment.