- Airplane Flight must not return status code 417 if flight document is published, check if you have enabled web view properly
- Airplane Flight must return 404 if flight document is not published
I have done all things of day 2 assignment, But got 1 issue and I am working on it from last 2 days and still not found any solution
My code is given below
Copyright (c) 2024, Bharat Bisen and contributors
For license information, please see license.txt
import frappe
from frappe.website.website_generator import WebsiteGenerator
class AirplaneFlight(WebsiteGenerator):
def before_submit(self):
self.status = "Completed"
def before_save(self):
self.is_published = True
def get_context(self, context):
flight = frappe.get_doc("Airplane Flight", self.name)
if not flight.is_published:
raise frappe.DoesNotExistError(frappe._("Flight not found"))
context.flight_duration = self.format_flight_duration(flight.duration_of_flight)
context.title = flight.flight_number
context.doc = flight
def format_flight_duration(self, duration):
total_seconds = float(duration)
hours = int(total_seconds // 3600)
minutes = int((total_seconds % 3600) // 60)
return f"{hours}h {minutes}m"