Merge pull request #39 from danieldupriest/example_policy

Created example policy config file
This commit is contained in:
Logan Miller 2019-01-28 13:53:44 -08:00 committed by GitHub
commit 0a930a21ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 81 deletions

View file

@ -2,26 +2,26 @@ import hashlib
hasher = hashlib.md5() hasher = hashlib.md5()
with open ('simple_policy.py', 'rb') as afile: with open ('simple_policy.py', 'rb') as afile:
buf = afile.read() buf = afile.read()
hasher.update(buf) hasher.update(buf)
print("md5 of simple: " + hasher.hexdigest()) print("md5 of simple: " + hasher.hexdigest())
hasher = hashlib.md5() hasher = hashlib.md5()
with open ('moderate_policy.py', 'rb') as afile: with open ('moderate_policy.py', 'rb') as afile:
buf = afile.read() buf = afile.read()
hasher.update(buf) hasher.update(buf)
print("md5 of moderate: " + hasher.hexdigest()) print("md5 of moderate: " + hasher.hexdigest())
hasher = hashlib.sha1() hasher = hashlib.sha1()
with open ('simple_policy.py', 'rb') as afile: with open ('simple_policy.py', 'rb') as afile:
buf = afile.read() buf = afile.read()
hasher.update(buf) hasher.update(buf)
print("sha1 of simple: " + hasher.hexdigest()) print("sha1 of simple: " + hasher.hexdigest())
hasher = hashlib.sha1() hasher = hashlib.sha1()
with open ('moderate_policy.py', 'rb') as afile: with open ('moderate_policy.py', 'rb') as afile:
buf = afile.read() buf = afile.read()
hasher.update(buf) hasher.update(buf)
print("sha1 of moderate: " + hasher.hexdigest()) print("sha1 of moderate: " + hasher.hexdigest())

View file

