0001-profile-register-users-search-engine-26261.patch
combo/profile/__init__.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
# |
|
1 | 3 |
# combo - content management system |
2 | 4 |
# Copyright (C) 2014-2018 Entr'ouvert |
3 | 5 |
# |
... | ... | |
23 | 25 |
name = 'combo.profile' |
24 | 26 |
verbose_name = _('Profile') |
25 | 27 | |
28 |
def ready(self): |
|
29 |
from combo.apps.search import engines |
|
30 |
engines.register(self.get_search_engines) |
|
31 | ||
32 |
def get_search_engines(self): |
|
33 |
from combo.data.models import Page |
|
34 |
from django.conf import settings |
|
35 | ||
36 |
user_page = Page.objects.filter(sub_slug__contains='<name_id>').first() |
|
37 |
if not user_page: |
|
38 |
return |
|
39 |
user_page_base_url = user_page.get_online_url() |
|
40 | ||
41 |
# return entry using first(&only) authentic (if it exists) |
|
42 |
for key, service in settings.KNOWN_SERVICES.get('authentic', {}).items(): |
|
43 |
return { |
|
44 |
'users': { |
|
45 |
'url': service['url'] + 'api/users/?q=%(q)s', |
|
46 |
'label': _('Users'), |
|
47 |
'signature': True, |
|
48 |
'data_key': 'results', |
|
49 |
'hit_url_template': user_page_base_url + '{{uuid}}/', |
|
50 |
'hit_label_template': '{{first_name}} {{last_name}}', |
|
51 |
'hit_description_template': |
|
52 |
'{{ email|default:"" }}' |
|
53 |
'{% if phone %} 📞 {{ phone }}{% endif %}' |
|
54 |
'{% if mobile %} 📱 {{ mobile }}{% endif %}' |
|
55 |
'{% if address or zipcode or city %} 📨 {% endif %}' |
|
56 |
'{% if address %} {{ address }}{% endif %}' |
|
57 |
'{% if zipcode %} {{ zipcode }}{% endif %}' |
|
58 |
'{% if city %} {{ city }}{% endif %}' |
|
59 |
} |
|
60 |
} |
|
61 | ||
26 | 62 |
default_app_config = 'combo.profile.AppConfig' |
tests/test_search.py | ||
---|---|---|
373 | 373 |
search_engines = engines.get_engines() |
374 | 374 |
assert 'tracking-code' not in search_engines.keys() |
375 | 375 |
assert len([x for x in search_engines.keys() if x.startswith('formdata:')]) == 0 |
376 | ||
377 | ||
378 |
def test_profile_search_engines(app): |
|
379 |
search_engines = engines.get_engines() |
|
380 |
assert 'users' not in search_engines.keys() |
|
381 |
with override_settings(KNOWN_SERVICES={'authentic': {'default': {'title': 'authentic', 'url': 'https://authentic/'}}}): |
|
382 |
search_engines = engines.get_engines() |
|
383 |
assert 'users' not in search_engines.keys() |
|
384 | ||
385 |
page = Page(slug='users', title='Users', sub_slug='(?P<name_id>[a-z0-9]+)') |
|
386 |
page.save() |
|
387 |
search_engines = engines.get_engines() |
|
388 |
assert 'users' in search_engines.keys() |
|
376 |
- |