Commit 4e4f1fbd authored by Michal Čihař's avatar Michal Čihař

Merge branch 'search' of https://github.com/xyzz/weblate into search

Conflicts:
	trans/forms.py
	trans/views/basic.py
parents a1f33218 5f1be10e
...@@ -31,7 +31,7 @@ from django.utils.safestring import mark_safe ...@@ -31,7 +31,7 @@ from django.utils.safestring import mark_safe
from trans.models import ( from trans.models import (
Project, SubProject, Translation, Check, Project, SubProject, Translation, Check,
Dictionary, Change, Dictionary, Change, Unit
) )
from trans.requirements import get_versions, get_optional_versions from trans.requirements import get_versions, get_optional_versions
from lang.models import Language from lang.models import Language
...@@ -108,9 +108,30 @@ def home(request): ...@@ -108,9 +108,30 @@ def home(request):
'last_changes_rss': reverse('rss'), 'last_changes_rss': reverse('rss'),
'last_changes_url': '', 'last_changes_url': '',
'usertranslations': usertranslations, 'usertranslations': usertranslations,
'search_form': SearchForm(),
})) }))
def search(request):
search_form = SearchForm(request.GET)
context = {}
if search_form.is_valid():
units = Unit.objects.search(
search_form.cleaned_data['search'],
search_form.cleaned_data['q'],
search_form.cleaned_data['src'],
search_form.cleaned_data['ctx'],
search_form.cleaned_data['tgt'],
).filter(translation__language__code="en").order_by("translation")[:1000]
context = {
'units': units,
'search_query': search_form.cleaned_data['q']
}
else:
messages.error(request, _('Invalid search query!'))
return render_to_response('search.html', RequestContext(request, context))
def show_engage(request, project, lang=None): def show_engage(request, project, lang=None):
# Get project object # Get project object
obj = get_project(request, project) obj = get_project(request, project)
......
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
<ul> <ul>
<li><a href="#changes">{% trans "History" %}</a></li> <li><a href="#changes">{% trans "History" %}</a></li>
<li><a href="#search">{% trans "Search" %}</a></li>
<li><a href="#translators">{% trans "Most active translators" %}</a></li> <li><a href="#translators">{% trans "Most active translators" %}</a></li>
<li><a href="#suggesters">{% trans "Most active suggesters" %}</a></li> <li><a href="#suggesters">{% trans "Most active suggesters" %}</a></li>
<li><a href="{% url 'view_activity' %}">{% trans "Activity" %}</a></li> <li><a href="{% url 'view_activity' %}">{% trans "Activity" %}</a></li>
...@@ -73,6 +74,13 @@ ...@@ -73,6 +74,13 @@
{% include "last-changes.html" %} {% include "last-changes.html" %}
</div> </div>
<div id="search">
<form action="{% url 'search' %}" method="GET">
{{ search_form.as_p }}
<input type="submit" value="{% trans "Search" %}" class="button" />
</form>
</div>
<div id="translators"> <div id="translators">
<table> <table>
<thead> <thead>
......
{% extends "base.html" %}
{% load i18n %}
{% load url from future %}
{% load translations %}
{% block breadcrumbs %}
<li><a href="{% url 'search' %}">{% trans "Search" %}</a></li>
{% endblock %}
{% block content %}
{% regroup units by translation as translation_units %}
{% for translation_unit in translation_units %}
<h2>{{ translation_unit.grouper }}</h2>
<table class="ui-widget-content">
{% for unit in translation_unit.list %}
<tr>
<th class="source">{% trans "Source" %}</th>
<td class="translatetext"><a href="{{ unit.get_absolute_url }}">{{ unit.source|fmtsearchmatch:search_query }}</a></td>
</tr>
<tr>
<th class="source">{{ unit.translation.language }}</th>
<td class="translatetext"><a href="{{ unit.get_absolute_url }}">{{ unit.target|fmtsearchmatch:search_query }}</a></td>
</tr>
{% if not forloop.last %}
<tr><td colspan="2">&nbsp;</td></tr>
{% endif %}
{% endfor %}
</table>
{% endfor %}
{% endblock %}
\ No newline at end of file
...@@ -635,4 +635,10 @@ urlpatterns = patterns( ...@@ -635,4 +635,10 @@ urlpatterns = patterns(
'django.views.static.serve', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT} {'document_root': settings.MEDIA_ROOT}
), ),
url(
r'^search/$',
'trans.views.basic.search',
name="search"
),
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment