def add_individual_post_pages (page_dict, post_dict): category =post_dict ["category"] specific_sidebar_contents = sidebars [category] if category == "stories": specific_sidebar_contents = '''<a class="sidebar_standalone_link" href="'''+post_permalink(post_dict)+'''/discussion">Author's notes and comments for '''+post_dict["title"]+'''</a>'''+ specific_sidebar_contents (HTML, head) = post_dict_html(post_dict) extras = {} if "after_body" in post_dict: extras ["after_body"] = post_dict ["after_body"] if "blurb" in post_dict: extras ["blurb"] = post_dict ["blurb"] utils.make_page (page_dict, post_dict["path_prefix"]+url_formatted_title(post_dict), title_formatted_title(post_dict)+("" if (category == "") else " ⊂ "+utils.capitalize_string(category))+" ⊂ Eli Dupree's website", head, make_blog_page_body(HTML, specific_sidebar_contents), extras ) if category == "stories": disc_specific_sidebar_contents = '''<a class="sidebar_standalone_link" href="'''+post_permalink(post_dict)+'''">Return to '''+post_dict["title"]+'''</a>'''+sidebars [category] discussion_post = { "title": post_dict["title"]+": Discussion", "contents": '''<p>If you haven't read <a href="'''+post_permalink(post_dict)+'''">'''+post_dict["title"]+'''</a> yet, you should do that before reading further.</p>'''+(post_dict["authors_notes"] if "authors_notes" in post_dict else "<p>There are no author's notes yet.</p>"), "parent_story": post_dict["title"], "category": "" # Not treated as a story. } (HTML, head) = post_dict_html(discussion_post) utils.make_page (page_dict, post_dict["path_prefix"]+url_formatted_title(post_dict)+'/discussion', title_formatted_title(discussion_post)+" ⊂ "+utils.capitalize_string(category)+" ⊂ Eli Dupree's website", head, make_blog_page_body(HTML, disc_specific_sidebar_contents) )
def add_individual_post_pages (page_dict, post_dict): category =post_dict ["category"] specific_sidebar_contents = sidebars [category] if category == "stories": specific_sidebar_contents = '''<a class="sidebar_standalone_link" href="'''+post_permalink(post_dict)+'''/discussion">Author's notes and comments for '''+post_dict["title"]+'''</a>'''+ specific_sidebar_contents (HTML, head) = post_dict_html(post_dict) extras = {} if "after_body" in post_dict: extras ["after_body"] = post_dict ["after_body"] if "blurb" in post_dict: extras ["blurb"] = post_dict ["blurb"] if "blurb_image" in post_dict: extras ["blurb_image"] = post_dict ["blurb_image"] utils.make_page (page_dict, post_permalink(post_dict), title_formatted_title(post_dict)+("" if (category == "") else " ⊂ "+utils.capitalize_string(category))+" ⊂ Eli Dupree's website", head, make_blog_page_body(HTML, specific_sidebar_contents), extras ) if category == "stories": disc_specific_sidebar_contents = '''<a class="sidebar_standalone_link" href="'''+post_permalink(post_dict)+'''">Return to '''+post_dict["title"]+'''</a>'''+sidebars [category] discussion_post = story_discussion_post(post_dict) (HTML, head) = post_dict_html(discussion_post) utils.make_page (page_dict, post_permalink(discussion_post), title_formatted_title(discussion_post)+" ⊂ "+utils.capitalize_string(category)+" ⊂ Eli Dupree's website", head, make_blog_page_body(HTML, disc_specific_sidebar_contents) )
def test_capitalize_string(self): s = utils.capitalize_string(None) self.assertEqual(s, None) s = utils.capitalize_string('') self.assertEqual(s, '') s = utils.capitalize_string('a') self.assertEqual(s, 'A') s = utils.capitalize_string('A') self.assertEqual(s, 'A') s = utils.capitalize_string('1') self.assertEqual(s, '1') s = utils.capitalize_string('lowercase') self.assertEqual(s, 'Lowercase') s = utils.capitalize_string('UPPERCASE') self.assertEqual(s, 'UPPERCASE') s = utils.capitalize_string('Partially') self.assertEqual(s, 'Partially') s = utils.capitalize_string('2be') self.assertEqual(s, '2be')
def get(self, collection_id): """Handles GET requests.""" try: collection = collection_services.get_collection_by_id( collection_id) except Exception as e: raise self.PageNotFoundException(e) collection_rights = rights_manager.get_collection_rights(collection_id, strict=False) self.values.update({ 'nav_mode': feconf.NAV_MODE_COLLECTION, 'can_edit': rights_manager.check_can_edit_activity(self.user, collection_rights), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('pages/collection_player/collection_player.html')
def _get_exploration_player_data( exploration_id, version, collection_id, can_edit): try: exploration = exp_services.get_exploration_by_id( exploration_id, version=version) except Exception: raise Exception collection_title = None if collection_id: try: collection = collection_services.get_collection_by_id( collection_id) collection_title = collection.title except Exception: raise Exception version = exploration.version # TODO(sll): Cache these computations. gadget_types = exploration.get_gadget_types() interaction_ids = exploration.get_interaction_ids() dependency_ids = ( interaction_registry.Registry.get_deduplicated_dependency_ids( interaction_ids)) dependencies_html, additional_angular_modules = ( dependency_registry.Registry.get_deps_html_and_angular_modules( dependency_ids)) gadget_templates = ( gadget_registry.Registry.get_gadget_html(gadget_types)) interaction_templates = ( rte_component_registry.Registry.get_html_for_all_components() + interaction_registry.Registry.get_interaction_html( interaction_ids)) return { 'GADGET_SPECS': gadget_registry.Registry.get_all_specs(), 'INTERACTION_SPECS': interaction_registry.Registry.get_all_specs(), 'DEFAULT_TWITTER_SHARE_MESSAGE_PLAYER': ( DEFAULT_TWITTER_SHARE_MESSAGE_PLAYER.value), 'additional_angular_modules': additional_angular_modules, 'can_edit': can_edit, 'dependencies_html': jinja2.utils.Markup( dependencies_html), 'exploration_title': exploration.title, 'exploration_version': version, 'collection_id': collection_id, 'collection_title': collection_title, 'gadget_templates': jinja2.utils.Markup(gadget_templates), 'interaction_templates': jinja2.utils.Markup( interaction_templates), 'is_private': rights_manager.is_exploration_private( exploration_id), # Note that this overwrites the value in base.py. 'meta_name': exploration.title, # Note that this overwrites the value in base.py. 'meta_description': utils.capitalize_string(exploration.objective), 'nav_mode': feconf.NAV_MODE_EXPLORE, }
def get(self, collection_id): """Handles GET requests.""" try: collection = collection_services.get_collection_by_id( collection_id) except Exception as e: raise self.PageNotFoundException(e) whitelisted_usernames = ( config_domain.WHITELISTED_COLLECTION_EDITOR_USERNAMES.value) self.values.update({ 'nav_mode': feconf.NAV_MODE_COLLECTION, 'can_edit': ( bool(self.username) and self.username in whitelisted_usernames and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( feconf.ACTIVITY_TYPE_COLLECTION, collection_id) ), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'collection_skills': collection.skills, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('collection_player/collection_player.html')
def get(self, collection_id): """Handles GET requests.""" try: collection = collection_services.get_collection_by_id( collection_id) except Exception as e: raise self.PageNotFoundException(e) self.values.update({ 'can_edit': (bool(self.username) and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( rights_manager.ACTIVITY_TYPE_COLLECTION, collection_id)), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('collection_player/collection_player.html')
def get(self, collection_id): """Handles GET requests.""" (collection, collection_rights) = ( collection_services.get_collection_and_collection_rights_by_id( collection_id)) if collection is None: raise self.PageNotFoundException self.values.update({ 'can_edit': rights_manager.check_can_edit_activity(self.user, collection_rights), 'is_logged_in': bool(self.user_id), 'collection_id': collection_id, 'collection_title': collection.title, 'is_private': rights_manager.is_collection_private(collection_id), 'meta_name': collection.title, 'meta_description': utils.capitalize_string(collection.objective) }) self.render_template('pages/collection_player/collection_player.html')
def _get_exploration_player_data( exploration_id, version, collection_id, can_edit): """Returns a dict of exploration player data. Args: exploration_id: str. The ID of the exploration. version: int or None. The version of the exploration. collection_id: str. ID of the collection. can_edit: bool. Whether the given user can edit this activity. Returns: dict. A dict of exploration player data. The keys and values of the dict are as follows: - 'can_edit': bool. Whether the given user can edit this activity. - 'exploration_title': str. Title of exploration. - 'exploration_version': int. The version of the exploration. - 'collection_id': str. ID of the collection. - 'collection_title': str. Title of collection. required by the given exploration ID. - 'is_private': bool. Whether the exploration is private or not. - 'meta_name': str. Title of exploration. - 'meta_description': str. Objective of exploration. """ try: exploration = exp_fetchers.get_exploration_by_id( exploration_id, version=version) except Exception: raise Exception collection_title = None if collection_id: try: collection = collection_services.get_collection_by_id( collection_id) collection_title = collection.title except Exception: raise Exception version = exploration.version return { 'can_edit': can_edit, 'exploration_title': exploration.title, 'exploration_version': version, 'collection_id': collection_id, 'collection_title': collection_title, 'is_private': rights_manager.is_exploration_private( exploration_id), # Note that this overwrites the value in base.py. 'meta_name': exploration.title, # Note that this overwrites the value in base.py. 'meta_description': utils.capitalize_string(exploration.objective), }
def test_capitalize_string(self) -> None: test_data: List[List[str]] = [ ['', ''], ['a', 'A'], ['A', 'A'], ['1', '1'], ['lowercase', 'Lowercase'], ['UPPERCASE', 'UPPERCASE'], ['Partially', 'Partially'], ['miDdle', 'MiDdle'], ['2be', '2be'], ] for datum in test_data: self.assertEqual(utils.capitalize_string(datum[0]), datum[1])
def test_capitalize_string(self): test_data = [ [None, None], ['', ''], ['a', 'A'], ['A', 'A'], ['1', '1'], ['lowercase', 'Lowercase'], ['UPPERCASE', 'UPPERCASE'], ['Partially', 'Partially'], ['miDdle', 'MiDdle'], ['2be', '2be'], ] for datum in test_data: self.assertEqual(utils.capitalize_string(datum[0]), datum[1])
def get(self, collection_id): """Populates the data on the individual collection page.""" collection_dict = (summary_services.get_learner_collection_dict_by_id( collection_id, self.user, allow_invalid_explorations=False)) collection_rights = rights_manager.get_collection_rights(collection_id, strict=False) self.values.update({ 'can_edit': rights_manager.check_can_edit_activity(self.user, collection_rights), 'collection': collection_dict, 'is_logged_in': bool(self.user_id), 'session_id': utils.generate_new_session_id(), 'meta_name': collection_dict['title'], 'meta_description': utils.capitalize_string(collection_dict['objective']) }) self.render_json(self.values)
def _get_exploration_player_data( exploration_id, version, collection_id, can_edit): """Returns a dict of exploration player data. Args: exploration_id: str. The ID of the exploration. version: int or None. The version of the exploration. collection_id: str. ID of the collection. can_edit: bool. Whether the given user can edit this activity. Returns: dict. A dict of exploration player data. The keys and values of the dict are as follows: - 'INTERACTION_SPECS': dict. A dict containing the full specs of each interaction. Contains interaction ID and a list of instances of all interactions. - 'additional_angular_modules': list. A de-duplicated list of strings, each representing an additional angular module that should be loaded. - 'can_edit': bool. Whether the given user can edit this activity. - 'dependencies_html': str. The additional HTML to insert on the page. - 'exploration_title': str. Title of exploration. - 'exploration_version': int. The version of the exploration. - 'collection_id': str. ID of the collection. - 'collection_title': str. Title of collection. - 'interaction_templates': str. The HTML bodies of the interactions required by the given exploration ID. - 'is_private': bool. Whether the exploration is private or not. - 'meta_name': str. Title of exploration. - 'meta_description': str. Objective of exploration. """ try: exploration = exp_fetchers.get_exploration_by_id( exploration_id, version=version) except Exception: raise Exception collection_title = None if collection_id: try: collection = collection_services.get_collection_by_id( collection_id) collection_title = collection.title except Exception: raise Exception version = exploration.version # TODO(sll): Cache these computations. interaction_ids = exploration.get_interaction_ids() for interaction_id in feconf.ALLOWED_QUESTION_INTERACTION_IDS: if interaction_id not in interaction_ids: interaction_ids.append(interaction_id) dependency_ids = ( interaction_registry.Registry.get_deduplicated_dependency_ids( interaction_ids)) dependencies_html, additional_angular_modules = ( dependency_registry.Registry.get_deps_html_and_angular_modules( dependency_ids)) interaction_templates = ( interaction_registry.Registry.get_interaction_html( interaction_ids)) return { 'INTERACTION_SPECS': interaction_registry.Registry.get_all_specs(), 'additional_angular_modules': additional_angular_modules, 'can_edit': can_edit, 'dependencies_html': jinja2.utils.Markup( dependencies_html), 'exploration_title': exploration.title, 'exploration_version': version, 'collection_id': collection_id, 'collection_title': collection_title, 'interaction_templates': jinja2.utils.Markup( interaction_templates), 'is_private': rights_manager.is_exploration_private( exploration_id), # Note that this overwrites the value in base.py. 'meta_name': exploration.title, # Note that this overwrites the value in base.py. 'meta_description': utils.capitalize_string(exploration.objective), }
def get(self, exploration_id): """Handles GET requests.""" version_str = self.request.get('v') version = int(version_str) if version_str else None # Note: this is an optional argument and will be None when the # exploration is being played outside the context of a collection. collection_id = self.request.get('collection_id') try: exploration = exp_services.get_exploration_by_id(exploration_id, version=version) except Exception as e: raise self.PageNotFoundException(e) collection_title = None if collection_id: try: collection = collection_services.get_collection_by_id( collection_id) collection_title = collection.title except Exception as e: raise self.PageNotFoundException(e) version = exploration.version if not rights_manager.Actor(self.user_id).can_view( feconf.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.PageNotFoundException is_iframed = (self.request.get('iframed') == 'true') # TODO(sll): Cache these computations. gadget_types = exploration.get_gadget_types() interaction_ids = exploration.get_interaction_ids() dependency_ids = (interaction_registry.Registry. get_deduplicated_dependency_ids(interaction_ids)) dependencies_html, additional_angular_modules = ( dependency_registry.Registry.get_deps_html_and_angular_modules( dependency_ids)) gadget_templates = ( gadget_registry.Registry.get_gadget_html(gadget_types)) interaction_templates = ( rte_component_registry.Registry.get_html_for_all_components() + interaction_registry.Registry.get_interaction_html(interaction_ids) ) self.values.update({ 'GADGET_SPECS': gadget_registry.Registry.get_all_specs(), 'INTERACTION_SPECS': interaction_registry.Registry.get_all_specs(), 'DEFAULT_TWITTER_SHARE_MESSAGE_PLAYER': (DEFAULT_TWITTER_SHARE_MESSAGE_PLAYER.value), 'additional_angular_modules': additional_angular_modules, 'can_edit': (bool(self.username) and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( feconf.ACTIVITY_TYPE_EXPLORATION, exploration_id)), 'dependencies_html': jinja2.utils.Markup(dependencies_html), 'exploration_title': exploration.title, 'exploration_version': version, 'collection_id': collection_id, 'collection_title': collection_title, 'gadget_templates': jinja2.utils.Markup(gadget_templates), 'iframed': is_iframed, 'interaction_templates': jinja2.utils.Markup(interaction_templates), 'is_private': rights_manager.is_exploration_private(exploration_id), # Note that this overwrites the value in base.py. 'meta_name': exploration.title, # Note that this overwrites the value in base.py. 'meta_description': utils.capitalize_string(exploration.objective), 'nav_mode': feconf.NAV_MODE_EXPLORE, }) if is_iframed: self.render_template('player/exploration_player.html', iframe_restriction=None) else: self.render_template('player/exploration_player.html')
def get(self, exploration_id): """Handles GET requests.""" version_str = self.request.get('v') version = int(version_str) if version_str else None # Note: this is an optional argument and will be None when the # exploration is being played outside the context of a collection. collection_id = self.request.get('collection_id') try: exploration = exp_services.get_exploration_by_id( exploration_id, version=version) except Exception as e: raise self.PageNotFoundException(e) collection_title = None if collection_id: try: collection = collection_services.get_collection_by_id( collection_id) collection_title = collection.title except Exception as e: raise self.PageNotFoundException(e) version = exploration.version if not rights_manager.Actor(self.user_id).can_view( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id): raise self.PageNotFoundException is_iframed = (self.request.get('iframed') == 'true') # TODO(sll): Cache these computations. gadget_types = exploration.get_gadget_types() interaction_ids = exploration.get_interaction_ids() dependency_ids = ( interaction_registry.Registry.get_deduplicated_dependency_ids( interaction_ids)) dependencies_html, additional_angular_modules = ( dependency_registry.Registry.get_deps_html_and_angular_modules( dependency_ids)) gadget_templates = ( gadget_registry.Registry.get_gadget_html(gadget_types)) interaction_templates = ( rte_component_registry.Registry.get_html_for_all_components() + interaction_registry.Registry.get_interaction_html( interaction_ids)) self.values.update({ 'GADGET_SPECS': gadget_registry.Registry.get_all_specs(), 'INTERACTION_SPECS': interaction_registry.Registry.get_all_specs(), 'SHARING_OPTIONS': SHARING_OPTIONS.value, 'SHARING_OPTIONS_TWITTER_TEXT': SHARING_OPTIONS_TWITTER_TEXT.value, 'additional_angular_modules': additional_angular_modules, 'can_edit': ( bool(self.username) and self.username not in config_domain.BANNED_USERNAMES.value and rights_manager.Actor(self.user_id).can_edit( rights_manager.ACTIVITY_TYPE_EXPLORATION, exploration_id) ), 'dependencies_html': jinja2.utils.Markup( dependencies_html), 'exploration_title': exploration.title, 'exploration_version': version, 'collection_id': collection_id, 'collection_title': collection_title, 'gadget_templates': jinja2.utils.Markup(gadget_templates), 'iframed': is_iframed, 'interaction_templates': jinja2.utils.Markup( interaction_templates), 'is_private': rights_manager.is_exploration_private( exploration_id), # Note that this overwrites the value in base.py. 'meta_name': exploration.title, # Note that this overwrites the value in base.py. 'meta_description': utils.capitalize_string(exploration.objective), 'nav_mode': feconf.NAV_MODE_EXPLORE, }) if is_iframed: self.render_template( 'player/exploration_player.html', iframe_restriction=None) else: self.render_template('player/exploration_player.html')