@ -9,22 +9,22 @@ from datetime import date
#### General #### General
#### Section 0 #### Section 0
general_section = Section( general_section = Section(
title = "General Info", title = "General Info",
html_description = "", html_description = "",
fields = { fields = {
"destination": {"label": "Destination City", "type": "string"} "destination": {"label": "Destination City", "type": "string"}
} }
) )
general_section.add_rule( general_section.add_rule(
title = "Destination city check", title = "Destination city check",
rule = lambda report, section: rule = lambda report, section:
if section.fields.destination == "Timbuktu": if section.fields.destination == "Timbuktu":
return True return True
else: else:
return False return False
, ,
rule_break_text = "What did the cowboy say about Tim, his wild horse?" rule_break_text = "What did the cowboy say about Tim, his wild horse?"
) )
@ -32,22 +32,22 @@ general_section.add_rule(
#### Flight #### Flight
#### Section 1 #### Section 1
flight_section = Section( flight_section = Section(
title = "Flight Info", title = "Flight Info",
html_description = "<p>Enter flight details here.</p>", html_description = "<p>Enter flight details here.</p>",
fields = { fields = {
"international": {"label": "Is this an international flight?", "type": "boolean"}, "international": {"label": "Is this an international flight?", "type": "boolean"},
"departure_date": {"label": "Departure date", "type": "date"}, "departure_date": {"label": "Departure date", "type": "date"},
"return_date": {"label": "Return date", "type": "date"}, "return_date": {"label": "Return date", "type": "date"},
"fare": {"label": "Fare", "type": "decimal"}, "fare": {"label": "Fare", "type": "decimal"},
} }
) )
flight_section.add_rule( flight_section.add_rule(
title = "Airline fare pre-approval check", title = "Airline fare pre-approval check",
rule = lambda report, section: rule = lambda report, section:
return section.fields.fare < 500 return section.fields.fare < 500
, ,
rule_break_text = "Fares cannot be more than $500" rule_break_text = "Fares cannot be more than $500"
) )
@ -55,25 +55,25 @@ flight_section.add_rule(
#### Lodging #### Lodging
#### Section 2 #### Section 2
lodging_section = Section( lodging_section = Section(
title = "Hotel Info", title = "Hotel Info",
html_description = "<p>Enter hotel info here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>", html_description = "<p>Enter hotel info here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>",
fields = { fields = {
"check-in_date": {"label": "Check-in date", "type": "date"}, "check-in_date": {"label": "Check-in date", "type": "date"},
"check-out_date": {"label": "Check-out date", "type": "date"}, "check-out_date": {"label": "Check-out date", "type": "date"},
"rate": {"label": "Per diem nightly rate", "type": "decimal"}, "rate": {"label": "Per diem nightly rate", "type": "decimal"},
"cost": {"label": "Total Cost", "type": "decimal"} "cost": {"label": "Total Cost", "type": "decimal"}
} }
) )
section.add_rule( section.add_rule(
title = "", title = "",
rule = lambda report, section: rule = lambda report, section:
check-in_date = date(section.fields.check-in_date) check-in_date = date(section.fields.check-in_date)
check-out_date = date(section.fields.check-out_date) check-out_date = date(section.fields.check-out_date)
duration = check-out_date - check-in_date duration = check-out_date - check-in_date
return section.fields.cost <= duration * section.fields.rate return section.fields.cost <= duration * section.fields.rate
, ,
rule_break_text = "The average nightly rate cannot be more than the USGSA rate." rule_break_text = "The average nightly rate cannot be more than the USGSA rate."
) )
@ -82,20 +82,20 @@ section.add_rule(
#### Local Transportation #### Local Transportation
#### Section 3 #### Section 3
transport_section = Section( transport_section = Section(
title = "Local Transportation", title = "Local Transportation",
html_description = "<p>How much did you spend on local transportation, in total?</p>", html_description = "<p>How much did you spend on local transportation, in total?</p>",
fields = { fields = {
"duration": {"label": "How many days was your trip?", "type": "decimal"}, "duration": {"label": "How many days was your trip?", "type": "decimal"},
"cost": {"label": "Total cost", "type": "decimal"} "cost": {"label": "Total cost", "type": "decimal"}
} }
) )
transport_section.add_rule( transport_section.add_rule(
title = "Total cost check", title = "Total cost check",
rule = lambda report, section: rule = lambda report, section:
return section.fields.cost <= section.fields.duration * 10 return section.fields.cost <= section.fields.duration * 10
, ,
rule_break_text = "Local transportation costs must be less than $10 per day, on average." rule_break_text = "Local transportation costs must be less than $10 per day, on average."
) )
@ -104,38 +104,38 @@ transport_section.add_rule(
#### Per Diem #### Per Diem
#### Section 4 #### Section 4
per_diem_section = Section( per_diem_section = Section(
title = "Per Diem", title = "Per Diem",
html_description = "<p>Enter info about meals and incidentals here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>", html_description = "<p>Enter info about meals and incidentals here.\nPer diem rates can be found at <a href='https://www.gsa.gov/travel/plan-book/per-diem-rates'></a></p>",
fields = { fields = {
"duration": {"label": "How many days was your trip?", "type": "decimal"}, "duration": {"label": "How many days was your trip?", "type": "decimal"},
"rate": {"label": "What is the per diem rate for your destination?", "type": "decimal"}, "rate": {"label": "What is the per diem rate for your destination?", "type": "decimal"},
"cost": {"label": "Total Cost for meals and incidentals", "type": "decimal"} "cost": {"label": "Total Cost for meals and incidentals", "type": "decimal"}
} }
) )
per_diem_section.add_rule( per_diem_section.add_rule(
title = "Per Diem Cost Check", title = "Per Diem Cost Check",
rule = lambda report, section: rule = lambda report, section:
return section.fields.cost <= section.fields.duration * section.fields.rate return section.fields.cost <= section.fields.duration * section.fields.rate
, ,
rule_break_text = "The average cost per day for per diem expenses cannot be more than the rate specified by the USGSA." rule_break_text = "The average cost per day for per diem expenses cannot be more than the rate specified by the USGSA."
) )
''' '''
Section( Section(
title = "", title = "",
html_description = "<p></p>", html_description = "<p></p>",
fields = { fields = {
"": {"label": "", "type": ""} "": {"label": "", "type": ""}
} }
) )
section.add_rule( section.add_rule(
title = "", title = "",
rule = lambda report, section: return boolean_statement, rule = lambda report, section: return boolean_statement,
rule_break_text = "" rule_break_text = ""
) )
#// or, for a rule which doesnt apply to a specific section... #// or, for a rule which doesnt apply to a specific section...