Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show URLS for exact redirect #3593

Merged
merged 5 commits into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions readthedocs/redirects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,30 @@ class Meta(object):
ordering = ('-update_dt',)

def __str__(self):
if self.redirect_type == 'prefix':
return ugettext('Prefix Redirect:') + ' %s ->' % self.from_url
elif self.redirect_type == 'page':
return ugettext('Page Redirect:') + ' %s -> %s' % (
self.from_url,
self.to_url)
return ugettext('Redirect: %s' % self.get_redirect_type_display())
redirect_text = '{type}: {from_to_url}'
if self.redirect_type in ['prefix', 'page', 'exact']:
return redirect_text.format(
type=self.get_redirect_type_display(),
from_to_url=self.get_from_to_url_display()
)
return ugettext('Redirect: {}'.format(
self.get_redirect_type_display())
)

def get_from_to_url_display(self):
if self.redirect_type in ['prefix', 'page', 'exact']:
from_url = self.from_url
to_url = self.to_url
if self.redirect_type == 'prefix':
to_url = '/{lang}/{version}/'.format(
lang=self.project.language,
version=self.project.default_version
)
return '{from_url} -> {to_url}'.format(
from_url=from_url,
to_url=to_url
)
return ''

def get_full_path(self, filename, language=None, version_slug=None):
"""
Expand Down
11 changes: 8 additions & 3 deletions readthedocs/templates/projects/project_redirects.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ <h3>{% trans "Redirects" %}</h3>
<ul>
{% for redirect in redirects %}
<li class="module-item">
<span>
{{ redirect }}
</span>
<div>
{{ redirect.get_redirect_type_display }}
</div>
{% if redirect.get_from_to_url_display %}
<div>
{{ redirect.get_from_to_url_display }}
</div>
{% endif %}
<ul class="module-item-menu">
<li>
<form method="post" action="{% url "projects_redirects_delete" project.slug %}">
Expand Down