Beispiel #1
0
    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)
Beispiel #2
0
    def get(self):
        """Handles GET requests."""
        if users.is_current_user_admin():
            exps = exp_services.get_all_explorations()
        else:
            exps = exp_services.get_editable_explorations(self.user_id)

        self.values.update({
            'explorations': [{
                'id': exp.id,
                'image_id': exp.image_id,
                'name': exp.title,
            } for exp in exps],
            'improvable': stats_services.get_top_ten_improvable_states(exps),
        })
        self.render_json(self.values)
Beispiel #3
0
 def get_editable_ids(user_id):
     return [e.id for e in exp_services.get_editable_explorations(user_id)]