Skip to content

Commit

Permalink
feat: allow user search to filter changes
Browse files Browse the repository at this point in the history
This allows to search from the info tab to match shown numbers.

Fixes WeblateOrg#12969
See also WeblateOrg#11808
  • Loading branch information
nijel committed Nov 12, 2024
1 parent 48d3c12 commit a9564a1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Weblate 5.8.4

Not yet released.

**Improvements**

* :ref:`search-users` can search based on user changes.

**Bug fixes**

* Fixed occasional crash in :ref:`rss`.
Expand Down
7 changes: 7 additions & 0 deletions docs/user/search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Searching
=========

.. _search-strings:

Searching for strings
+++++++++++++++++++++

Expand Down Expand Up @@ -178,6 +180,7 @@ There are many options to order the strings according to your needs:

.. image:: /screenshots/query-sort.webp

.. _search-users:

Searching for users
+++++++++++++++++++
Expand All @@ -198,6 +201,10 @@ The user browsing has similar search abilities:
User has contributed to a given language in the past 90 days.
``contributes:TEXT``
User has contributed to a given project or component in the past 90 days.
``change_time:DATETIME``
Same as in :ref:`search-strings`.
``change_action:TEXT``
Same as in :ref:`search-strings`.

Additional lookups are available in the :ref:`management-interface`:

Expand Down
8 changes: 5 additions & 3 deletions weblate/templates/snippets/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ <h4 class="panel-title">{% trans "Trends of last 30 days" %}</h4>
</div>
<div class="col-sm-3">
<div class="metric">
<a href="{% url "user_list" %}?q={% if language %}translates:{{ language.code|urlencode }}{% elif translation %}translates:{{ translation.language.code|urlencode }}{% endif %} {% if component %}contributes:{{ component.full_slug|urlencode }}{% elif project %}contributes:{{ project.slug|urlencode }}{% endif %}">
<a href="{% url "user_list" %}?q={% if language %}translates:{{ language.code|urlencode }}{% elif translation %}translates:{{ translation.language.code|urlencode }}{% endif %} {% if component %}contributes:{{ component.full_slug|urlencode }}{% elif project %}contributes:{{ project.slug|urlencode }}{% endif %} change_time:&gt;'30 days ago' ">
<div class="metric-number">{{ metrics.contributors|number_format }}</div>
<div class="metric-text">{% trans "Contributors" %}</div>
</a>
Expand Down Expand Up @@ -509,8 +509,10 @@ <h4 class="panel-title">{% trans "Trends of last 30 days" %}</h4>
</div>
<div class="col-sm-3">
<div class="metric">
<div class="metric-number">{{ metrics.trend_30_contributors|trend_format }}</div>
<div class="metric-text">{% trans "Contributors" %}</div>
<a href="{% url "user_list" %}?q={% if language %}translates:{{ language.code|urlencode }}{% elif translation %}translates:{{ translation.language.code|urlencode }}{% endif %} {% if component %}contributes:{{ component.full_slug|urlencode }}{% elif project %}contributes:{{ project.slug|urlencode }}{% endif %} change_time:&lt;'30 days ago' change_time:&gt;'60 days ago' ">
<div class="metric-number">{{ metrics.trend_30_contributors|trend_format }}</div>
<div class="metric-text">{% trans "Contributors" %}</div>
</a>
<div class="metric-detail">{{ metrics.trend_60_contributors|trend_format }}</div>
</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions weblate/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ def convert_change_action(self, text: str) -> int:
except KeyError:
return Change.ACTION_STRINGS[text]

def convert_change_time(self, text: str) -> datetime | tuple[datetime, datetime]:
return self.convert_datetime(text)

def field_name(self, field: str, suffix: str | None = None) -> str:
if suffix is None:
suffix = OPERATOR_MAP[self.operator]
Expand Down Expand Up @@ -536,9 +539,6 @@ def path_field(self, text: str, context: dict) -> Q:
return Q(translation__language=obj)
raise TypeError(f"Unsupported path lookup: {obj}")

def convert_change_time(self, text: str) -> datetime | tuple[datetime, datetime]:
return self.convert_datetime(text)

def convert_changed(self, text: str) -> datetime | tuple[datetime, datetime]:
return self.convert_datetime(text)

Expand Down Expand Up @@ -591,6 +591,8 @@ class UserTermExpr(BaseTermExpr):
PLAIN_FIELDS: set[str] = {"username", "full_name"}
NONTEXT_FIELDS: dict[str, str] = {
"joined": "date_joined",
"change_time": "change__timestamp",
"change_action": "change__action",
}
EXACT_FIELD_MAP: dict[str, str] = {
"language": "profile__languages__code",
Expand Down

0 comments on commit a9564a1

Please sign in to comment.