Browse files

Merge pull request #3323 from mozilla/bug1177264

Remove dumb_wiki_urls flag and simplify wiki_url helper.
  • Loading branch information...
jezdez committed Jul 7, 2015
2 parents 8f4e96d + 96e85d8 commit a9ae8306ac83260f5dc005b3a774c266eba28c4d
@@ -18,7 +18,7 @@
{% for revision in revisions %}
{% set previous_id = revision.get_previous().id %}
{% set revision_url = url('wiki.document', revision.document.slug, locale=revision.document.locale) %}
{% set revision_url = revision.document.get_absolute_url() %}
class="dashboard-row {% if not previous_id %}dashboard-row-new{% endif %}"
@@ -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 import Revision
from import wiki_url
from .helpers import gravatar_url
from .jobs import UserGravatarURLJob
@@ -236,8 +236,9 @@ def invalidate_gravatar_url(sender, instance, created, **kwargs):
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
@@ -10,19 +10,16 @@
from tidylib import tidy_document
from tower import ugettext as _
from django.conf import settings
from django.contrib.sites.models import Site
from django.core.serializers.json import DjangoJSONEncoder
from django.utils.html import conditional_escape
from constance import config
from jingo import register
import waffle
from kuma.core.urlresolvers import reverse
from .constants import DIFF_WRAP_COLUMN
from .jobs import DocumentZoneStackJob
from .models import Document, memcache
def compare_url(doc, from_id, to_id):
@@ -316,49 +313,9 @@ def absolutify(url, site=None):
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'
# 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,
# 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()
# use the redirect URL instead
url = redirect_url
except Document.DoesNotExist:
# otherwise use the already defined url to the English document
# 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])
@@ -1515,11 +1515,6 @@ def zone_stack(self):
return DocumentZoneStackJob().get(
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.
@@ -10,7 +10,7 @@
<article id="compare-revisions">
<h1>{{ _('Compare Revisions') }}</h1>
<h2><a href="{{ url('wiki.document', document.slug, locale=document.locale) }}">{{ document.title }}</a></h2>
<h2><a href="{{ document.get_absolute_url() }}">{{ document.title }}</a></h2>
{{ revision_diff(revision_from, revision_to) }}
@@ -36,7 +36,7 @@ <h1>{{ _('Delete') }} <a href="{{ document.get_absolute_url() }}">{{ document.ti
<p>{{ _('Are you sure you want to continue?') }}</p>
<input type="submit" value="{{ _('Delete') }}" />
<a href="{{ url('wiki.document', document.slug) }}">{{ _('Cancel') }}</a>
<a href="{{ document.get_absolute_url() }}">{{ _('Cancel') }}</a>
@@ -2,7 +2,7 @@
<nav class="crumbs" role="navigation"><ol xmlns:v="" aria-label="{{ _('breadcrumbs') }}">
<li typeof="v:Breadcrumb"><a href="/{{ request.locale }}" rel="v:url" property="v:title">MDN</a></li>
{% for doc in document.parents %}
<li class="crumb" typeof="v:Breadcrumb"><a href="{{ url('wiki.document', doc.slug) }}" rel="v:url" property="v:title">{{ doc.title }}</a></li>
<li class="crumb" typeof="v:Breadcrumb"><a href="{{ doc.get_absolute_url() }}" rel="v:url" property="v:title">{{ doc.title }}</a></li>
{% endfor %}
<li class="crumb" typeof="v:Breadcrumb" property="v:title">{{ document.title }}</li>
@@ -65,7 +65,7 @@ <h1>{{ _('<span class="title-prefix">Moving</span> <em>{title}</em>')|fe(title=d
<dt>{{ _('Preview URL:') }}</dt>
<dd id="preview-url" data-url="{{ settings.SITE_URL }}/{{ document.locale }}/docs/" data-specific="{{ specific_slug }}">
{{ request.build_absolute_uri(url('wiki.document', document.slug)) }}
{{ request.build_absolute_uri(document.get_absolute_url()) }}

0 comments on commit a9ae830

Please sign in to comment.