This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug 877679 - added a document navigator stored in localStorage fo…
…r MDN search traffic
- Loading branch information
Showing
24 changed files
with
620 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from rest_framework.renderers import TemplateHTMLRenderer | ||
|
||
from .store import ref_from_request | ||
|
||
|
||
class ExtendedTemplateHTMLRenderer(TemplateHTMLRenderer): | ||
template_name = 'search/results.html' | ||
|
||
def resolve_context(self, data, request, response): | ||
""" | ||
Adds some more data to the template context. | ||
""" | ||
data['search_ref'] = ref_from_request(request) | ||
return super(ExtendedTemplateHTMLRenderer, | ||
self).resolve_context(data, request, response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import hashlib | ||
|
||
from urlobject import URLObject as URL | ||
|
||
from django.conf import settings | ||
from django.utils import translation | ||
|
||
from sumo.urlresolvers import reverse | ||
|
||
QUERY_PARAM = 'q' | ||
PAGE_PARAM = 'page' | ||
TOPICS_PARAM = 'topic' | ||
|
||
|
||
def ref_from_referer(request): | ||
referrer = request.META.get('HTTP_REFERER', None) | ||
if (referrer is None or | ||
reverse('search', locale=request.locale) != URL(referrer).path): | ||
return None | ||
return ref_from_url(referrer) | ||
|
||
|
||
def ref_from_request(request): | ||
return ref_from_url(request.build_absolute_uri()) | ||
|
||
|
||
def ref_from_url(url): | ||
url = URL(url) | ||
query = url.query.dict.get(QUERY_PARAM, '') | ||
page = url.query.dict.get(PAGE_PARAM, 1) | ||
topics = url.query.multi_dict.get(TOPICS_PARAM, []) | ||
locale = translation.get_language() | ||
|
||
md5 = hashlib.md5() | ||
for value in [query, page, locale] + topics: | ||
md5.update(unicode(value)) | ||
|
||
return md5.hexdigest()[:16] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.