0002-replace-use-of-self.compute-.-by-misc.compute-.-1451.patch
tests/test_workflows.py | ||
---|---|---|
11 | 11 |
from quixote import cleanup, get_response |
12 | 12 |
from wcs.qommon.http_request import HTTPRequest |
13 | 13 |
from qommon.form import * |
14 |
from qommon.misc import compute |
|
14 | 15 | |
15 | 16 |
from wcs.formdef import FormDef |
16 | 17 |
from wcs import sessions |
... | ... | |
120 | 121 |
formdata.store() |
121 | 122 |
pub.substitutions.feed(formdata) |
122 | 123 | |
123 |
item = JumpWorkflowStatusItem() |
|
124 | ||
125 | 124 |
# straight string |
126 |
assert item.compute('blah') == 'blah'
|
|
125 |
assert compute('blah') == 'blah' |
|
127 | 126 | |
128 | 127 |
# ezt string |
129 |
assert item.compute('[form_var_foo]') == 'hello'
|
|
128 |
assert compute('[form_var_foo]') == 'hello' |
|
130 | 129 |
# ezt string, but not ezt asked |
131 |
assert item.compute('[form_var_foo]', do_ezt=False) == '[form_var_foo]'
|
|
130 |
assert compute('[form_var_foo]', do_ezt=False) == '[form_var_foo]' |
|
132 | 131 |
# ezt string, with an error |
133 |
assert item.compute('[end]', raises=False) == '[end]'
|
|
132 |
assert compute('[end]', raises=False) == '[end]' |
|
134 | 133 |
with pytest.raises(Exception): |
135 |
item.compute('[end]', raises=True)
|
|
134 |
compute('[end]', raises=True) |
|
136 | 135 | |
137 | 136 |
# python expression |
138 |
assert item.compute('=form_var_foo') == 'hello'
|
|
137 |
assert compute('=form_var_foo') == 'hello' |
|
139 | 138 |
# python expression, with an error |
140 |
assert item.compute('=1/0', raises=False) == '=1/0'
|
|
139 |
assert compute('=1/0', raises=False) == '=1/0' |
|
141 | 140 |
with pytest.raises(Exception): |
142 |
item.compute('=1/0', raises=True)
|
|
141 |
compute('=1/0', raises=True) |
|
143 | 142 | |
144 | 143 |
def test_jump_nothing(pub): |
145 | 144 |
FormDef.wipe() |
wcs/wf/backoffice_fields.py | ||
---|---|---|
22 | 22 | |
23 | 23 |
from qommon import _ |
24 | 24 |
from qommon import get_logger |
25 |
from qommon.misc import compute |
|
25 | 26 |
from qommon.form import (WidgetListAsTable, CompositeWidget, SingleSelectWidget, |
26 | 27 |
ComputedExpressionWidget, PicklableUpload) |
27 | 28 |
from wcs.fields import WidgetField |
... | ... | |
122 | 123 |
continue |
123 | 124 | |
124 | 125 |
try: |
125 |
new_value = self.compute(field['value'], raises=True)
|
|
126 |
new_value = compute(field['value'], raises=True) |
|
126 | 127 |
except: |
127 | 128 |
get_publisher().notify_of_exception(sys.exc_info()) |
128 | 129 |
continue |
wcs/wf/geolocate.py | ||
---|---|---|
29 | 29 |
from qommon import _ |
30 | 30 |
from qommon import get_logger |
31 | 31 |
from qommon.form import RadiobuttonsWidget, ComputedExpressionWidget, CheckboxWidget |
32 |
from qommon.misc import http_get_page |
|
32 |
from qommon.misc import http_get_page, compute
|
|
33 | 33 |
from wcs.workflows import WorkflowStatusItem, register_item_class |
34 | 34 | |
35 | 35 |
class GeolocateWorkflowStatusItem(WorkflowStatusItem): |
... | ... | |
107 | 107 |
nominatim_url = 'http://nominatim.openstreetmap.org' |
108 | 108 | |
109 | 109 |
try: |
110 |
address = self.compute(self.address_string, raises=True)
|
|
110 |
address = compute(self.address_string, raises=True) |
|
111 | 111 |
except Exception, e: |
112 | 112 |
get_logger().error('error in template for address string [%r]', e) |
113 | 113 |
return |
... | ... | |
129 | 129 |
return {'lon': float(coords['lon']), 'lat': float(coords['lat'])} |
130 | 130 | |
131 | 131 |
def geolocate_map_variable(self, formdata): |
132 |
value = self.compute(self.map_variable)
|
|
132 |
value = compute(self.map_variable) |
|
133 | 133 |
if not value: |
134 | 134 |
return |
135 | 135 | |
... | ... | |
146 | 146 |
get_logger().error('error geolocating from file (missing PIL)') |
147 | 147 |
return |
148 | 148 | |
149 |
value = self.compute(self.photo_variable)
|
|
149 |
value = compute(self.photo_variable) |
|
150 | 150 |
if not hasattr(value, 'get_file_pointer'): |
151 | 151 |
get_logger().error('error geolocating from photo, invalid variable') |
152 | 152 |
return |
wcs/wf/jump.py | ||
---|---|---|
27 | 27 |
from qommon import errors |
28 | 28 |
from qommon.publisher import get_publisher_class |
29 | 29 |
from qommon.cron import CronJob |
30 |
from qommon.misc import compute |
|
30 | 31 | |
31 | 32 |
from wcs.workflows import Workflow, WorkflowStatusJumpItem, register_item_class |
32 | 33 |
from wcs.api import get_user_from_api_query_string, is_url_signed |
... | ... | |
215 | 216 |
must_jump = must_jump and triggered |
216 | 217 | |
217 | 218 |
if self.timeout: |
218 |
timeout = int(self.compute(self.timeout))
|
|
219 |
timeout = int(compute(self.timeout)) |
|
219 | 220 |
if formdata.evolution: |
220 | 221 |
last = formdata.evolution[-1].time |
221 | 222 |
else: |
wcs/wf/profile.py | ||
---|---|---|
24 | 24 |
from qommon.form import (CompositeWidget, SingleSelectWidget, |
25 | 25 |
WidgetListAsTable, ComputedExpressionWidget) |
26 | 26 |
from qommon.ident.idp import is_idp_managing_user_attributes |
27 |
from qommon.misc import http_patch_request |
|
27 |
from qommon.misc import http_patch_request, compute
|
|
28 | 28 |
from qommon.publisher import get_cfg, get_logger |
29 | 29 | |
30 | 30 |
from wcs.api_utils import sign_url, get_secret_and_orig, MissingSecret |
... | ... | |
145 | 145 |
get_publisher().substitutions.feed(formdata) |
146 | 146 |
new_data = {} |
147 | 147 |
for field in self.fields: |
148 |
new_data[field.get('field_id')] = self.compute(field.get('value'))
|
|
148 |
new_data[field.get('field_id')] = compute(field.get('value')) |
|
149 | 149 | |
150 | 150 |
user_formdef = get_publisher().user_class.get_formdef() |
151 | 151 |
new_user_data = {} |
wcs/workflows.py | ||
---|---|---|
1856 | 1856 |
return _('Change Status (not completed)') |
1857 | 1857 | |
1858 | 1858 |
def fill_form(self, form, formdata, user): |
1859 |
form.add_submit('button%s' % self.id, self.compute(self.label))
|
|
1859 |
form.add_submit('button%s' % self.id, compute(self.label)) |
|
1860 | 1860 |
if self.require_confirmation: |
1861 | 1861 |
get_response().add_javascript(['jquery.js', '../../i18n.js', 'qommon.js']) |
1862 | 1862 |
widget = form.get_widget('button%s' % self.id) |
... | ... | |
2010 | 2010 | |
2011 | 2011 |
url = formdata.get_url() |
2012 | 2012 |
try: |
2013 |
mail_body = template_on_formdata(formdata, self.compute(self.body, do_ezt=False))
|
|
2013 |
mail_body = template_on_formdata(formdata, compute(self.body, do_ezt=False)) |
|
2014 | 2014 |
except ezt.EZTException: |
2015 | 2015 |
get_logger().error('error in template for email body [%s], mail could not be generated' % url) |
2016 | 2016 |
return |
2017 | 2017 | |
2018 | 2018 |
try: |
2019 |
mail_subject = template_on_formdata(formdata, self.compute(self.subject, do_ezt=False))
|
|
2019 |
mail_subject = template_on_formdata(formdata, compute(self.subject, do_ezt=False)) |
|
2020 | 2020 |
except ezt.EZTException: |
2021 | 2021 |
get_logger().error('error in template for email subject [%s], mail could not be generated' % url) |
2022 | 2022 |
return |
... | ... | |
2032 | 2032 |
addresses = [] |
2033 | 2033 |
for dest in self.to: |
2034 | 2034 |
try: |
2035 |
dest = self.compute(dest, raises=True)
|
|
2035 |
dest = compute(dest, raises=True) |
|
2036 | 2036 |
except: |
2037 | 2037 |
continue |
2038 | 2038 | |
... | ... | |
2171 | 2171 |
if not self.body: |
2172 | 2172 |
return |
2173 | 2173 | |
2174 |
destinations = [self.compute(x) for x in self.to]
|
|
2174 |
destinations = [compute(x) for x in self.to] |
|
2175 | 2175 |
destinations = [x for x in destinations if x] # ignore empty elements |
2176 | 2176 |
if not destinations: |
2177 | 2177 |
return |
2178 | 2178 | |
2179 | 2179 |
try: |
2180 |
sms_body = template_on_formdata(formdata, self.compute(self.body, do_ezt=False))
|
|
2180 |
sms_body = template_on_formdata(formdata, compute(self.body, do_ezt=False)) |
|
2181 | 2181 |
except ezt.EZTException: |
2182 | 2182 |
url = formdata.get_url() |
2183 | 2183 |
get_logger().error('error in template for sms [%s], sms could not be generated' % url) |
2184 |
- |