Пример #1
0
    def get(self, program_id_or_label):
        user = self.get_current_user()
        if not user.super_admin:
            return self.http_forbidden()

        program = Program.get_by_id(program_id_or_label)
        if not program:
            program = Program.get_by_label(program_id_or_label)
        if not program:
            return self.http_not_found()

        search_str = self.get_param('q', unicode, None)

        if not search_str:
            return self.write([])

        if search_str.startswith('user:'******'t have team r
        orgs = Organization.query_by_name(search_str, program.uid)
        teams = Team.query_by_name(search_str, program.uid)
        classrooms = Classroom.query_by_name(search_str, program.uid)
        users = User.query_by_name_or_email(search_str)

        self.write({
            'organizations': [e.to_client_dict() for e in orgs],
            'teams': [e.to_client_dict() for e in teams],
            'classrooms': [e.to_client_dict() for e in classrooms],
            'users': [e.to_client_dict() for e in users],
        })
Пример #2
0
 def query(self, override_permissions=False):
     if 'order' not in self.request.GET:
         self.request.GET['order'] = 'name'
     program_label = self.request.GET.pop('program', None)
     if program_label:
         program = Program.get_by_label(program_label)
         if not program:
             self.write([])
             return
         self.request.GET['program_id'] = program.uid
     super(Networks, self).query(override_permissions=override_permissions)
Пример #3
0
    def get(self, user_id):
        user = self.get_current_user()

        program_label = self.request.GET.pop('program', None)
        if program_label:
            program = Program.get_by_label(program_label)
            if not program:
                self.write([])
                return
            program_id = program.uid
        else:
            program_id = None

        if not owns(user, user_id):
            return self.http_forbidden("Can't list networks for someone else.")

        self.write(Network.query_by_user(user, program_id=program_id))
Пример #4
0
    def get(self, script):
        """Describe for RServe all the classrooms and teams that we'd like
        reports on, including what URLs to post the report data back to."""

        week = self.request.get('week', None)
        if not week:
            monday = datetime.date.today()
            while monday.weekday() != 0:
                monday = monday + datetime.timedelta(days=1)
            week = util.datelike_to_iso_string(monday)

        should_force = self.request.get('force', 'false') == 'true'
        really_send = self.request.get('really_send', 'true') == 'true'

        script_to_label = {
            'ep': 'ep19',
            'beleset': 'beleset19',
            'cset': 'cset19',
            'mset': 'mset19',
        }
        program = Program.get_by_label(script_to_label[script])

        # Manual calls to this handler may specify reporting unit ids.
        # We'll use them as a whitelist to filter what we query.
        reporting_unit_ids = self.request.get_all('ru') or []

        # What reporting units should get reports this week? If should_force is
        # true, this function will return all possible units for the program.
        # Otherwise it will ignore units that already have reports.
        orgs, teams, classrooms = cron_rserve.get_report_parents(
            program, week, should_force)

        payload = cron_rserve.build_payload(
            orgs,
            teams,
            classrooms,
            cron_rserve.get_secrets(self.request),
            ru_whitelist=reporting_unit_ids,
        )
        fetch_params = cron_rserve.get_fetch_params(script, payload)

        if not really_send:
            logging.info("really_send is false, not contacting RServe.")
            # More convenient to see payload parsed rather than dumpsed.
            fetch_params['payload'] = payload
            self.write(fetch_params)
            return

        try:
            result = urlfetch.fetch(**fetch_params)
        except urlfetch.DeadlineExceededError as e:
            logging.warning("RServe took a long time to reply (caught a "
                            "DeadlineExceededError). Exiting without checking "
                            "results. Original error message follows.")
            logging.warning(e.message)
            return

        if not result:
            raise Exception("No response from RServe.")

        if result.status_code >= 300:
            # App Engine will consider this cron job to have failed, and will
            # follow any retry instructions in cron.yaml.
            raise Exception(
                "Non-successful response from RServe: {} {}".format(
                    result.status_code, result.content))

        logging.info("response status: {}".format(result.status_code))
        try:
            json.loads(result.content)
            # ok, it's valid
            logging.info(util.truncate_json(result.content))
            logging.info(result.content)
        except:
            # just log as text
            logging.info(result.content)