Skip to content

Instantly share code, notes, and snippets.

@mford22392
Created May 28, 2020 21:21
Show Gist options
  • Save mford22392/7baf76025f728d221ba3874172290786 to your computer and use it in GitHub Desktop.
Save mford22392/7baf76025f728d221ba3874172290786 to your computer and use it in GitHub Desktop.
class ProgramsAndApplicationsAccordion:
def __init__(self, data_store):
self.data_store = data_store
self.default = self.programs_and_applications_tabs_default()
def calculate_weights(self):
weights = {
"key": "programs_and_applications",
"weight": 90,
"children": [
{
"key": "explore_tab",
"weight": self.handle_default_tab("explore_tab"),
"children": self.explore_tab_children,
},
{
"key": "coach_recommendations_tab",
"weight": self.handle_default_tab("coach_recommendations_tab"),
"children": None
},
{
"key": "bookmarks_tab",
"weight": self.handle_default_tab("bookmarks_tab"),
"children": None
},
{
"key": "applications_tab",
"weight": self.handle_default_tab("applications_tab"),
"children": None
}
]
}
return weights
@property
def any_apps_or_bookmarks(self):
return self.data_store.any_apps or self.data_store.bookmarks
@property
def hide_tab_for_career_oriented(self):
return self.data_store.supports_career_oriented_programs_and_apps and not self.any_apps_or_bookmarks
@property
def explore_tab_children(self):
explore_weights = self.handle_explore_tab_weights()
keys = ["find_programs", "view_quiz_results", "view_programs", "career", "jobs"]
children = [
{
"key": key,
"weight": explore_weights[key],
"children": None
} for key in keys
]
return children
def handle_explore_tab_weights(self):
default = {
"explore_tab": self.handle_default_tab("explore_tab"),
"find_programs": 0 if self.data_store.quiz_results else 100,
"view_quiz_results": 100 if self.data_store.quiz_results else 0,
"view_programs": 90,
"career": 0,
"jobs": 0
}
if self.data_store.supports_career_oriented_programs_and_apps:
default.update({
"find_programs": 0,
"view_quiz_results": 0,
"view_programs": 0,
"career": 100,
"jobs": 90
})
return default
def handle_default_tab(self, tab_name):
return 100 if self.default == tab_name else self.non_default_weights[tab_name]
def programs_and_applications_tabs_default(self):
if self.data_store.any_apps:
return "applications_tab"
elif self.data_store.coach_recommendations:
return "coach_recommendations_tab"
elif self.data_store.bookmarks:
return "bookmarks_tab"
else:
return "explore_tab"
@property
def non_default_weights(self):
return {
"applications_tab": 0 if self.hide_tab_for_career_oriented else 10,
"bookmarks_tab": 0 if self.hide_tab_for_career_oriented else 10,
"coach_recommendations_tab": 10,
"explore_tab": 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment