summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-07-21 14:27:49 +0200
committerGitHub <noreply@github.com>2021-07-21 14:27:49 +0200
commit4f0d232a3dc95042be809d6fa6e93ca746156658 (patch)
tree4155de82568afd651558cb91a5d59aa256577a19 /searx
parent17e028e57928f7925a2d1ee1177d28ff33ff8487 (diff)
parent19abaf272def8faee5e7d3652d95413c3256d638 (diff)
Merge pull request #213 from return42/drop-brand
[mod] drop searx.brand namespace
Diffstat (limited to 'searx')
-rw-r--r--searx/__init__.py70
-rw-r--r--searx/settings_defaults.py7
-rw-r--r--searx/settings_robot.yml9
-rw-r--r--searx/templates/__common__/about.html14
-rw-r--r--searx/templates/__common__/new_issue.html6
-rw-r--r--searx/templates/oscar/base.html10
-rw-r--r--searx/templates/oscar/messages/no_results.html2
-rw-r--r--searx/templates/oscar/stats.html4
-rw-r--r--searx/templates/simple/base.html8
-rw-r--r--searx/templates/simple/messages/no_results.html2
-rw-r--r--searx/templates/simple/stats.html4
-rwxr-xr-xsearx/webapp.py14
12 files changed, 69 insertions, 81 deletions
diff --git a/searx/__init__.py b/searx/__init__.py
index 8452dd7b4..0b73d5204 100644
--- a/searx/__init__.py
+++ b/searx/__init__.py
@@ -32,52 +32,24 @@ if max_request_timeout is None:
else:
logger.info('max_request_timeout=%i second(s)', max_request_timeout)
-
-class _brand_namespace: # pylint: disable=invalid-name
-
- @classmethod
- def get_val(cls, group, name, default=''):
- return settings.get(group, {}).get(name) or default
-
- @property
- def SEARX_URL(self):
- return self.get_val('server', 'base_url')
-
- @property
- def CONTACT_URL(self):
- return self.get_val('general', 'contact_url')
-
- @property
- def GIT_URL(self):
- return self.get_val('brand', 'git_url')
-
- @property
- def GIT_BRANCH(self):
- return self.get_val('brand', 'git_branch')
-
- @property
- def ISSUE_URL(self):
- return self.get_val('brand', 'issue_url')
-
- @property
- def NEW_ISSUE_URL(self):
- return self.get_val('brand', 'new_issue_url')
-
- @property
- def DOCS_URL(self):
- return self.get_val('brand', 'docs_url')
-
- @property
- def PUBLIC_INSTANCES(self):
- return self.get_val('brand', 'public_instances')
-
- @property
- def WIKI_URL(self):
- return self.get_val('brand', 'wiki_url')
-
- @property
- def TWITTER_URL(self):
- return self.get_val('brand', 'twitter_url')
-
-
-brand = _brand_namespace()
+_unset = object()
+
+def get_setting(name, default=_unset):
+ """Returns the value to which ``name`` point. If there is no such name in the
+ settings and the ``default`` is unset, a :py:obj:`KeyError` is raised.
+
+ """
+ value = settings
+ for a in name.split('.'):
+ if isinstance(value, dict):
+ value = value.get(a, _unset)
+ else:
+ value = _unset
+
+ if value is _unset:
+ if default is _unset:
+ raise KeyError(name)
+ value = default
+ break
+
+ return value
diff --git a/searx/settings_defaults.py b/searx/settings_defaults.py
index 8350d92ba..d034cb1cd 100644
--- a/searx/settings_defaults.py
+++ b/searx/settings_defaults.py
@@ -130,6 +130,13 @@ SCHEMA = {
'contact_url': SettingsValue((None, False, str), None),
},
'brand': {
+ 'git_url': SettingsValue(str),
+ 'git_branch': SettingsValue(str),
+ 'issue_url': SettingsValue(str, None),
+ 'new_issue_url': SettingsValue(str, None),
+ 'docs_url': SettingsValue(str, None),
+ 'public_instances': SettingsValue(str, None),
+ 'wiki_url': SettingsValue(str, None),
},
'search': {
'safe_search': SettingsValue((0,1,2), 0),
diff --git a/searx/settings_robot.yml b/searx/settings_robot.yml
index 00dcb8da8..ca65449f7 100644
--- a/searx/settings_robot.yml
+++ b/searx/settings_robot.yml
@@ -2,6 +2,15 @@ general:
debug: false
instance_name: "searx_test"
+brand:
+ git_url: https://github.com/searxng/searxng
+ git_branch: master
+ issue_url: https://github.com/searxng/searxng/issues
+ new_issue_url: https://github.com/searxng/searxng/issues/new
+ docs_url: https://searxng.github.io/searxng
+ public_instances: https://searx.space
+ wiki_url: https://github.com/searxng/searxng/wiki
+
search:
language: "all"
diff --git a/searx/templates/__common__/about.html b/searx/templates/__common__/about.html
index 72c7b133f..96ebab28a 100644
--- a/searx/templates/__common__/about.html
+++ b/searx/templates/__common__/about.html
@@ -11,7 +11,7 @@
<p>More about SearXNG ...</p>
<ul>
- <li><a href="{{ brand.GIT_URL }}">github</a></li>
+ <li><a href="{{ get_setting('brand.git_url') }}">SearXNG sources</a></li>
<li><a href="https://www.transifex.com/projects/p/searx/">transifex</a></li>
</ul>
@@ -30,7 +30,8 @@
</li>
<li>
SearXNG is free software, the code is 100% open and you can help to make
- it better. See more on <a href="{{ brand.GIT_URL }}">github</a>.
+ it better. See more on <a href="{{ get_setting('brand.git_url')
+ }}">SearXNG sources</a>.
</li>
</ul>
@@ -80,10 +81,11 @@
<p>
SearXNG appreciates your concern regarding logs, so take the code from
- the <a href="{{ brand.GIT_URL }}">SearXNG project</a> and run it yourself!
+ the <a href="{{ get_setting('brand.git_url') }}">SearXNG project</a> and
+ run it yourself!
</p>
<p>
- Add your instance to this <a href="{{ brand.PUBLIC_INSTANCES }}"> list of
+ Add your instance to this <a href="{{ get_setting('brand.public_instances') }}"> list of
public instances</a> to help other people reclaim their privacy and make the
Internet freer! The more decentralized the Internet is, the more freedom we
have!
@@ -92,8 +94,8 @@
<h2>Where are the docs & code of this instance?</h2>
<p>
- See the <a href="{{ brand.DOCS_URL }}">{{ brand.DOCS_URL }}</a>
- and <a href="{{ brand.GIT_URL }}">{{ brand.GIT_URL }}</a>
+ See the <a href="{{ get_setting('brand.docs_url') }}">SearXNG docs</a>
+ and <a href="{{ get_setting('brand.git_url') }}">SearXNG sources</a>
</p>
</div>
diff --git a/searx/templates/__common__/new_issue.html b/searx/templates/__common__/new_issue.html
index 1b28804af..c741a049f 100644
--- a/searx/templates/__common__/new_issue.html
+++ b/searx/templates/__common__/new_issue.html
@@ -1,5 +1,5 @@
-{% macro new_issue(new_issue_url, engine_name, engine_reliability) %}
-<form action="{{ new_issue_url }}" method="GET">
+{% macro new_issue(engine_name, engine_reliability) %}
+<form action="{{ get_setting('brand.new_issue_url') }}" method="GET">
<input name="title" type="hidden" value="Bug: {{ engine_name }} engine">
<input name="labels" type="hidden" value="bug">
<input name="template" type="hidden" value="bug-report.md">
@@ -52,6 +52,6 @@ or manually by executing the searx/webapp.py file? -->
{{-'\n '}}* {{ test_name }}: {% for result in results%}`{{ result }}`,{% endfor -%}
{%- endfor -%}
</textarea>
- <button type="submit" class="github-issue-button" title="{{ new_issue_url }}">{{ _('Submit a new issue on Github including the above information') }}</button>
+ <button type="submit" class="github-issue-button" title="{{ get_setting('brand.new_issue_url') }}">{{ _('Submit a new issue on Github including the above information') }}</button>
</form>
{% endmacro %}
diff --git a/searx/templates/oscar/base.html b/searx/templates/oscar/base.html
index b85f69fa9..cc716e62b 100644
--- a/searx/templates/oscar/base.html
+++ b/searx/templates/oscar/base.html
@@ -82,11 +82,11 @@
{% endblock %}
<p class="text-muted">
<small>
- {{ _('Powered by') }} <a href="{{ brand.DOCS_URL }}">searxng</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}<br/>
- <a href="{{ brand.GIT_URL }}">{{ _('Source code') }}</a> |
- <a href="{{ brand.ISSUE_URL }}">{{ _('Issue tracker') }}</a> |
- <a href="{{ brand.PUBLIC_INSTANCES }}">{{ _('Public instances') }}</a>{% if brand.CONTACT_URL %} |
- <a href="{{ brand.CONTACT_URL }}">{{ _('Contact instance maintainer') }}</a>{% endif %}
+ {{ _('Powered by') }} <a href="{{ get_setting('brand.docs_url') }}">SearXNG</a> - {{ searx_version }} - {{ _('a privacy-respecting, hackable metasearch engine') }}<br/>
+ <a href="{{ get_setting('brand.git_url') }}">{{ _('Source code') }}</a> |
+ <a href="{{ get_setting('brand.issue_url') }}">{{ _('Issue tracker') }}</a> |
+ <a href="{{ get_setting('brand.public_instances') }}">{{ _('Public instances') }}</a>{% if get_setting('general.contact_url') %} |
+ <a href="{{ get_setting('general.contact_url') }}">{{ _('Contact instance maintainer') }}</a>{% endif %}
</small>
</p>
</div>
diff --git a/searx/templates/oscar/messages/no_results.html b/searx/templates/oscar/messages/no_results.html
index 7ad6423c5..fe8e39d33 100644
--- a/searx/templates/oscar/messages/no_results.html
+++ b/searx/templates/oscar/messages/no_results.html
@@ -10,7 +10,7 @@
</a> ){{- '' -}}
</p>
{%- endfor -%}
- <p><small>{{ _('Please, try again later or find another searx instance.') }} (<a href="{{ brand.PUBLIC_INSTANCES }}">{{ _('Public instances') }}</a>)</small></p>
+ <p><small>{{ _('Please, try again later or find another searx instance.') }} (<a href="{{ get_setting('brand.public_instances') }}">{{ _('Public instances') }}</a>)</small></p>
</div>
{% else %}
<div class="alert alert-info fade in" role="alert">
diff --git a/searx/templates/oscar/stats.html b/searx/templates/oscar/stats.html
index d9b2ab68e..4be8043ff 100644
--- a/searx/templates/oscar/stats.html
+++ b/searx/templates/oscar/stats.html
@@ -1,5 +1,5 @@
{% extends 'oscar/base.html' %}
-{% from '__common__/new_issue.html' import new_issue %}
+{% from '__common__/new_issue.html' import new_issue with context %}
{% block title %}{{ _('stats') }} - {% if selected_engine_name %} {{ selected_engine_name }} - {% endif %}{% endblock %}
@@ -148,7 +148,7 @@
{% endfor %}
</table>
{% endif %}
- {{ new_issue(brand.NEW_ISSUE_URL, selected_engine_name, engine_reliabilities[selected_engine_name]) }}
+ {{ new_issue(selected_engine_name, engine_reliabilities[selected_engine_name]) }}
{% endif %}
</div>
</div>
diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html
index 50cea045a..edf0eb6eb 100644
--- a/searx/templates/simple/base.html
+++ b/searx/templates/simple/base.html
@@ -51,10 +51,10 @@
<footer>
<p>
{{ _('Powered by') }} <a href="{{ url_for('about') }}">searxng</a> - {{ searx_version }} — {{ _('a privacy-respecting, hackable metasearch engine') }}<br/>
- <a href="{{ brand.GIT_URL }}">{{ _('Source code') }}</a> |
- <a href="{{ brand.ISSUE_URL }}">{{ _('Issue tracker') }}</a> |
- <a href="{{ brand.PUBLIC_INSTANCES }}">{{ _('Public instances') }}</a>{% if brand.CONTACT_URL %} |
- <a href="{{ brand.CONTACT_URL }}">{{ _('Contact instance maintainer') }}</a>{% endif %}
+ <a href="{{ get_setting('brand.git_url') }}">{{ _('Source code') }}</a> |
+ <a href="{{ get_setting('brand.issue_url') }}">{{ _('Issue tracker') }}</a> |
+ <a href="{{ get_setting('brand.public_instances') }}">{{ _('Public instances') }}</a>{% if get_setting('general.contact_url') %} |
+ <a href="{{ get_setting('general.contact_url') }}">{{ _('Contact instance maintainer') }}</a>{% endif %}
</p>
</footer>
<!--[if gte IE 9]>-->
diff --git a/searx/templates/simple/messages/no_results.html b/searx/templates/simple/messages/no_results.html
index b7f02167e..845f3e21a 100644
--- a/searx/templates/simple/messages/no_results.html
+++ b/searx/templates/simple/messages/no_results.html
@@ -11,7 +11,7 @@
</p>
{%- endfor %}
- <p><small>{{ _('Please, try again later or find another searx instance.') }} (<a href="{{ brand.PUBLIC_INSTANCES }}">{{ _('Public instances') }}</a>) </small></p>
+ <p><small>{{ _('Please, try again later or find another searx instance.') }} (<a href="{{ get_setting('brand.public_instances') }}">{{ _('Public instances') }}</a>) </small></p>
</div>
{% else %}
<div class="dialog-error" role="alert">
diff --git a/searx/templates/simple/stats.html b/searx/templates/simple/stats.html
index 7058d04d4..f423b6861 100644
--- a/searx/templates/simple/stats.html
+++ b/searx/templates/simple/stats.html
@@ -1,5 +1,5 @@
{% from 'simple/macros.html' import icon %}
-{% from '__common__/new_issue.html' import new_issue %}
+{% from '__common__/new_issue.html' import new_issue with context %}
{% extends "simple/base.html" %}
@@ -147,7 +147,7 @@
{% endfor %}
</table>
{% endif %}
- {{ new_issue(brand.NEW_ISSUE_URL, selected_engine_name, engine_reliabilities[selected_engine_name]) }}
+ {{ new_issue(selected_engine_name, engine_reliabilities[selected_engine_name]) }}
{% endif %}
</div>
diff --git a/searx/webapp.py b/searx/webapp.py
index 4d838062b..09c0643be 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -50,7 +50,7 @@ from flask_babel import (
)
from searx import logger
-from searx import brand
+from searx import get_setting
from searx import (
settings,
searx_debug,
@@ -473,11 +473,9 @@ def render(template_name, override_theme=None, **kwargs):
kwargs['search_formats'] = [
x for x in settings['search']['formats'] if x != 'html'
]
-
- # brand
- kwargs['instance_name'] = settings['general']['instance_name']
+ kwargs['instance_name'] = get_setting('general.instance_name')
kwargs['searx_version'] = VERSION_STRING
- kwargs['brand'] = brand
+ kwargs['get_setting'] = get_setting
# helpers to create links to other pages
kwargs['url_for'] = url_for_theme # override url_for function in templates
@@ -1323,9 +1321,9 @@ def config():
'default_theme': settings['ui']['default_theme'],
'version': VERSION_STRING,
'brand': {
- 'CONTACT_URL': brand.CONTACT_URL,
- 'GIT_URL': brand.GIT_URL,
- 'DOCS_URL': brand.DOCS_URL
+ 'CONTACT_URL': get_setting('general.contact_url'),
+ 'GIT_URL': get_setting('brand.git_url'),
+ 'DOCS_URL': get_setting('brand.docs_url'),
},
'doi_resolvers': list(settings['doi_resolvers'].keys()),
'default_doi_resolver': settings['default_doi_resolver'],