From 9460b41ec29ffe2152e3e3d365cf95b3f9c4f8f8 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 13 May 2017 14:26:16 -0500 Subject: [PATCH] Add basic 'robots.txt' support to CommonView --- tailbone/static/robots.txt | 2 ++ tailbone/views/common.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tailbone/static/robots.txt diff --git a/tailbone/static/robots.txt b/tailbone/static/robots.txt new file mode 100644 index 00000000..1f53798b --- /dev/null +++ b/tailbone/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/tailbone/views/common.py b/tailbone/views/common.py index a9e4c479..5547efb3 100644 --- a/tailbone/views/common.py +++ b/tailbone/views/common.py @@ -26,12 +26,16 @@ Various common views from __future__ import unicode_literals, absolute_import +import six + import rattail from rattail.mail import send_email from rattail.util import OrderedDict +from rattail.files import resource_path import formencode as fe from pyramid import httpexceptions +from pyramid.response import Response from pyramid_simpleform import Form import tailbone @@ -55,6 +59,7 @@ class CommonView(View): """ project_title = "Tailbone" project_version = tailbone.__version__ + robots_txt_path = resource_path('tailbone.static:robots.txt') def home(self, mobile=False): """ @@ -65,6 +70,14 @@ class CommonView(View): default=self.request.static_url('tailbone:static/img/home_logo.png')) return {'image_url': image_url} + def robots_txt(self): + """ + Returns a basic 'robots.txt' response + """ + with open(self.robots_txt_path, 'rt') as f: + content = f.read() + return Response(content_type=six.binary_type('text/plain'), body=content) + def mobile_home(self): """ Home page view for mobile. @@ -135,6 +148,10 @@ class CommonView(View): config.add_route('mobile.home', '/mobile/') config.add_view(cls, attr='mobile_home', route_name='mobile.home', renderer='/mobile/home.mako') + # robots.txt + config.add_route('robots.txt', '/robots.txt') + config.add_view(cls, attr='robots_txt', route_name='robots.txt') + # about config.add_route('about', '/about') config.add_view(cls, attr='about', route_name='about', renderer='/about.mako')