Commit bb6de4c6 authored by Vincent Le gallic's avatar Vincent Le gallic

Custom 404

parent e6a08998
......@@ -1689,15 +1689,22 @@ def logout(request):
_add_success(request, settings.SUCCMSG_LOGOUT)
return HttpResponseRedirect(settings.NOTE_LOGIN_URL)
def _get_versions():
"""Renvoie un tuple contenant les versions de nginx et django."""
proc = subprocess.Popen(["nginx", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = proc.communicate()[1]
nginxversion = re.findall("nginx version: (.*)", err)
nginxversion = nginxversion[0] if nginxversion else None
return (nginxversion, django.get_version())
def _display_versions():
"""Revoie un string html-formaté des version de nginx et django."""
return "<address> %s <br/> Django/%s </address>\n" % _get_versions()
def teapot(request):
"""Easter egg"""
page = """<html><head>\n<title>418 I'm a Teapot</title>\n</head><body>\n<h1>HTCPCP error 418: I'm a Teapot</h1>\nThe requested URL cannot provide coffe, because this is a networked teapot. See RFC2324.<p>\n<hr>\n"""
proc = subprocess.Popen(["nginx", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
err = proc.communicate()[1]
nginxversion = re.findall("nginx version: (.*)", err)
if nginxversion:
page += "<address> %s <br/> Django/%s </address>\n"%(nginxversion[0], django.get_version())
page += _display_versions()
page += "</html>\n</body></html>"
return HttpResponse(page, status=418)
......@@ -1858,3 +1865,9 @@ def get_photo(request, idbde=None):
return HttpResponse('<img src = "%s"></img>' % (urlphoto))
else:
return HttpResponse("Erreur")
def page_not_found(request):
"""Page 404 customisée pour y ajouter des variables."""
variables = {"report_bugs_to" : settings.REPORT_BUGS_EMAIL,
"NOTE_ROOT_URL" : settings.NOTE_ROOT_URL}
return render_to_response('404.html', variables, context_instance=RequestContext(request))
......@@ -6,10 +6,11 @@ DEFAULT_CHARSET = "utf-8"
DEBUG = True
TEMPLATE_DEBUG = DEBUG
REPORT_BUGS_EMAIL = 'notekfet2015@crans.org'
ADMINS = (
('20-100', 'legallic@crans.org'),
('Report bugs to', 'notekfet2015@crans.org')
# ('Your Name', 'your_email@example.com'),
('Report bugs to', REPORT_BUGS_EMAIL)
)
NOTE_ROOT_URL = r'/note/'
......
<h1> 404 Page Not Found</h1>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Note Kfet 2015 - 404</title>
</head>
<body>
<h1>404 Page Not Found</h1>
<p>
Si tu as bidouillé l'URL pour tomber ici, ben t'es puni.
</p>
<p>
Sinon, c'est qu'il y un problème plus grave, dans ce cas, tu peux envoyer un mail à {{report_bugs_to}} en expliquant comment tu as obtenu ce bug.
</p>
<p>
Pour te sortir de cette situation :
<ul>
<li><a href="{{NOTE_ROOT_URL}}">Page de Login</a></li>
<li><a href="{{NOTE_ROOT_URL}}/consos">Consos</a></li>
</ul>
</p>
<hr>
<p><em>J'ai perdu.</em></p>
</body>
</html>
......@@ -9,6 +9,9 @@ if settings.DEBUG:
# On n'utilise pas ça en prod
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# custom 404
handler404 = "note.views.page_not_found"
from django.contrib import admin
admin.autodiscover()
import views
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment