Skip to content

Commit

Permalink
#140 Clone redirects app (#141)
Browse files Browse the repository at this point in the history
- Inherit redirects app from django's one
- Fix redirects mutlideps
- Fix middleware name
  • Loading branch information
duker33 authored Jul 3, 2018
2 parents 897f2bb + 8f6e230 commit 0356ee6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions refarm_redirects/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'refarm_redirects.apps.RedirectsConfig'
7 changes: 7 additions & 0 deletions refarm_redirects/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class RedirectsConfig(AppConfig):
name = 'refarm_redirects'
verbose_name = _('refarm_redirects')
36 changes: 36 additions & 0 deletions refarm_redirects/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from django.conf import settings
from django.contrib.redirects.models import Redirect
from django.contrib.redirects.middleware \
import RedirectFallbackMiddleware \
as DjangoRedirectFallbackMiddleware
from django.contrib.sites.shortcuts import get_current_site


class RedirectAllMiddleware(DjangoRedirectFallbackMiddleware):
# reloaded this method
# just to drop `response.status_code` status check
# in base class
def process_response(self, request, response):
full_path = request.get_full_path()
current_site = get_current_site(request)

r = None
try:
r = Redirect.objects.get(site=current_site, old_path=full_path)
except Redirect.DoesNotExist:
pass
if r is None and settings.APPEND_SLASH and not request.path.endswith('/'):
try:
r = Redirect.objects.get(
site=current_site,
old_path=request.get_full_path(force_append_slash=True),
)
except Redirect.DoesNotExist:
pass
if r is not None:
if r.new_path == '':
return self.response_gone_class()
return self.response_redirect_class(r.new_path)

# No redirect was found. Return the response.
return response
Empty file.
2 changes: 2 additions & 0 deletions tests/refarm_redirects/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# @todo:30m Move test case to custom redirects app
# You can find example at SE's tests_views.Redirects app
6 changes: 6 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'refarm_redirects.middleware.RedirectAllMiddleware',
)

# @todo #140:60m Use `refarm-site's` packages with it's prefix.
# For example do `INSTALLED_APPS = ['refarm-site.pages', ...]`
# instead of just `['pages']`.

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
Expand All @@ -76,6 +81,7 @@
'ecommerce',
'pages',
'search',
'refarm_redirects',
'generic_admin',
'tests',
)
Expand Down

1 comment on commit 0356ee6

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 0356ee6 Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site && pdd -v -f /tmp/20180703-27789-rgh0ns [1]: bash: warning: setlocale: LC_ALL: cannot change locale (UTF-8) + set -e + set -o pipefail + cd /tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site + pdd -v -f...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site && pdd -v -f /tmp/20180703-27789-rgh0ns [1]:
bash: warning: setlocale: LC_ALL: cannot change locale (UTF-8)
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site
+ pdd -v -f /tmp/20180703-27789-rgh0ns

My version is 0.20.3
Ruby version is 2.3.3 at x86_64-linux
Reading /tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site
212 file(s) found, 56 excluded
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/pages/templatetags/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/pages/management/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/pages/management/commands/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/pages/migrations/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/search/migrations/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/search/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/images/templatetags/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/images/migrations/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/ecommerce/img/02.png is a binary file (32719 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/ecommerce/img/01.png is a binary file (247355 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/ecommerce/migrations/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/ecommerce/__init__.py is a binary file (1 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/pages/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/search/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/images/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/images/assets/gold.jpg is a binary file (45940 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/images/assets/deer.jpg is a binary file (19044 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/ecommerce/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/management/commands/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/fixtures/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/migrations/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/catalog/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/generic_admin/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/tests/refarm_redirects/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/catalog/templatetags/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/catalog/migrations/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/catalog/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/catalog/views/__init__.py is a binary file (0 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-icons_cc0000_256x240.png is a binary file (3262 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/jstree/32px.png is a binary file (1562 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/jstree/throbber.gif is a binary file (1720 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/jstree/40px.png is a binary file (5717 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-icons_444444_256x240.png is a binary file (3266 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-icons_555555_256x240.png is a binary file (3274 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-icons_777620_256x240.png is a binary file (3262 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-bg_flat_0_aaaaaa_40x100.png is a binary file (86 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-icons_ffffff_256x240.png is a binary file (3264 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/ui-icons_777777_256x240.png is a binary file (3266 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/front/images/loading.gif is a binary file (1787 bytes)
/tmp/0pdd20180703-4-1pbrzyv/fidals/refarm-site/generic_admin/__init__.py is a binary file (0 bytes)
Reading .gitignore...
Reading pages/urls.py...
Puzzle 343-7b06e173 30/DEV at pages/urls.py
Reading pages/views.py...
Reading pages/templatetags/pages_extras.py...
Reading pages/management/commands/get_app_path_for_gulp.py...
Reading pages/management/commands/custom_pages.py...
Reading pages/apps.py...
Reading pages/templates/pages/breadcrumbs.html...
Reading pages/templates/pages/page.html...
Reading pages/templates/pages/sitemap.html...
Reading pages/templates/pages/accordion.html...
Reading pages/templates/pages/breadcrumbs_with_siblings.html...
Reading pages/templates/robots.txt...
Reading pages/templates/index/index.html...
Reading pages/migrations/0013_auto_20170317_1457.py...
Reading pages/migrations/0005_db_refactor.py...
Reading pages/migrations/0006_remove_redundant_fields.py...
Reading pages/migrations/0015_add_validation_to_template.py...
Reading pages/migrations/0012_auto_20170301_0020.py...
Reading pages/migrations/0003_auto_20160909_0747.py...
Reading pages/migrations/0008_add_db_index.py...
Reading pages/migrations/0007_rename_private_field.py...
Reading pages/migrations/0001_initial.py...
Reading pages/migrations/0009_pages_mptt.py...
Reading pages/migrations/0002_auto_20160829_1730.py...
Reading pages/migrations/0014_auto_20170504_0944.py...
Reading pages/migrations/0010_rebuild_pages_tree.py...
Reading pages/migrations/0011_title_to_text_field.py...
Reading pages/migrations/0004_auto_20160909_1100.py...
Reading pages/__init__.py...
Reading pages/utils.py...
Reading pages/README.md...
Reading pages/models.py...
Reading search/urls.py...
Reading search/views.py...
Puzzle 85-5b8190cf 0/DEV at search/views.py
Reading search/apps.py...
Reading search/templates/search/results.html...
Reading search/templates/search/no_results.html...
Reading search/migrations/0001_trigram_search.py...
Reading search/search.py...
Reading LICENSE...
Reading images/templatetags/images.py...
Reading images/apps.py...
Reading images/migrations/0004_auto_20170124_1444.py...
Reading images/migrations/0006_auto_20170418_1615.py...
Reading images/migrations/0003_auto_20161027_0940.py...
Reading images/migrations/0005_auto_20170317_1457.py...
Reading images/migrations/0002_alter_fields.py...
Reading images/migrations/0001_initial.py...
Reading images/__init__.py...
Reading images/models.py...
Reading docker/docker-compose.yml...
Reading docker/.env.dist...
Reading docker/Dockerfile.python...
Reading ecommerce/urls.py...
Reading ecommerce/front/paths.js...
Reading ecommerce/front/backcall.es6...
Reading ecommerce/front/trackers.es6...
Puzzle 292-ba927d60 0/DEV at ecommerce/front/trackers.es6
Reading ecommerce/views.py...
Reading ecommerce/mailer.py...
Reading ecommerce/apps.py...
Reading ecommerce/templates/ecommerce/order/backcall_modal.html...
Reading ecommerce/templates/ecommerce/order/order.html...
Reading ecommerce/templates/ecommerce/order/table_form.html...
Reading ecommerce/templates/ecommerce/order/backcall_email.html...
Reading ecommerce/templates/ecommerce/order/success.html...
Reading ecommerce/templates/ecommerce/order/email.html...
Reading ecommerce/templates/ecommerce/header_cart.html...
Reading ecommerce/migrations/0003_position_vendor_code.py...
Reading ecommerce/migrations/0002_auto_20161123_0936.py...
Reading ecommerce/migrations/0001_initial.py...
Reading ecommerce/context_processors.py...
Reading ecommerce/tasks.py...
Reading ecommerce/README.md...
Reading ecommerce/models.py...
Reading ecommerce/cart.py...
Reading ecommerce/admin.py...
Reading ecommerce/forms.py...
Reading tests/urls.py...
Reading tests/pages/test_models.py...
Reading tests/pages/urls.py...
Reading tests/pages/test_views.py...
Reading tests/search/test_models.py...
Reading tests/search/urls.py...
Reading tests/search/views.py...
Reading tests/search/test_views.py...
Puzzle 85-01b685cc 0/DEV at tests/search/test_views.py
Reading tests/images/tests.py...
Reading tests/ecommerce/tests_models.py...
Reading tests/ecommerce/tests_forms.py...
Reading tests/ecommerce/urls.py...
Reading tests/ecommerce/views.py...
Reading tests/ecommerce/tests_views.py...
Reading tests/ecommerce/tests_cart.py...
Reading tests/ecommerce/tests_mailer.py...
Reading tests/ecommerce/models.py...
Reading tests/static/logo.svg...
Reading tests/management/commands/create_fixtures.py...
Reading tests/fixtures/search.json...
Reading tests/migrations/0001_initial.py...
Reading tests/test_settings.py...
Puzzle 140-e3f06142 60/DEV at tests/test_settings.py
Reading tests/catalog/test_models.py...
Reading tests/catalog/urls.py...
Reading tests/catalog/views.py...
Reading tests/catalog/models.py...
Reading tests/catalog/test_views.py...
Reading tests/generic_admin/urls.py...
Reading tests/generic_admin/test_admin_models.py...
Reading tests/generic_admin/test_views.py...
Reading tests/models.py...
Reading tests/refarm_redirects/test_views.py...
ERROR: tests/refarm_redirects/test_views.py; puzzle at line #1; @todo found, but puzzle can't be parsed, most probably because @todo is not followed by a puzzle marker, as this page explains: https://github.com/yegor256/pdd#how-to-format. If you can't understand the cause of this issue or you don't know how to fix it, please submit a GitHub issue, we will try to help you: https://github.com/yegor256/pdd/issues. This tool is still in its beta version and we will appreciate your feedback. Here is where you can find more documentation: https://github.com/yegor256/pdd/blob/master/README.md.
Exit code is 1

/app/objects/git_repo.rb:66:in `rescue in block in xml'
/app/objects/git_repo.rb:63:in `block in xml'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/tempfile.rb:295:in `open'
/app/objects/git_repo.rb:62:in `xml'
/app/objects/puzzles.rb:36:in `deploy'
/app/objects/job.rb:38:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:48:in `exclusive'
/app/objects/job_detached.rb:36:in `block in proceed'
/app/objects/job_detached.rb:36:in `fork'
/app/objects/job_detached.rb:36:in `proceed'
/app/0pdd.rb:342:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1634:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1634:in `block in compile!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:992:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1011:in `route_eval'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:992:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1039:in `block in process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1037:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1037:in `process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:990:in `block in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:989:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:989:in `route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1096:in `block in dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1093:in `dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:924:in `block in call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1075:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:924:in `call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:913:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.1/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.1/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.1/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.1/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.1/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.1/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/common_logger.rb:33:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:231:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:194:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1957:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1501:in `block in call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1728:in `synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.1/lib/sinatra/base.rb:1501:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.5/lib/rack/handler/webrick.rb:86:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Please sign in to comment.