def get(self): current_reader = self.require_current_reader() read_key = self.get_str('read_key') read = Read.get_read(read_key) if current_reader.key() != read.meter.reader.key(): self.return_forbidden() self.return_ok(self.page_fields(current_reader, read))
def post(self): current_reader = self.require_current_reader() read_key = self.post_str('read_key') read = Read.get_read(read_key) try: meter = read.meter if current_reader.key() != meter.reader.key(): self.return_forbidden() if 'update' in self.request.POST: meter.send_read_to = self.post_str('send_read_to').strip() meter.send_read_name = self.post_str('send_read_name').strip() meter.send_read_reader_email = self.post_str( 'send_read_reader_email').strip() meter.send_read_address = self.post_str( 'send_read_address').strip() meter.send_read_postcode = self.post_str( 'send_read_postcode').strip() meter.send_read_account = self.post_str( 'send_read_account').strip() meter.send_read_msn = self.post_str('send_read_msn').strip() meter.put() fields = self.page_fields(current_reader, read) fields['message'] = "Info updated successfully." self.return_ok(fields) else: if meter.send_read_to is None or len(meter.send_read_to) == 0: raise HTTPBadRequest( """The supplier's email address must be filled in.""") body = jinja2.Template("""Hi, I'd like to submit a \ reading for my {{ read.meter.utility_id }} meter. Details below: My Name: {{ read.meter.send_read_name }} My Email Address: {{ read.meter.send_read_reader_email }} First Line Of Postal Address Of Meter: {{ read.meter.send_read_address }} Postcode Of Meter: {{ read.meter.send_read_postcode }} Account Number: {{ read.meter.send_read_account }} Meter Serial Number: {{ read.meter.send_read_msn }} Read Date: {{ read.local_read_date().strftime("%Y-%m-%d %H:%M") }} Reading: {{ read.value }} {{ read.meter.units }}""").render(read=read) mail.send_mail( sender="MtrHub <*****@*****.**>", to=meter.send_read_to, cc=meter.send_read_reader_email, reply_to=meter.send_read_reader_email, subject="My " + meter.utility_id + " meter reading", body=body) meter.latest_customer_read_date = read.read_date meter.put() fields = self.page_fields(current_reader, read) fields['message'] = "Reading sent successfully." self.return_ok(fields) except HTTPBadRequest as e: self.return_bad_request(self.page_fields(current_reader, read, e))
def get(self): current_reader = self.find_current_reader() read_key = self.get_str("read_key") read = Read.get_read(read_key) meter = read.meter if meter.is_public: self.return_ok(self.page_fields(current_reader, read)) elif current_reader is None: self.return_unauthorized() elif current_reader.key() == meter.reader.key(): self.return_ok(self.page_fields(current_reader, read)) else: self.return_forbidden()
def post(self): current_reader = self.require_current_reader() read_key = self.post_str("read_key") read = Read.get_read(read_key) try: meter = read.meter if current_reader.key() != meter.reader.key(): self.return_forbidden() if 'delete' in self.request.POST: read.delete() self.return_see_other( "/view_meter?meter_key=" + str(meter.key())) else: read_date = self.post_datetime("read") value = self.post_float("value") read.update(read_date, value) self.add_flash("Read edited successfully.") self.return_see_other("/view_read?read_key=" + str(read.key())) except HTTPBadRequest as e: self.return_bad_request(self.page_fields(current_reader, read, e))
def get(self): current_reader = self.require_current_reader() read_key = self.get_str("read_key") read = Read.get_read(read_key) self.return_ok(self.page_fields(current_reader, read))