1498: Внепланово со скайпа - редиректы 301

remotes/origin/stage4
Alexander Burdeiny 10 years ago
parent edd92d4d6b
commit a89358e3d6
  1. 4
      conference/urls.py
  2. 4
      exposition/urls.py
  3. 4
      place_exposition/urls.py
  4. 65
      proj/middleware.py
  5. 1
      settings/old_urls.py
  6. 1
      support/dev/settings.py
  7. 2
      support/prod/settings.py

@ -35,7 +35,7 @@ urlpatterns = patterns('',
url(r'^conference/country/(?P<slug>[^/]*)/page/(?P<page>\d+)/$', ConferenceCountryCatalog.as_view(), {'meta_id':23}),
url(r'^conference/country/(?P<slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/$', ConferenceCountryCatalog.as_view(), {'meta_id':25}),
url(r'^conference/country/(?P<slug>[^/]*)/(?P<year>\d+)/$', ConferenceCountryCatalog.as_view(), {'meta_id':24}),
url(r'^conference/country/(?P<slug>[^/]*)/$', ConferenceCountryCatalog.as_view(), {'meta_id':23}),
url(r'^conference/country/(?P<slug>[^/]*)/$', ConferenceCountryCatalog.as_view(), {'meta_id':23}, name='conf_country'),
# city catalog
url(r'^conference/city/$', ConferenceByCity.as_view(), {'meta_id':52}),
url(r'^conference/city/(?P<slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/page/(?P<page>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':28}),
@ -43,7 +43,7 @@ urlpatterns = patterns('',
url(r'^conference/city/(?P<slug>[^/]*)/page/(?P<page>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':26}),
url(r'^conference/city/(?P<slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/$', ConferenceCityCatalog.as_view(), {'meta_id':28}),
url(r'^conference/city/(?P<slug>[^/]*)/(?P<year>\d+)/$', ConferenceCityCatalog.as_view(), {'meta_id':27}),
url(r'^conference/city/(?P<slug>[^/]*)/$', ConferenceCityCatalog.as_view(), {'meta_id':26}),
url(r'^conference/city/(?P<slug>[^/]*)/$', ConferenceCityCatalog.as_view(), {'meta_id':26}, name='conf_city'),
# theme catalog
url(r'^conference/theme/$', ConferenceByTheme.as_view(), {'meta_id':50}),
url(r'^conference/theme/(?P<slug>[^/]*)/country/(?P<country_slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/page/(?P<page>\d+)/$', ConferenceThemeCatalog.as_view()),

