def test_get_public_explorations(self): exploration = Exploration.get( exp_services.create_new(self.owner_id, "A title", "A category", "A exploration_id") ) self.assertEqual(exp_services.get_public_explorations(), []) exploration.is_public = True exploration.put() self.assertEqual([e.id for e in exp_services.get_public_explorations()], [exploration.id])
def get(self): """Handles GET requests.""" if users.is_current_user_admin(): explorations = exp_services.get_all_explorations() editable_exploration_ids = [e.id for e in explorations] elif self.user_id: explorations = exp_services.get_viewable_explorations(self.user_id) editable_exploration_ids = [ e.id for e in exp_services.get_editable_explorations( self.user_id) ] else: explorations = exp_services.get_public_explorations() editable_exploration_ids = [] categories = collections.defaultdict(list) for exploration in explorations: categories[exploration.category].append({ 'can_edit': exploration.id in editable_exploration_ids, 'can_fork': self.user_id and exploration.is_demo, 'id': exploration.id, 'image_id': exploration.image_id, 'is_owner': (users.is_current_user_admin() or exploration.is_owned_by(self.user_id)), 'title': exploration.title, }) self.values.update({ 'categories': categories, }) self.render_json(self.values)
def get(self): """Handles GET requests.""" explorations = exp_services.get_public_explorations() # Don't use the first exploration; users will have seen that already # on the main page. selected_exploration = utils.get_random_choice(explorations[1:]) self.redirect('/learn/%s' % selected_exploration.id)