def get_data_hs(code, field, field_value): # TODO: try-except obj = Dictionary(code) obj_names = DictionaryNames() document = obj.get_document({str(field): field_value}) origin_dict = obj_names.get_by_code(code) if 'oid' in origin_dict: # Работаем с НСИ справочником data = document oid = origin_dict['oid'] else: try: try: linked_dict = _get_linked_dict(document, origin_dict) except AttributeError: raise InvalidAPIUsage(u'Not found', status_code=404) except KeyError: raise InvalidAPIUsage(u'Not found', status_code=404) if not document: return make_response( vesta_jsonify( dict(oid=linked_dict['oid'], message="not found")), 404) except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except InvalidId, e: raise InvalidAPIUsage(e.message, status_code=404)
def get(self, code, document_id): if document_id is None: return self.list_documents(code) else: result = self.document_details(code, document_id) if not result: abort(404) return vesta_jsonify(result)
def get(self, code): """Получение списка клиентов или информации по конкретному клиенту""" collection = Clients() if code is None: # return list of Clients try: result = collection.get_list() except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except ValueError, e: return vesta_jsonify(dict())
def get(self, code): """Получение списка справочников или информации по конкретному справочнику""" collection = DictionaryNames() if code is None: # return list of Dictionaries try: result = collection.get_list() except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except ValueError, e: return vesta_jsonify(dict())
class ClientsAPI(MethodView, APIMixin): """API для работы с информацией о зарегистрированных клиентах (внешних системах)""" #decorators = [user_required] def get(self, code): """Получение списка клиентов или информации по конкретному клиенту""" collection = Clients() if code is None: # return list of Clients try: result = collection.get_list() except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except ValueError, e: return vesta_jsonify(dict()) return vesta_jsonify(dict(data=list(result)))
class DictionaryNamesAPI(MethodView, APIMixin): """API для работы с информацией о справочниках""" #decorators = [user_required] def get(self, code): """Получение списка справочников или информации по конкретному справочнику""" collection = DictionaryNames() if code is None: # return list of Dictionaries try: result = collection.get_list() except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except ValueError, e: return vesta_jsonify(dict()) return vesta_jsonify(data=list(result))
def get_linked_data(code, field, field_value): # TODO: try-except obj = Dictionary(code) obj_names = DictionaryNames() document = obj.get_document({str(field): field_value}) try: origin_dict = obj_names.get_by_code(code) try: linked_dict = _get_linked_dict(document, origin_dict) except AttributeError: raise InvalidAPIUsage(u'Not found', status_code=404) except KeyError: raise InvalidAPIUsage(u'Not found', status_code=404) if not document: return make_response( vesta_jsonify(dict(oid=linked_dict['oid'], data={})), 200) except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400)
collection = Clients() if code is None: # return list of Clients try: result = collection.get_list() except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except ValueError, e: return vesta_jsonify(dict()) return vesta_jsonify(dict(data=list(result))) else: # return Dictionary info by code result = collection.get_by_code(code) if result is None: result = dict() return vesta_jsonify(result) def post(self): """Заведение информации о клиенте""" data = self.parse_request(request) obj = Clients() try: _id = obj.add(data) except TypeError, e: raise InvalidAPIUsage(e.message, status_code=400) except AttributeError, e: raise InvalidAPIUsage(e.message, status_code=400) else: if _id: return make_response(vesta_jsonify(dict(_id=str(_id))), 201) raise InvalidAPIUsage(u'Ошибка добавления данных', 500)
def get_documents(code=None): if code: obj = Dictionary(code) data = obj.get_list() return vesta_jsonify(result=list(data))