def get(self, request, *args, **kwargs): out = {'success': False, 'status': 'error', 'data': [], 'errors': {}} fields = ( 'field_name', 'steps', 'current_value', 'steps_calculated', 'unit', 'is_enabled', ) if auth.get_user(request).is_authenticated: obj = self.get_object() out['success'] = True out['status'] = 'ok' form = obj.get_user_form() fields = [dump(r, fields) for r in obj.definitions.all()] out['data'] = { 'form': form.as_table(), 'fields': fields, 'emails': obj.emails, 'notification': dump(obj) } status = 200 else: out['errors']['user'] = ['User is not authenticated'] status = 401 return json_response(out, status=status)
def get(self, request, *args, **kwargs): capi = CollectorAPI() checks = capi.get_notifications() data = {'status': 'ok', 'success': True, 'data': {}} d = data['data'] d['problems'] = problems = [] d['health_level'] = 'ok' _levels = ( 'fatal', 'error', 'warning', ) levels = set() for nc, ncdata in checks: for ncd in ncdata: levels.add(ncd.severity) problems.append(dump(ncd, self.fields)) if levels: for lyr in _levels: if lyr in levels: d['health_level'] = lyr break return json_response(data)
def post(self, request, *args, **kwargs): out = {'success': False, 'status': 'error', 'data': [], 'errors': {}} if auth.get_user(request).is_authenticated: obj = self.get_object() try: is_json = True data = json.loads(request.body) except ( TypeError, ValueError, ): is_json = False data = request.POST.copy() try: configs = obj.process_user_form(data, is_json=is_json) out['success'] = True out['status'] = 'ok' out['data'] = [dump(c) for c in configs] status = 200 except forms.ValidationError as err: out['errors'] = err.errors status = 400 else: out['errors']['user'] = ['User is not authenticated'] status = 401 return json_response(out, status=status)
def post(self, request, *args, **kwargs): out = {'success': False, 'status': 'error', 'data': [], 'errors': {}} status = 500 if request.user.is_authenticated(): obj = self.get_object() try: is_json = True data = json.loads(request.body) except (TypeError, ValueError,): is_json = False data = request.POST.copy() try: configs = obj.process_user_form(data, is_json=is_json) out['success'] = True out['status'] = 'ok' out['data'] = [dump(c) for c in configs] status = 200 except forms.ValidationError as err: out['errors'] = err.errors status = 400 else: out['errors']['user'] = ['User is not authenticated'] status = 401 return json_response(out, status=status)
def post(self, request, *args, **kwargs): out = {'success': False, 'status': 'error', 'data': [], 'errors': {}} d = self.create(request, *args, **kwargs) if d is None: out['errors'] = self.errors status = 400 else: out['data'] = dump(d) out['success'] = True out['status'] = 'ok' status = 200 return json_response(out, status=status)
def get(self, request, *args, **kwargs): out = {'success': False, 'status': 'error', 'data': [], 'errors': {}} status = 500 fields = ('field_name', 'steps', 'current_value', 'steps_calculated', 'unit', 'is_enabled',) if request.user.is_authenticated(): obj = self.get_object() out['success'] = True out['status'] = 'ok' form = obj.get_user_form() fields = [dump(r, fields) for r in obj.definitions.all()] out['data'] = {'form': form.as_table(), 'fields': fields, 'emails': obj.emails, 'notification': dump(obj)} status = 200 else: out['errors']['user'] = ['User is not authenticated'] status = 401 return json_response(out, status=status)
def get(self, request, *args, **kwargs): capi = CollectorAPI() checks = capi.get_notifications() data = {'status': 'ok', 'success': True, 'data': {}} d = data['data'] d['problems'] = problems = [] d['health_level'] = 'ok' _levels = ('fatal', 'error', 'warning',) levels = set([]) for nc, ncdata in checks: for ncd in ncdata: levels.add(ncd.severity) problems.append(dump(ncd, self.fields)) if levels: for l in _levels: if l in levels: d['health_level'] = l break return json_response(data)