@ -37,7 +37,7 @@ urlpatterns = patterns('',
url(r'^expo/country/(?P<slug>[^/]*)/page/(?P<page>\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}),
url(r'^expo/country/(?P<slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/$', ExpoCountryCatalog.as_view(), {'meta_id':7}),
url(r'^expo/country/(?P<slug>[^/]*)/(?P<year>\d+)/$', ExpoCountryCatalog.as_view(), {'meta_id':6}),
url(r'^expo/country/(?P<slug>[^/]*)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}),
url(r'^expo/country/(?P<slug>[^/]*)/$', ExpoCountryCatalog.as_view(), {'meta_id':5}, name='expo_country'),
# city catalog
url(r'^expo/city/$', ExpositionByCity.as_view(), {'meta_id':53}),
url(r'^expo/city/(?P<slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/page/(?P<page>\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':10}),
@ -45,7 +45,7 @@ urlpatterns = patterns('',
url(r'^expo/city/(?P<slug>[^/]*)/page/(?P<page>\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':8}),
url(r'^expo/city/(?P<slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/$', ExpoCityCatalog.as_view(), {'meta_id':10}),
url(r'^expo/city/(?P<slug>[^/]*)/(?P<year>\d+)/$', ExpoCityCatalog.as_view(), {'meta_id':9}),
url(r'^expo/city/(?P<slug>[^/]*)/$', ExpoCityCatalog.as_view(), {'meta_id':8}),
url(r'^expo/city/(?P<slug>[^/]*)/$', ExpoCityCatalog.as_view(), {'meta_id':8}, name='expo_city'),
# theme catalog
url(r'^expo/theme/$', ExpositionByTheme.as_view(), {'meta_id':55}),
url(r'^expo/theme/(?P<slug>[^/]*)/country/(?P<country_slug>[^/]*)/(?P<year>\d+)/(?P<month>[^/]*)/page/(?P<page>\d+)/$', ExpoThemeCatalog.as_view(), {'meta_id':44}),

@ -15,11 +15,11 @@ urlpatterns = patterns('',
url(r'^country/$', PlaceByCountry.as_view(), {'meta_id': 49}),
url(r'^country/(?P<slug>.*)/page/(?P<page>\d+)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}),
url(r'^country/(?P<slug>.*)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}),
url(r'^country/(?P<slug>.*)/$', PlaceCountryCatalog.as_view(), {'meta_id': 49}, name='place_country'),
url(r'^city/$', PlaceByCity.as_view(), {'meta_id': 48}),
url(r'^city/(?P<slug>.*)/page/(?P<page>\d+)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}),
url(r'^city/(?P<slug>.*)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}),
url(r'^city/(?P<slug>.*)/$', PlaceCityCatalog.as_view(), {'meta_id': 48}, name='place_city'),
url(r'^(?P<slug>.*)/photo/page/(?P<page>\d+)/$', PlacePhoto.as_view(), {'meta_id': 91}),
url(r'^(?P<slug>.*)/photo/$', PlacePhoto.as_view(), {'meta_id': 91}),

@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
# from django.contrib.redirects.middleware import RedirectFallbackMiddleware
import re
from django.http import HttpResponsePermanentRedirect
from django.core.urlresolvers import reverse
from exposition.models import Exposition
from country.models import Country
from city.models import City
class RedirectFallbackMiddleware(object):
def process_response(self, request, response):
if response.status_code != 404:
return response # No need to check for a redirect for non-404 responses.
full_path = request.get_full_path()
redirects = [
(r'^/(?P<event_type>expo|conference)/(?P<slug>[^/]*)/$', check_events),
(r'^/places/(?P<slug>[^/]*)/$', check_places),
]
for regex, handler in redirects:
check = re.compile(regex)
match = check.match(full_path)
if match:
response = handler(**match.groupdict())
if response is not None:
return response
return response
def check_events(event_type, slug):
'''
Event redirects (ticket 1498: Внепланово со скайпа - редиректы 301)
https://expomap.ru/expo/dusseldorf/ -> https://expomap.ru/expo/city/dusseldorf/
https://expomap.ru/expo/moscow/ -> https://expomap.ru/expo/country/moscow/
https://expomap.ru/conference/berlin/ -> https://expomap.ru/conference/city/berlin/
https://expomap.ru/conference/moscow/ -> https://expomap.ru/conference/country/moscow/
'''
types = {
'expo': 'expo',
'conference': 'conf'
}
if City.objects.filter(url=slug).exists():
return HttpResponsePermanentRedirect(reverse(types.get(event_type) + '_city', kwargs={'slug': slug}))
if Country.objects.filter(url=slug).exists():
return HttpResponsePermanentRedirect(reverse(types.get(event_type) + '_country', kwargs={'slug': slug}))
return None
def check_places(slug):
"""
Правила для старых ошибок (ticket 1498: Внепланово со скайпа - редиректы 301)
https://expomap.ru/places/russia/ -> https://expomap.ru/places/country/russia/
https://expomap.ru/places/moscow/ -> https://expomap.ru/places/city/moscow/
- где пропущен параметр city и country - тоже автоматической склейки по 301
"""
if City.objects.filter(url=slug).exists():
return HttpResponsePermanentRedirect(reverse('place_city', kwargs={'slug': slug}))
if Country.objects.filter(url=slug).exists():
return HttpResponsePermanentRedirect(reverse('place_country', kwargs={'slug': slug}))
return None

@ -39,6 +39,7 @@ urlpatterns = patterns('',
url(r'^newsp.php/news_id/(?P<news_p>\d+)/(?P<some>.*)$', old_redirect, {'redirect_url': '/news/{news_p}/'}),
# users
url(r'^users/(?P<user>.*)$', old_redirect, {'redirect_url': '/{user}/'}),
url(r'^user/(?P<user>.*)$', old_redirect, {'redirect_url': '/{user}/'}),
url(r'^account_edit.php$', old_profile),
url(r'^myexpo.php$', old_redirect, {'redirect_url': '/profile/calendar/'}),
url(r'^newsletter2.php?email=(?P<some>.*)$', old_redirect, {'redirect_url': '/profile/settings/'}),

@ -153,6 +153,7 @@ MIDDLEWARE_CLASSES = (
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'proj.middleware.RedirectFallbackMiddleware',
)

@ -153,7 +153,7 @@ MIDDLEWARE_CLASSES = (
# Uncomment the next line for simple clickjacking protection:
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'proj.middleware.RedirectFallbackMiddleware',
)

Loading…
Cancel
Save