0001-manage-Publik-s-SMS-default-country-setting-through-.patch
hobo/environment/models.py | ||
---|---|---|
52 | 52 |
'meta_keywords', |
53 | 53 |
'sms_url', |
54 | 54 |
'sms_sender', |
55 |
'default_country_code', |
|
55 | 56 |
) |
56 | 57 | |
57 | 58 |
hobo/multitenant/settings_loaders.py | ||
---|---|---|
203 | 203 |
tenant_settings.USER_PROFILE_CONFIG = hobo_json.get('profile') |
204 | 204 |
tenant_settings.SMS_URL = variables.get('sms_url', '') |
205 | 205 |
tenant_settings.SMS_SENDER = variables.get('sms_sender', '') |
206 |
tenant_settings.DEFAULT_COUNTRY_CODE = variables.get('default_country_code', '') |
|
206 | 207 | |
207 | 208 | |
208 | 209 |
class SettingsVars(SettingsDictUpdateMixin, FileBaseSettingsLoader): |
hobo/settings.py | ||
---|---|---|
238 | 238 |
# List of service to show in the create service menu, it overrides HOBO_SERVICES_DISABLED. |
239 | 239 |
HOBO_SERVICES_ENABLED = [] |
240 | 240 | |
241 |
# Phone prefixes by country for phone number as authentication identifier |
|
242 |
PHONE_COUNTRY_CODES = { |
|
243 |
'32': {'lang': 'BE', 'area': _('Belgium')}, |
|
244 |
'33': {'lang': 'FR', 'area': _('Metropolitan France')}, |
|
245 |
'262': {'lang': 'FR', 'area': _('Réunion')}, |
|
246 |
'508': {'lang': 'FR', 'area': _('Saint Pierre and Miquelon')}, |
|
247 |
'590': {'lang': 'FR', 'area': _('Guadeloupe')}, |
|
248 |
'594': {'lang': 'FR', 'area': _('French Guiana')}, |
|
249 |
'596': {'lang': 'FR', 'area': _('Martinique')}, |
|
250 |
} |
|
251 | ||
241 | 252 |
local_settings_file = os.environ.get( |
242 | 253 |
'HOBO_SETTINGS_FILE', os.path.join(os.path.dirname(__file__), 'local_settings.py') |
243 | 254 |
) |
hobo/sms/forms.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
from django import forms |
17 |
from django.conf import settings |
|
17 | 18 |
from django.core.exceptions import ValidationError |
18 | 19 |
from django.core.validators import RegexValidator |
19 | 20 |
from django.utils.translation import ugettext_lazy as _ |
... | ... | |
33 | 34 |
'Sender name or phone number. It must neither exceed 11 characters nor contain special characters.' |
34 | 35 |
), |
35 | 36 |
) |
37 |
default_country_code = forms.ChoiceField( |
|
38 |
label=_('Default country code'), |
|
39 |
help_text=_('Default country code used as international prefix while sending SMS messages.'), |
|
40 |
) |
|
41 | ||
42 |
def __init__(self, *args, **kwargs): |
|
43 |
super().__init__(*args, **kwargs) |
|
44 |
country_code_choices = [ |
|
45 |
(key, f"+{key} ({value['area']})") for key, value in settings.PHONE_COUNTRY_CODES.items() |
|
46 |
] |
|
47 |
self.fields['default_country_code'].choices = country_code_choices |
|
36 | 48 | |
37 | 49 |
def clean_sms_url(self): |
38 | 50 |
value = self.cleaned_data['sms_url'] |
hobo/sms/views.py | ||
---|---|---|
25 | 25 | |
26 | 26 |
class HomeView(VariablesFormMixin, TemplateView): |
27 | 27 |
template_name = 'hobo/sms_home.html' |
28 |
variables = ['sms_url', 'sms_sender'] |
|
28 |
variables = ['sms_url', 'sms_sender', 'default_country_code']
|
|
29 | 29 |
form_class = SMSForm |
30 | 30 |
success_message = _('SMS settings have been updated. It will take a few seconds to be effective.') |
31 | 31 |
tests/test_settings_loaders.py | ||
---|---|---|
162 | 162 |
tenant_settings = UserSettingsHolder({}) |
163 | 163 |
loader = TemplateVars() |
164 | 164 | |
165 |
variables = {'sms_url': 'https://example.com/send/', 'sms_sender': 'Sender'} |
|
165 |
variables = { |
|
166 |
'sms_url': 'https://example.com/send/', |
|
167 |
'sms_sender': 'Sender', |
|
168 |
'default_country_code': '262', |
|
169 |
} |
|
166 | 170 |
env = {'services': [], 'variables': variables} |
167 | 171 |
path = os.path.join(str(tmpdir), 'hobo.json') |
168 | 172 |
json.dump(env, open(path, 'w')) |
169 | 173 |
loader.update_settings_from_path(tenant_settings, path) |
170 | 174 |
assert tenant_settings.SMS_URL == 'https://example.com/send/' |
171 | 175 |
assert tenant_settings.SMS_SENDER == 'Sender' |
176 |
assert tenant_settings.DEFAULT_COUNTRY_CODE == '262' |
|
172 |
- |