0001-DRAFT-tests-needed-wcs-handle-network-error-on-reque.patch
combo/apps/wcs/models.py | ||
---|---|---|
61 | 61 |
if isinstance(forms_response_json, dict): |
62 | 62 |
# forward compability with future w.c.s. API |
63 | 63 |
forms_response_json = forms_response_json.get('data') |
64 |
for form in forms_response_json: |
|
64 |
for form in forms_response_json or []:
|
|
65 | 65 |
slug = form.get('slug') |
66 | 66 |
if slug == form_slug: |
67 | 67 |
self.cached_title = form.get('title') |
... | ... | |
133 | 133 |
wcs_key, category_slug = self.category_reference.split(':') |
134 | 134 |
wcs_site = get_wcs_services().get(wcs_key) |
135 | 135 |
categories_response_json = get_wcs_json(wcs_site, 'api/categories/') |
136 |
for category in categories_response_json.get('data'): |
|
136 |
for category in categories_response_json.get('data') or []:
|
|
137 | 137 |
slug = category.get('slug') |
138 | 138 |
if slug == category_slug: |
139 | 139 |
self.cached_title = category.get('title') |
combo/apps/wcs/utils.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 | |
17 |
from requests.exceptions import RequestException |
|
18 | ||
17 | 19 |
from django.conf import settings |
18 | 20 | |
19 | 21 |
from combo.utils import requests |
... | ... | |
27 | 29 |
return settings.KNOWN_SERVICES.get('wcs') |
28 | 30 | |
29 | 31 |
def get_wcs_json(wcs_site, path): |
30 |
response = requests.get(path, remote_service=wcs_site, without_user=True, |
|
31 |
headers={'accept': 'application/json'}) |
|
32 |
if response.status_code != 200: |
|
32 |
try: |
|
33 |
response = requests.get(path, remote_service=wcs_site, without_user=True, |
|
34 |
headers={'accept': 'application/json'}) |
|
35 |
response.raise_for_status() |
|
36 |
except RequestException: |
|
33 | 37 |
# the exact error will have been logged during request. |
34 |
return {} |
|
38 |
return {'err': 1, 'data': None}
|
|
35 | 39 |
return response.json() |
36 | 40 | |
37 | 41 |
def get_wcs_options(url, include_category_slug=False): |
38 |
- |