refactor: check license names before sending text
File might not exist.
This commit is contained in:
parent
011d21b4a3
commit
2ed85ca9f2
1 changed files with 10 additions and 3 deletions
|
|
@ -6,6 +6,12 @@ import os
|
|||
import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
LICENSES = (
|
||||
"GNU Affero General Public License",
|
||||
"GNU General Public License",
|
||||
"MIT License",
|
||||
)
|
||||
|
||||
|
||||
class Package(Document):
|
||||
# begin: auto-generated types
|
||||
|
|
@ -29,6 +35,7 @@ class Package(Document):
|
|||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_license_text(license_type):
|
||||
with open(os.path.join(os.path.dirname(__file__), "licenses", license_type + ".md")) as textfile:
|
||||
return textfile.read()
|
||||
def get_license_text(license_type: str) -> str | None:
|
||||
if license_type in LICENSES:
|
||||
with open(os.path.join(os.path.dirname(__file__), "licenses", license_type + ".md")) as textfile:
|
||||
return textfile.read()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue