Skip to content

Commit

Permalink
Fixed the issues from Dave and Paul's comments; refactored Jeff's poi…
Browse files Browse the repository at this point in the history
…nt about the duplicate code.
  • Loading branch information
James Socol committed Apr 2, 2010
1 parent d03b6f8 commit a0ba1c3
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 45 deletions.
6 changes: 3 additions & 3 deletions apps/search/templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<a class="show-search-tabs" href="{{ url('search') }}{{ refine_query }}">{{ _("Refine your search") }}</a>
</div>

{% if spellcheck(q, search_form.language.data or locale) %}
<div class="search-suggestion">{{ _('Did you mean: {0}')|f(q|suggestions(search_form.language.data or locale))|safe }}</div>
{% if spellcheck(q, search_form.language.data or request.locale) %}
<div class="search-suggestion">{{ _('Did you mean: {0}')|f(q|suggestions(search_form.language.data or request.locale))|safe }}</div>
{% endif %}

<div class="search-count">
Expand Down Expand Up @@ -47,5 +47,5 @@

</div>

<p>{{ _("Can't find what you're looking for?") }} <a href="/{{ locale }}/kb/Ask+a+question">{{ _('Ask a support question instead!') }}</a></p>
<p>{{ _("Can't find what you're looking for?") }} <a href="/{# TODO: Use url() #}{{ request.locale }}/kb/Ask+a+question">{{ _('Ask a support question instead!') }}</a></p>
{% endblock %}
41 changes: 14 additions & 27 deletions apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ def search(request):
# => return empty form
if (not q or (request.GET.get('a', '0') == '1')):
return jingo.render(request, 'form.html',
{'locale': request.locale,
'advanced': request.GET.get('a'),
'request': request,
'w': where, 'search_form': search_form,
})
{'advanced': request.GET.get('a'), 'request': request,
'w': where, 'search_form': search_form})

# get language name for display in template
if settings.LANGUAGES.get(language):
Expand All @@ -71,9 +68,8 @@ def search(request):
documents = []

if (where & constants.WHERE_WIKI):
wc = WikiClient() # Wiki SearchClient instance
filters_w = [] # filters for the wiki search

wc = WikiClient() # Wiki SearchClient instance
filters_w = [] # Filters for the wiki search

# Category filter
categories = search_params.getlist('category')
Expand All @@ -82,14 +78,12 @@ def search(request):
'value': map(int, categories),
})


# Locale filter
filters_w.append({
'filter': 'locale',
'value': search_locale,
})


# Tag filter
tag = [t.strip() for t in request.GET.get('tag', '').split()]
if tag:
Expand All @@ -100,13 +94,12 @@ def search(request):
'value': (t,),
})


# execute the query and append to documents
# Execute the query and append to documents
documents += wc.query(q, filters_w)

if (where & constants.WHERE_FORUM):
fc = ForumClient() # Forum SearchClient instance
filters_f = [] # filters for the forum search
fc = ForumClient() # Forum SearchClient instance
filters_f = [] # Filters for the forum search

# Forum filter
filters_f.append({
Expand All @@ -116,14 +109,14 @@ def search(request):

# Status filter
status = int(request.GET.get('status', 0))
# no replies case is not stored in status
# No replies case is not stored in status
if status == constants.STATUS_ALIAS_NR:
filters_f.append({
'filter': 'replies',
'value': (0,),
})

# avoid filtering by status
# Avoid filtering by status
status = None

if status:
Expand All @@ -146,7 +139,7 @@ def search(request):
created_date = request.GET.get('created_date', '')

if not created_date:
# no date => no filtering
# No date => no filtering
created = None
else:
try:
Expand All @@ -156,15 +149,13 @@ def search(request):
except ValueError:
created = None


if created == constants.CREATED_BEFORE:
filters_f.append({
'range': True,
'filter': 'created',
'min': 0,
'max': created_date,
})

elif created == constants.CREATED_AFTER:
filters_f.append({
'range': True,
Expand All @@ -173,7 +164,6 @@ def search(request):
'max': int(unix_now),
})


# Last modified filter
lastmodif = int(request.GET.get('lastmodif', 0))

Expand Down Expand Up @@ -252,19 +242,16 @@ def search(request):

return response


return jingo.render(request, 'results.html',
{'num_results': len(documents), 'results': results, 'q': q,
'locale': request.locale, 'pages': pages,
'w': where, 'refine_query': refine_query,
'search_form': search_form,
'lang_name': lang_name, })
'pages': pages, 'w': where, 'refine_query': refine_query,
'search_form': search_form, 'lang_name': lang_name, })


class SearchForm(forms.Form):
q = forms.CharField()

# kb form data
# KB form data
tag = forms.CharField(label=_('Tags'))

language = forms.ChoiceField(label=_('Language'),
Expand All @@ -277,7 +264,7 @@ class SearchForm(forms.Form):
widget=forms.CheckboxSelectMultiple,
label=_('Category'), choices=categories)

# forum form data
# Forum form data
status = forms.ChoiceField(label=_('Post status'),
choices=constants.STATUS_LIST)
author = forms.CharField()
Expand Down
3 changes: 2 additions & 1 deletion apps/sumo/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ def process_request(self, request):

if full_path != request.path:
query_string = request.META.get('QUERY_STRING', '')
full_path = urllib.quote(full_path.encode('utf-8'))

if query_string:
full_path = '%s?%s' % (full_path, query_string)

full_path = urllib.quote(full_path.encode('utf-8'))
response = HttpResponsePermanentRedirect(full_path)

# Vary on Accept-Language if we changed the locale
Expand Down
13 changes: 7 additions & 6 deletions apps/sumo/urlresolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None):
return url


def find_supported(test):
return [x for x in settings.LANGUAGE_URL_MAP if
x.split('-', 1)[0] == test.lower().split('-', 1)[0]]


class Prefixer(object):

def __init__(self, request):
Expand All @@ -52,9 +57,7 @@ def split_path(self, path_):
if first.lower() in settings.LANGUAGES:
return first, rest
else:
supported = [x for x in settings.LANGUAGE_URL_MAP if
x.split('-')[0] ==
first.lower().split('-')[0]]
supported = find_supported(first)
if len(supported):
return supported[0], rest
else:
Expand Down Expand Up @@ -82,9 +85,7 @@ def get_language(self):
# Do we support a less specific locale? (xx-YY -> xx)
if not len(supported):
for lang in ranked_languages:
supported = [x for x in settings.LANGUAGE_URL_MAP if
lang[0].split('-', 1)[0] ==
x.split('-', 1)[0]]
supported = find_supported(lang[0])
if supported:
break

Expand Down
8 changes: 5 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)

sys.stderr.write(
"Error: Tried importing 'settings_local.py' and 'settings.py' "
"but neither could be found (or they're throwing an ImportError)."
" Please come back and try again later.")
raise

# The first thing execute_manager does is call `setup_environ`. Logging config
# needs to access settings, so we'll setup the environ early.
Expand Down
4 changes: 2 additions & 2 deletions templates/layout/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="{{ locale }}" dir="{{ dir }}">
<html lang="{{ request.locale }}" dir="{{ dir }}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>{{ title }} | {{ SITE_TITLE }}</title>
Expand Down Expand Up @@ -33,7 +33,7 @@
{% block breadcrumbs %}
<div id="breadcrumbs">
<ul>
<li><a href="{{ locale }}/kb/">{{ _('Firefox Support') }}</a></li>
<li><a href="{{ request.locale }}/kb/">{{ _('Firefox Support') }}</a></li>
<li class="divider">/</li><li>{{ title }}</li>
</ul>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/layout/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</li>
<li><a href="/">{{ _('Support') }}</a>
<ul>
<li><a href="http://support.mozilla.com/{{ locale }}/kb/">{{ _('Firefox Support') }}</a></li>
<li><a href="http://mobile.support.mozilla.com/{{ locale }}/kb/">{{ _('Mobile Support') }}</a></li>
<li><a href="http://support.mozilla.com/{{ request.locale }}/kb/">{{ _('Firefox Support') }}</a></li>
<li><a href="http://mobile.support.mozilla.com/{{ request.locale }}/kb/">{{ _('Mobile Support') }}</a></li>
<li><a href="http://www.mozilla.org/support/thunderbird/" class="external">{{ _('Thunderbird Support') }}</a></li>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion templates/layout/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h1><a href="http://www.mozilla.com/" title="{{ _('Back to Mozilla.com') }}"><im
</li>
<li id="menu_support" class="yuimenubaritem"><span class="current">{{ _('Support') }}</span>
<div class="yuimenu"><div class="bd">
<ul><li id="submenu_support_kb" class="yuimenuitem"><a href="http://support.mozilla.com/{{ locale }}/kb/">{{ _('Firefox Support') }}</a></li><li id="submenu_support_mobile" class="yuimenuitem"><a href="http://mobile.support.mozilla.com/{{ locale }}/kb/">{{ _('Mobile Support') }}</a></li><li id="submenu_support_thunderbird" class="yuimenuitem"><a href="http://www.mozilla.org/support/thunderbird/">{{ _('Thunderbird Support') }}</a></li></ul>
<ul><li id="submenu_support_kb" class="yuimenuitem"><a href="http://support.mozilla.com/{{ request.locale }}/kb/">{{ _('Firefox Support') }}</a></li><li id="submenu_support_mobile" class="yuimenuitem"><a href="http://mobile.support.mozilla.com/{{ request.locale }}/kb/">{{ _('Mobile Support') }}</a></li><li id="submenu_support_thunderbird" class="yuimenuitem"><a href="http://www.mozilla.org/support/thunderbird/">{{ _('Thunderbird Support') }}</a></li></ul>
</div></div>
</li><li id="menu_community" class="yuimenubaritem"><a href="http://www.mozilla.com/manyfaces/">{{ _('Community') }}</a>
<div class="yuimenu"><div class="bd">
Expand Down

1 comment on commit a0ba1c3

@davedash
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You aren't rebasing these changes?

Please sign in to comment.