Skip to content

Commit

Permalink
Merge pull request #3593 from stsewd/redirect-repr
Browse files Browse the repository at this point in the history
Show URLS for exact redirect
  • Loading branch information
ericholscher authored Apr 18, 2018
2 parents 3934c35 + a0790e4 commit d270a67
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
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

0 comments on commit d270a67

Please sign in to comment.