def can_cross_all_users_blacklist(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        GandalfFilter(bridge=bridge, filter_type=filter_type,
                      whitelist=False).put()

        return gandalf(bridge_name)
    def can_cross_all_users_outside_percentage(self):
        bridge_name = "balrog"
        filter_type = "all-users"

        bridge = GandalfBridge.get_or_insert(bridge_name)

        filter = GandalfFilter(bridge=bridge, filter_type=filter_type,
                               whitelist=True)
        filter.put()

        identity_percentage = BridgeFilter._identity_percentage(filter.key())

        filter.percentage = identity_percentage
        filter.put()

        return gandalf(bridge_name)
Exemple #3
0
    def get(self):
        if not gandalf("new_faster_search"):
            self.get_old()
            return

        query = self.request.get('page_search_query')
        # Remove any characters that Solr doesn't understand or interfere with
        # the query language syntax, so we don't get errors returned.
        query = self.SEARCH_FILTER_RE.sub(" ", query).strip().lower()
        template_values = {'page_search_query': query}
        if len(query) < self.MIN_QUERY_LENGTH:
            if len(query) > 0:
                template_values.update({
                    'query_too_short': self.MIN_QUERY_LENGTH
                })
            self.render_jinja2_template(
                "searchresults_new.html", template_values)
            return

        url = ("http://search-rpc.khanacademy.org/solr/select/?q=%s&start=0&"
               "rows=1000&indent=on&wt=json&fl=*%%20score&defType=edismax&"
               "qf=title^10.0+keywords^2.0+description^6.0+subtitles" %
               urllib.quote(query.encode('utf-8')))
        try:
            logging.info("Fetching: %s" % url)
            # Allow responses to be cached for an hour
            response = urlfetch.fetch(url=url, deadline=25, headers={
                'Cache-Control': 'max-age=3600'
            })
            response_object = json.loads(response.content)
        except Exception, e:
            logging.error("Failed to fetch search results from search-rpc! "
                          "Error: %s" % str(e))
            template_values.update({
                'server_timout': True
            })
            self.render_jinja2_template(
                "searchresults_new.html", template_values)
            return
Exemple #4
0
    def get(self):
        if not gandalf("new_faster_search"):
            self.get_old()
            return

        query = self.request.get('page_search_query')
        # Remove any characters that Solr doesn't understand or interfere with
        # the query language syntax, so we don't get errors returned.
        query = self.SEARCH_FILTER_RE.sub(" ", query).strip().lower()
        template_values = {'page_search_query': query}
        if len(query) < self.MIN_QUERY_LENGTH:
            if len(query) > 0:
                template_values.update(
                    {'query_too_short': self.MIN_QUERY_LENGTH})
            self.render_jinja2_template("searchresults_new.html",
                                        template_values)
            return

        url = ("http://search-rpc.khanacademy.org/solr/select/?q=%s&start=0&"
               "rows=1000&indent=on&wt=json&fl=*%%20score&defType=edismax&"
               "qf=title^10.0+keywords^2.0+description^6.0+subtitles" %
               urllib.quote(query.encode('utf-8')))
        try:
            logging.info("Fetching: %s" % url)
            # Allow responses to be cached for an hour
            response = urlfetch.fetch(
                url=url,
                deadline=25,
                headers={'Cache-Control': 'max-age=3600'})
            response_object = json.loads(response.content)
        except Exception, e:
            logging.error("Failed to fetch search results from search-rpc! "
                          "Error: %s" % str(e))
            template_values.update({'server_timout': True})
            self.render_jinja2_template("searchresults_new.html",
                                        template_values)
            return
    def add_global_template_values(self, template_values):
        template_values['App'] = App
        template_values['None'] = None

        if not template_values.has_key('user_data'):
            user_data = user_models.UserData.current()
            template_values['user_data'] = user_data

        user_data = template_values['user_data']

        display_name = ""
        if user_data:
            display_name = user_data.nickname or user_data.username

        template_values['server_time'] = time.time()

        # TODO(marcia): Remove username, points, logged_in template values
        # since they should be encapsulated in this UserProfile object
        logged_in_user_profile = util_profile.UserProfile.from_user(user_data,
                                                                    user_data)
        template_values['logged_in_user_profile'] = logged_in_user_profile

        # TODO(benkomalo): rename this global template property from "username"
        #    as it's not really the user's username, but just a display name.
        template_values['username'] = display_name
        template_values['points'] = user_data.points if user_data else 0
        template_values['logged_in'] = not user_data.is_phantom if user_data else False
        template_values['http_host'] = os.environ["HTTP_HOST"]

        # Always insert a post-login request before our continue url
        template_values['continue'] = url_util.create_post_login_url(
            template_values.get('continue') or self.request.uri)
        template_values['login_url'] = ('%s&direct=1' %
                                        url_util.create_login_url(
                                            template_values['continue']))
        template_values['logout_url'] = url_util.create_logout_url(
            self.request.uri)

        # TODO(stephanie): these settings are temporary; for FB testing purposes only
        template_values['site_base_url'] = 'http://%s' % os.environ["HTTP_HOST"]

        template_values['is_mobile'] = False
        template_values['is_mobile_capable'] = False
        template_values['is_ipad'] = False

        if self.is_mobile_capable():
            template_values['is_mobile_capable'] = True
            template_values['is_ipad'] = self.is_ipad()

            if 'is_mobile_allowed' in template_values and template_values['is_mobile_allowed']:
                template_values['is_mobile'] = self.is_mobile()

        # overridable hide_analytics querystring that defaults to true in dev
        # mode but false for prod.
        hide_analytics = self.request_bool("hide_analytics", App.is_dev_server)
        template_values['hide_analytics'] = hide_analytics

        # client-side error logging
        template_values['include_errorception'] = gandalf('errorception')

        # Analytics
        template_values['mixpanel_enabled'] = gandalf('mixpanel_enabled')

        # Enable for Mixpanel testing only
        # You will need to ask Tom, Kitt, or Marcia to add you to the "Khan
        # Academy Test" project on Mixpanel so that you can see the results.
        if False:
            template_values['mixpanel_test'] = "70acc4fce4511b89477ac005639cfee1"
            template_values['mixpanel_enabled'] = True
            template_values['hide_analytics'] = False

        if template_values['mixpanel_enabled']:
            template_values['mixpanel_id'] = gae_bingo.identity.identity()

        if not template_values['hide_analytics']:
            superprops_list = user_models.UserData.get_analytics_properties(user_data)

            # Create a superprops dict for MixPanel with a version number
            # Bump the version number if changes are made to the client-side
            # analytics code and we want to be able to filter by version.
            template_values['mixpanel_superprops'] = dict(superprops_list)

            # Copy over first 4 per-user properties for GA
            # (The 5th is reserved for Bingo)
            template_values['ga_custom_vars'] = superprops_list[0:4]

        if user_data:
            user_goals = goals.models.GoalList.get_current_goals(user_data)
            goals_data = [g.get_visible_data() for g in user_goals]
            if goals_data:
                template_values['global_goals'] = jsonify(goals_data)

        badges_earned = badges.util_badges.get_badge_notifications_json()
        template_values['badges_earned'] = badges_earned

        # Disable topic browser in the header on mobile devices
        template_values['watch_topic_browser_enabled'] = not self.is_mobile_capable()

        template_values['show_topic_pages'] = True

        return template_values
    def can_cross_empty_bridge(self):
        bridge_name = "balrog"

        GandalfBridge.get_or_insert(bridge_name)

        return gandalf(bridge_name)