Add robots.txt disallowing all
This commit is contained in:
parent
329264715e
commit
8d8d26a14e
2 changed files with 42 additions and 29 deletions
|
@ -2,11 +2,18 @@ from django.conf.urls import url
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.HomeView.as_view(), name='homepage'),
|
url(r"^$", views.HomeView.as_view(), name="homepage"),
|
||||||
url(r'^ecrire$', views.WriteArticleView.as_view(), name='write_article'),
|
url(r"^robots.txt$", views.robots_view, name="robots"),
|
||||||
url(r'^speciaux/', views.SpecialPublicationsView.as_view(),
|
url(r"^ecrire$", views.WriteArticleView.as_view(), name="write_article"),
|
||||||
name='special_publications'),
|
url(
|
||||||
url(r'^(?P<year>\d{4})-(?P<nYear>\d{4})/',
|
r"^speciaux/",
|
||||||
views.YearView.as_view(), name='year_view'),
|
views.SpecialPublicationsView.as_view(),
|
||||||
url(r'^latest$', views.latestPublication, name='latestPublication'),
|
name="special_publications",
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
r"^(?P<year>\d{4})-(?P<nYear>\d{4})/",
|
||||||
|
views.YearView.as_view(),
|
||||||
|
name="year_view",
|
||||||
|
),
|
||||||
|
url(r"^latest$", views.latestPublication, name="latestPublication"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,30 +1,38 @@
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.http import Http404
|
from django.http import Http404, HttpResponse
|
||||||
|
|
||||||
from mainsite.models import Publication, PublicationYear, SiteConfiguration
|
from mainsite.models import Publication, PublicationYear, SiteConfiguration
|
||||||
|
|
||||||
|
|
||||||
|
def robots_view(request):
|
||||||
|
""" Robots.txt view """
|
||||||
|
body = "User-Agent: *\nDisallow: /\n"
|
||||||
|
return HttpResponse(body, content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
class HomeView(TemplateView):
|
class HomeView(TemplateView):
|
||||||
''' Website's homepage '''
|
""" Website's homepage """
|
||||||
template_name = 'mainsite/homepage.html'
|
|
||||||
|
template_name = "mainsite/homepage.html"
|
||||||
|
|
||||||
|
|
||||||
class WriteArticleView(TemplateView):
|
class WriteArticleView(TemplateView):
|
||||||
''' Tell the readers how they can contribute to the BOcal '''
|
""" Tell the readers how they can contribute to the BOcal """
|
||||||
template_name = 'mainsite/write_article.html'
|
|
||||||
|
template_name = "mainsite/write_article.html"
|
||||||
|
|
||||||
|
|
||||||
class PublicationListView(TemplateView):
|
class PublicationListView(TemplateView):
|
||||||
''' Display a list of publications (generic class).
|
""" Display a list of publications (generic class).
|
||||||
|
|
||||||
Reimplement `get_publications` (called with the url template args in a
|
Reimplement `get_publications` (called with the url template args in a
|
||||||
place where you can Http404) in subclasses to get it working. '''
|
place where you can Http404) in subclasses to get it working. """
|
||||||
|
|
||||||
template_name = 'mainsite/publications_list_view.html'
|
template_name = "mainsite/publications_list_view.html"
|
||||||
|
|
||||||
def initView(self):
|
def initView(self):
|
||||||
''' Cannot be __init__, we don't have **kwargs there '''
|
""" Cannot be __init__, we don't have **kwargs there """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -37,13 +45,13 @@ class PublicationListView(TemplateView):
|
||||||
|
|
||||||
if len(publications) == 0:
|
if len(publications) == 0:
|
||||||
raise Http404
|
raise Http404
|
||||||
context['publications'] = publications
|
context["publications"] = publications
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class YearView(PublicationListView):
|
class YearView(PublicationListView):
|
||||||
''' Display a year worth of BOcals '''
|
""" Display a year worth of BOcals """
|
||||||
|
|
||||||
def initView(self, year, nYear):
|
def initView(self, year, nYear):
|
||||||
try:
|
try:
|
||||||
|
@ -58,9 +66,9 @@ class YearView(PublicationListView):
|
||||||
|
|
||||||
def additional_context(self, year, nYear):
|
def additional_context(self, year, nYear):
|
||||||
return {
|
return {
|
||||||
'intro_text': self.pubYear.descr,
|
"intro_text": self.pubYear.descr,
|
||||||
'is_year_view': True,
|
"is_year_view": True,
|
||||||
'year_range': self.pubYear.prettyName,
|
"year_range": self.pubYear.prettyName,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_publications(self, year, nYear):
|
def get_publications(self, year, nYear):
|
||||||
|
@ -68,24 +76,22 @@ class YearView(PublicationListView):
|
||||||
|
|
||||||
|
|
||||||
class SpecialPublicationsView(PublicationListView):
|
class SpecialPublicationsView(PublicationListView):
|
||||||
''' Display the list of special publications '''
|
""" Display the list of special publications """
|
||||||
|
|
||||||
def additional_context(self):
|
def additional_context(self):
|
||||||
siteConf = SiteConfiguration.get_solo()
|
siteConf = SiteConfiguration.get_solo()
|
||||||
return {
|
return {
|
||||||
'intro_text': siteConf.specialPublisDescr,
|
"intro_text": siteConf.specialPublisDescr,
|
||||||
'is_year_view': False,
|
"is_year_view": False,
|
||||||
'list_title': "Numéros spéciaux",
|
"list_title": "Numéros spéciaux",
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_publications(self):
|
def get_publications(self):
|
||||||
publications = Publication.objects\
|
publications = Publication.objects.filter(is_special=True).order_by("-date")
|
||||||
.filter(is_special=True)\
|
|
||||||
.order_by('-date')
|
|
||||||
return publications
|
return publications
|
||||||
|
|
||||||
|
|
||||||
def latestPublication(req):
|
def latestPublication(req):
|
||||||
''' Redirects to the latest standard publication '''
|
""" Redirects to the latest standard publication """
|
||||||
latestPubli = Publication.latest()
|
latestPubli = Publication.latest()
|
||||||
return redirect(latestPubli.url)
|
return redirect(latestPubli.url)
|
||||||
|
|
Loading…
Reference in a new issue