Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Bug 1177264 - Simplify wiki_url template helper.
Browse files Browse the repository at this point in the history
This also removes the dumb_wiki_urls waffle flag introduced in 81a1b5f.
  • Loading branch information
jezdez committed Jul 7, 2015
1 parent c9604f1 commit 54f08b1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 50 deletions.
7 changes: 4 additions & 3 deletions kuma/users/models.py
Expand Up @@ -18,8 +18,8 @@
from kuma.core.fields import LocaleField, JSONField
from kuma.core.managers import NamespacedTaggableManager
from kuma.core.models import ModelBase
from kuma.core.urlresolvers import reverse
from kuma.wiki.models import Revision
from kuma.wiki.helpers import wiki_url

from .helpers import gravatar_url
from .jobs import UserGravatarURLJob
Expand Down Expand Up @@ -236,8 +236,9 @@ def invalidate_gravatar_url(sender, instance, created, **kwargs):

@receiver(user_signed_up)
def on_user_signed_up(sender, request, user, **kwargs):
context = {'request': request}
msg = _('You have completed the first step of <a href="%s">getting started with MDN</a>') % wiki_url(context, 'MDN/Getting_started')
url = reverse('wiki.document', args=['MDN/Getting_started'])
msg = _('You have completed the first step of '
'<a href="%s">getting started with MDN</a>') % url
messages.success(request, msg)
if switch_is_active('welcome_email'):
# only send if the user has already verified at least one email address
Expand Down
44 changes: 2 additions & 42 deletions kuma/wiki/helpers.py
Expand Up @@ -316,49 +316,9 @@ def absolutify(url, site=None):


@register.function
@jinja2.contextfunction
def wiki_url(context, path):
def wiki_url(path):
"""
Create a URL pointing to Kuma.
Look for a wiki page in the current locale, or default to given path
"""
request = context['request']
if waffle.flag_is_active(request, 'dumb_wiki_urls'):
return reverse('wiki.document', args=[path])

default_locale = settings.WIKI_DEFAULT_LANGUAGE
locale = getattr(request, 'locale', default_locale)

# let's first check if the cache is already filled
url = memcache.get(u'wiki_url:%s:%s' % (locale, path))
if url:
# and return the URL right away if yes
return url

# shortcut for when the current locale is the default one (English)
url = reverse('wiki.document', locale=default_locale, args=[path])

if locale != default_locale:
# in case the current request's locale is *not* the default, e.g. 'de'
try:
# check if there are any translated documents in the request's
# locale of a document with the given path and the default locale
translation = Document.objects.get(locale=locale,
parent__slug=path,
parent__locale=default_locale)

# look if the document is actual just a redirect
redirect_url = translation.redirect_url()
if redirect_url is None:
# if no, build the URL of the translation
url = translation.get_absolute_url()
else:
# use the redirect URL instead
url = redirect_url
except Document.DoesNotExist:
# otherwise use the already defined url to the English document
pass

# finally cache the reversed document URL for a bit
memcache.set(u'wiki_url:%s:%s' % (locale, path), url, 60 * 5)
return url
return reverse('wiki.document', args=[path])
5 changes: 0 additions & 5 deletions kuma/wiki/models.py
Expand Up @@ -1515,11 +1515,6 @@ def zone_stack(self):
return DocumentZoneStackJob().get(self.pk)


@receiver(render_done)
def purge_wiki_url_cache(sender, instance, **kwargs):
memcache.delete(u'wiki_url:%s:%s' % (instance.locale, instance.slug))


class DocumentDeletionLog(models.Model):
"""
Log of who deleted a Document, when, and why.
Expand Down

0 comments on commit 54f08b1

Please sign in to comment.