From 116cb21d68a5661746a9c33010a23543822ba423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 1 May 2016 09:50:57 +0200 Subject: [PATCH 2/4] backoffice: add "geolocations" option to forms (#10581) --- tests/test_admin_pages.py | 18 ++++++++++++++++++ wcs/admin/forms.py | 30 +++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/test_admin_pages.py b/tests/test_admin_pages.py index 3dd5d8d..a8e32ef 100644 --- a/tests/test_admin_pages.py +++ b/tests/test_admin_pages.py @@ -291,6 +291,24 @@ def test_forms_edit(pub): resp = resp.follow() assert_option_display(resp, 'Online Status', 'Inactive by date') + # enable geolocation + resp = resp.click('Geolocation') + resp.forms[0]['geoloc_label'] = 'Foobar' + resp = resp.forms[0].submit() + assert resp.location == 'http://example.net/backoffice/forms/1/' + resp = resp.follow() + assert_option_display(resp, 'Geolocation', 'Enabled') + assert FormDef.get(formdef.id).geolocations == {'base': 'Foobar'} + + # and disable it + resp = resp.click('Geolocation') + resp.forms[0]['geoloc_label'] = '' + resp = resp.forms[0].submit() + assert resp.location == 'http://example.net/backoffice/forms/1/' + resp = resp.follow() + assert_option_display(resp, 'Geolocation', 'Disabled') + assert FormDef.get(formdef.id).geolocations is None + # try changing title resp = app.get('/backoffice/forms/1/') resp = resp.click('change title') diff --git a/wcs/admin/forms.py b/wcs/admin/forms.py index 5a101df..48c42da 100644 --- a/wcs/admin/forms.py +++ b/wcs/admin/forms.py @@ -135,7 +135,8 @@ class FieldsDirectory(FieldsDirectory): class OptionsDirectory(Directory): _q_exports = ['confirmation', 'private_status', 'only_allow_one', 'always_advertise', 'tracking_code', 'online_status', 'captcha', - 'description', 'keywords', 'category', ('360_view', 'p_360_view')] + 'description', 'keywords', 'category', ('360_view', 'p_360_view'), + 'geolocations'] def __init__(self, formdef): self.formdef = formdef @@ -229,6 +230,14 @@ class OptionsDirectory(Directory): options=[(None, '---', '')] + categories) return self.handle(form, _('Category')) + def geolocations(self): + form = Form(enctype='multipart/form-data') + geoloc_label = (self.formdef.geolocations or {}).get('base') + form.add(StringWidget, 'geoloc_label', title=_('Geolocation Label'), + value=geoloc_label, size=50, + hint=_('Location label (empty to disable geolocation)')) + return self.handle(form, _('Geolocation')) + def handle(self, form, title): form.add_submit('submit', _('Submit')) form.add_submit('cancel', _('Cancel')) @@ -241,11 +250,17 @@ class OptionsDirectory(Directory): 'always_advertise', 'disabled_redirection', 'publication_date', 'expiration_date', 'has_captcha', 'description', 'keywords', 'category_id', - 'skip_from_360_view'] - for f in attrs: - widget = form.get_widget(f) + 'skip_from_360_view', 'geoloc_label'] + for attr in attrs: + widget = form.get_widget(attr) if widget: - setattr(self.formdef, str(f), widget.parse()) + if attr == 'geoloc_label': + if widget.parse(): + self.formdef.geolocations = {'base': widget.parse()} + else: + self.formdef.geolocations = None + else: + setattr(self.formdef, str(attr), widget.parse()) self.formdef.store() return redirect('..') @@ -459,6 +474,11 @@ class FormDefPage(Directory): self.formdef.enable_tracking_codes and C_('tracking code|Enabled') or C_('tracking code|Disabled')) + r += add_option_line('options/geolocations', + _('Geolocation'), + self.formdef.geolocations and + C_('geolocation|Enabled') or C_('geolocation|Disabled')) + if get_publisher().has_site_option('formdef-captcha-option'): r += add_option_line('options/captcha', _('CAPTCHA for anonymous users'), -- 2.8.1