def get(self): page = request.args.get('page', 1) total_pages = 1 q = request.args.get('query') if q: users = User.query.filter( (User.first_name.like('%' + q + '%')) | (User.last_name.like('%' + q + '%')) | (User.email.like('%' + q + '%')) ).all() else: paginator = Paginator(User.query, int(page), request.args.get('orderBy'), request.args.get('orderDir')) total_pages = paginator.total_pages users = paginator.get_result() user_list = list(map(lambda user: { 'first_name': user.first_name, 'last_name': user.last_name, 'name': user.first_name + ' ' + user.last_name, 'id': user.id, 'email': user.email, 'attributes': get_user_attr(user), 'roles': list(map(lambda r: { 'name': r.name, 'id': r.id }, user.roles)) }, users)) return Result.paginate(user_list, page, total_pages)
def get(self, customer_id=None): if customer_id: customer = Customer.query.options( joinedload('customer_projects'), joinedload('customer_projects.installations'), joinedload( 'customer_projects.installations.panels.panel_model'), joinedload( 'customer_projects.installations.inverters.inverter_model' ), joinedload( 'customer_projects.installations.installation_documents'), joinedload('customer_projects.installations.status'), joinedload('customer_projects.installations.financing'), joinedload('customer_projects.installations.financing.status'), joinedload( 'customer_projects.installations.financing.financial_entity' )).filter_by(id=customer_id) return Result.model(customer.first()) page = request.args.get('page', 1) total_pages = 1 q = request.args.get('query') if q: customers = Customer.query.filter( (Customer.first_name.like('%' + q + '%')) | (Customer.last_name.like('%' + q + '%')) | (Customer.primary_email.like('%' + q + '%')) | (Customer.primary_phone.like('%' + q + '%'))( Customer.identification_number.like('%' + q + '%'))).all() else: paginator = Paginator(Customer.query, int(page), request.args.get('orderBy', 'last_name'), request.args.get('orderDir', 'desc')) total_pages = paginator.total_pages customers = paginator.get_items() return Result.paginate(customers, page, total_pages)
def get(self, installation_id=None): page = int(request.args.get('page', 1)) if installation_id: docs = Installation.query.filter_by(id=installation_id).first() if docs: s3 = Storage(configs.UPLOAD_FILE_BUCKET) row = dict(docs) row['signed_urls'] = [] if docs: [ row['signed_urls'].append({ 'category': installation_document.category, 'name': installation_document.name, 'object': installation_document.object_key, 'url': Cache.remember( 'f_%s' % installation_document.object_key, lambda: s3.sign_url(installation_document. object_key), 14400) }) for installation_document in docs.installation_documents ] return row else: raise HttpNotFoundException() else: paginator = Paginator(InstallationDocument.query, page, request.args.get('orderBy'), request.args.get('orderDir')) total_pages = paginator.total_pages result = paginator.get_items() return Result.paginate(result, page, total_pages)