Repository: fidals/shopelectro

Issue:
починить sitemap.xml
Сейчас он выдает 500 ошибку


Discussion:
Stacktrace:
```python
Internal Server Error: /sitemap.xml
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 39, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/views.py", line 16, in inner
    response = func(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/views.py", line 68, in sitemap
    protocol=req_protocol))
  File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/__init__.py", line 105, in get_urls
    urls = self._urls(page, protocol, domain)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/__init__.py", line 114, in _urls
    loc = "%s://%s%s" % (protocol, domain, self.__get('location', item))
  File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/__init__.py", line 62, in __get
    return attr(obj)
  File "/usr/local/lib/python3.6/site-packages/django/contrib/sitemaps/__init__.py", line 69, in location
    return obj.get_absolute_url()
  File "/usr/local/lib/python3.6/site-packages/pages/models.py", line 175, in get_absolute_url
    return reverse(Page.CUSTOM_PAGES_URL_NAME, args=(self.slug, ))
  File "/usr/local/lib/python3.6/site-packages/django/urls/base.py", line 91, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 389, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns)
django.urls.exceptions.NoReverseMatch: Reverse for 'custom_page' with arguments '('robots',)' and keyword arguments '{}' not found. 7 pattern(s) tried: ['(?P<page>sitemap)/$', 'shop/(?P<page>order-success)/$', 'shop/(?P<page>order)/$', '(?P<page>catalog)/$', '(?P<page>search)/$', 'robots\\.txt/$', '(?P<page>)$']
```

Resolving patch:
diff --git a/shopelectro/migrations/0024_update_robots_slug.py b/shopelectro/migrations/0024_update_robots_slug.py
new file mode 100644
--- /dev/null
+++ b/shopelectro/migrations/0024_update_robots_slug.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10 on 2018-07-10 01:38
+from __future__ import unicode_literals
+
+from django.db import migrations
+from pages.models import CustomPage
+
+
+def migrate_forward(apps, schema_editor):
+    robots = CustomPage.objects.filter(slug='robots').first()
+    if robots:
+        robots.slug = 'robots.txt'
+        robots.save()
+
+
+def migrate_backward(apps, schema_editor):
+    robots = CustomPage.objects.filter(slug='robots.txt').first()
+    if robots:
+        robots.slug = 'robots'
+        robots.save()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('shopelectro', '0023_excludedmodeltpage'),
+    ]
+
+    operations = [
+        migrations.RunPython(migrate_forward, migrate_backward),
+    ]
diff --git a/shopelectro/settings/base.py b/shopelectro/settings/base.py
--- a/shopelectro/settings/base.py
+++ b/shopelectro/settings/base.py
@@ -353,7 +353,7 @@ def get_robots_content():
         'name': 'Заказ принят',
     },
     'robots': {
-        'slug': 'robots',
+        'slug': 'robots.txt',
         'content': get_robots_content(),
     },
 }
diff --git a/shopelectro/urls.py b/shopelectro/urls.py
--- a/shopelectro/urls.py
+++ b/shopelectro/urls.py
@@ -92,7 +92,7 @@ def cache_page(arg):  # Ignore PyFlakesBear
 
 custom_pages = [
     custom_page_url(r'^(?P<page>)$', cached_2h(views.IndexPage.as_view())),
-    custom_page_url(r'^robots\.txt/$', RobotsView.as_view(in_db=True)),
+    custom_page_url(r'^(?P<page>robots\.txt)/$', RobotsView.as_view(in_db=True)),
     custom_page_url(r'^(?P<page>search)/$', views.Search.as_view()),
     custom_page_url(r'^(?P<page>catalog)/$', cached_2h(views.CategoryTree.as_view())),
     custom_page_url(r'^shop/(?P<page>order)/$', views.OrderPage.as_view()),


Test patch: