def app_settings(request, domain): if request.method == 'GET': apps = get_cloudcare_apps(domain) access = ApplicationAccess.get_template_json(domain, apps) groups = Group.by_domain(domain) return render(request, 'cloudcare/config.html', { 'domain': domain, 'apps': apps, 'groups': groups, 'access': access, }) elif request.method == 'PUT': j = json.loads(request.raw_post_data) old = ApplicationAccess.get_by_domain(domain) new = ApplicationAccess.wrap(j) old.restrict = new.restrict old.app_groups = new.app_groups try: if old._rev != new._rev or old._id != new._id: raise ResourceConflict() old.save() except ResourceConflict: return HttpResponseConflict() else: return json_response({'_rev': old._rev})
def test_form_pillow_error_in_form_metadata(self): self.assertEqual(0, PillowError.objects.filter(pillow=self.pillow_id).count()) with patch('pillowtop.processors.form.mark_latest_submission') as mark_latest_submission: mark_latest_submission.side_effect = ResourceConflict('couch sucks') case_id, case_name = self._create_form_and_sync_to_es() # confirm change made it to form index results = FormES().run() self.assertEqual(1, results.total) self.assertEqual(1, PillowError.objects.filter(pillow=self.pillow_id).count())
def put(self, request, *args, **kwargs): j = json.loads(request.body.decode('utf-8')) old = ApplicationAccess.get_by_domain(self.domain) new = ApplicationAccess.wrap(j) old.restrict = new.restrict old.app_groups = new.app_groups try: if old._rev != new._rev or old._id != new._id: raise ResourceConflict() old.save() except ResourceConflict: return HttpResponseConflict() else: return json_response({'_rev': old._rev})
def apply_update(doc, update_fn, max_tries=5): """ A function for safely applying a change to a couch doc. For getting around ResourceConflict errors that stem from the distributed cloudant nodes """ tries = 0 while tries < max_tries: try: update_fn(doc) doc.save() return doc except ResourceConflict: doc = doc.__class__.get(doc._id) tries += 1 raise ResourceConflict("Document update conflict. -- Max Retries Reached")