def put(self, installation_id): c = Installation.query.filter_by(id=installation_id).first() if not c: raise HttpNotFoundException() json = get_fillable(Installation, **request.get_json()) for field, value in json.items(): setattr(c, field, value) data = request.get_json().copy() if 'panels' in data: InstallationPanelModel.query.filter_by( installation_id=installation_id).delete() for panel in data['panels']: db.session.add( InstallationPanelModel(installation_id=installation_id, model_id=panel['id'], quantity=int(panel['quantity']), serials=panel['serials'])) if 'inverters' in data: InstallationInverterModel.query.filter_by( installation_id=installation_id).delete() for inverter in data['inverters']: db.session.add( InstallationInverterModel(installation_id=installation_id, model_id=inverter['id'], quantity=int( inverter['quantity']), serials=inverter['serials'])) db.session.commit() return Result.success(code=201)
def put(self, customer_id): c = Customer.query.filter_by(id=customer_id).first() if not c: raise HttpNotFoundException() json = get_fillable(Customer, **request.get_json()) for field, value in json.items(): setattr(c, field, value) db.session.commit() return Result.success(code=201)
def put(self, project_id): project = CustomerProject.query.filter_by(id=project_id).first() if not project: raise HttpNotFoundException() json = get_fillable(CustomerProject, **request.get_json()) for field, value in json.items(): setattr(project, field, value) db.session.commit() return Result.success(code=201)
def put(self, installation_id): status = InstallationStatus.query.filter_by( installation_id=installation_id).first() if status is None: raise HttpNotFoundException() update = request.get_json().copy() for field, value in update.items(): if isinstance(value, str): setattr(status, field, local_to_utc(value)) elif isinstance(value, bool): setattr(status, field, value) db.session.commit() return Result.success(code=201)
def put(self, installation_id): financing = InstallationFinancing.query.filter_by( installation_id=installation_id).first() if financing is None: raise HttpNotFoundException() data = request.get_json().copy() if 'request_date' in data: data['request_date'] = local_to_utc(data['request_date']) if 'response_date' in data: data['response_date'] = local_to_utc(data['response_date']) for field, value in data.items(): setattr(financing, field, value) db.session.commit() return Result.success(code=201)
def put(self, installation_follow_up_id): data = request.get_json().copy() follow_up = InstallationFollowUp.query.filter_by( id=installation_follow_up_id).first() if follow_up is None: raise HttpNotFoundException() for key, value in data.items(): if key in InstallationFollowUp.fillable: setattr(follow_up, key, value) if 'comment' in data: follow_up.comments.append( InstallationFollowUpComment(user_id=request.user.id, comment=data['comment'])) db.session.commit() return Result.success(code=201)
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)
def get(self, group_id=None): if group_id is None: result = {} for item in self._get_user_groups_query().all(): if item.name not in result: result.update({item.name: {'name': item.name, 'id': item.id, 'users': []}}) result[item.name]['users'].append({ 'name': '{} {}'.format(item.first_name, item.last_name), 'id': item.id }) return result up = self._get_user_groups_query().filter(UserGroup.id == group_id).all() if len(up) == 0: raise HttpNotFoundException() result = {'users': []} for item in up: result['name'] = item.name result['id'] = item.id result['users'].append({'name': '{} {}'.format(item.first_name, item.last_name), 'id': item.user_id}) return result
def post(self): data = request.get_json().copy() if 'next_follow_up' in data: data['next_follow_up'] = local_to_utc(data['next_follow_up']) inst = Installation.query.filter_by(id=data['installation_id']).first() if inst is None: raise HttpNotFoundException() follow_up = InstallationFollowUp( **get_fillable(InstallationFollowUp, **data)) follow_up.user_id = request.user.id if 'comment' in data: follow_up.comments.append( InstallationFollowUpComment(user_id=request.user.id, comment=data['comment'])) inst.follow_ups.append(follow_up) db.session.commit() return Result.id(follow_up.id)
def get(self, installation_id): inst = Installation.query.filter_by(id=installation_id).first() if inst is None: raise HttpNotFoundException() egauge = EGaugeAPI(inst.egauge_url) return egauge.get_month_range_egauge()