浏览代码

minor fixes of doi resolver

Closes #1047
Noémi Ványi 7 年前
父节点
当前提交
1b10abfc92
共有 4 个文件被更改,包括 19 次插入32 次删除
  1. 4
    5
      searx/plugins/oa_doi_rewrite.py
  2. 1
    1
      searx/preferences.py
  3. 12
    17
      searx/templates/oscar/preferences.html
  4. 2
    9
      searx/webapp.py

+ 4
- 5
searx/plugins/oa_doi_rewrite.py 查看文件

@@ -1,7 +1,6 @@
1 1
 from flask_babel import gettext
2 2
 import re
3 3
 from searx.url_utils import urlparse, parse_qsl
4
-from flask import request
5 4
 from searx import settings
6 5
 
7 6
 
@@ -26,12 +25,12 @@ def extract_doi(url):
26 25
     return None
27 26
 
28 27
 
29
-def get_doi_resolver():
28
+def get_doi_resolver(args, preference_doi_resolver):
30 29
     doi_resolvers = settings['doi_resolvers']
31
-    doi_resolver = request.args.get('doi_resolver', request.preferences.get_value('doi_resolver'))[0]
30
+    doi_resolver = args.get('doi_resolver', preference_doi_resolver)[0]
32 31
     if doi_resolver not in doi_resolvers:
33 32
         doi_resolvers = settings['default_doi_resolver']
34
-    return doi_resolvers[doi_resolver]
33
+    return doi_resolver
35 34
 
36 35
 
37 36
 def on_result(request, search, result):
@@ -40,6 +39,6 @@ def on_result(request, search, result):
40 39
         for suffix in ('/', '.pdf', '/full', '/meta', '/abstract'):
41 40
             if doi.endswith(suffix):
42 41
                 doi = doi[:-len(suffix)]
43
-        result['url'] = get_doi_resolver() + doi
42
+        result['url'] = get_doi_resolver(request.args, request.preferences.get_value('doi_resolver')) + doi
44 43
         result['parsed_url'] = urlparse(result['url'])
45 44
     return True

+ 1
- 1
searx/preferences.py 查看文件

@@ -15,7 +15,7 @@ LANGUAGE_CODES = [l[0] for l in languages]
15 15
 LANGUAGE_CODES.append('all')
16 16
 DISABLED = 0
17 17
 ENABLED = 1
18
-DOI_RESOLVERS = [r for r in settings['doi_resolvers'].keys()]
18
+DOI_RESOLVERS = list(settings['doi_resolvers'])
19 19
 
20 20
 
21 21
 class MissingArgumentException(Exception):

+ 12
- 17
searx/templates/oscar/preferences.html 查看文件

@@ -118,6 +118,18 @@
118 118
                             <option value="0" {% if not results_on_new_tab %}selected="selected"{% endif %}>{{ _('Off')}}</option>
119 119
                         </select>
120 120
                     {{ preferences_item_footer(info, label, rtl) }}
121
+
122
+                    {% set label = _('Open Access DOI resolver') %}
123
+                    {% set info = _('Redirect to open-access versions of publications when available (plugin required)') %}
124
+                    {{ preferences_item_header(info, label, rtl) }}
125
+                        <select class="form-control" id='doi_resolver' name='doi_resolver'>
126
+                            {% for doi_resolver_name,doi_resolver_url in doi_resolvers.items() %}
127
+                            <option value="{{ doi_resolver_name }}" {% if doi_resolver_name == current_doi_resolver %}selected="selected"{% endif %}>
128
+                                    {{ doi_resolver_name }} - {{ doi_resolver_url }}
129
+                            </option>
130
+                             {% endfor %}
131
+                         </select>
132
+                    {{ preferences_item_footer(info, label, rtl) }}
121 133
                 </div>
122 134
                 </fieldset>
123 135
             </div>
@@ -223,23 +235,6 @@
223 235
                             </div>
224 236
                         </div>
225 237
                         {% endfor %}
226
-                        <div class="panel panel-default">
227
-                            <div class="panel-heading">
228
-                                <h3 class="panel-title">{{ _('OA DOI rewrite') }}</h3>
229
-                            </div>
230
-                            <div class="panel-body">
231
-                                <div class="col-xs-6 col-sm-4 col-md-6">{{ _('Avoid paywalls by redirecting to open-access versions of publications when available') }}</div>
232
-                                <div class="col-xs-6 col-sm-4 col-md-6">
233
-                                    <select class="form-control" id='doi_resolver' name='doi_resolver'>
234
-                                        {% for doi_resolver_name,doi_resolver_url in doi_resolvers.items() %}
235
-                                        <option value="{{ doi_resolver_name }}" {% if doi_resolver_name == current_doi_resolver %}selected="selected"{% endif %}>
236
-                                                {{ doi_resolver_name }} - {{ doi_resolver_url }}
237
-                                        </option>
238
-                                         {% endfor %}
239
-                                     </select>
240
-                                </div>
241
-                            </div>
242
-                        </div>
243 238
                     </div>
244 239
                 </fieldset>
245 240
             </div>

+ 2
- 9
searx/webapp.py 查看文件

@@ -66,6 +66,7 @@ from searx.search import SearchWithPlugins, get_search_query_from_webapp
66 66
 from searx.query import RawTextQuery
67 67
 from searx.autocomplete import searx_bang, backends as autocomplete_backends
68 68
 from searx.plugins import plugins
69
+from searx.plugins.oa_doi_rewrite import get_doi_resolver
69 70
 from searx.preferences import Preferences, ValidationException
70 71
 from searx.answerers import answerers
71 72
 from searx.url_utils import urlencode, urlparse, urljoin
@@ -164,14 +165,6 @@ def get_locale():
164 165
     return locale
165 166
 
166 167
 
167
-def get_doi_resolver():
168
-    doi_resolvers = settings['doi_resolvers']
169
-    doi_resolver = request.args.get('doi_resolver', request.preferences.get_value('doi_resolver'))[0]
170
-    if doi_resolver not in doi_resolvers:
171
-        doi_resolvers = settings['default_doi_resolver']
172
-    return doi_resolver
173
-
174
-
175 168
 # code-highlighter
176 169
 @app.template_filter('code_highlighter')
177 170
 def code_highlighter(codelines, language=None):
@@ -704,7 +697,7 @@ def preferences():
704 697
                   themes=themes,
705 698
                   plugins=plugins,
706 699
                   doi_resolvers=settings['doi_resolvers'],
707
-                  current_doi_resolver=get_doi_resolver(),
700
+                  current_doi_resolver=get_doi_resolver(request.args, request.preferences.get_value('doi_resolver')),
708 701
                   allowed_plugins=allowed_plugins,
709 702
                   theme=get_current_theme_name(),
710 703
                   preferences_url_params=request.preferences.get_as_url_params(),