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], })
def post(self): """Anyone can create network. Same as RestHandler.post, but removes permission check. """ user = self.get_current_user() params = self.get_params(self.model.property_types()) # Sanity check program. program = Program.get_by_id(params['program_id']) if not program: return self.http_bad_request("Program not found.") if not program.active: return self.http_bad_request("Program is inactive.") # Codes are not set on POST. They're generated randomly by create() # and can be changed to a new random value later. params.pop('code', None) # Create network. org = self.model.create(**params) org.put() # Associate with creating user. p = user.get_owner_property(org) if p is not None: p.append(org.uid) user.put() self.write(org) return org
def post(self, team_id, date_str=None): survey = Survey.get(team_id=team_id)[0] if date_str: today = datetime.strptime(date_str, config.iso_date_format).date() else: today = date.today() # Cycle ultimately comes from Cycle.get_current_for_team() and so is # guaranteed to have start and end dates. cycle = survey.should_notify(today) if not cycle: # This task is run every week, but only actually send notifications # if the date matches the survey interval. return team = Team.get_by_id(survey.team_id) program = Program.get_by_id(team.program_id) classrooms = Classroom.get(team_id=team_id) users = User.query_by_team(team_id) if len(classrooms) == 0: pct_complete_by_id = {} else: ppn = get_participation(cycle, classrooms) pct_complete_by_id = self.participation_to_pct(ppn, classrooms) # Get all the responses once to save trips to the db. Redact them later # according to the relevate user. unsafe_responses = Response.get_for_teams_unsafe([team_id], parent_id=cycle.uid) to_put = [] for user in users: if user.receive_email: safe_responses = Response.redact_private_responses( unsafe_responses, user) email = cycle_emailers.create_cycle_email( program.label, user, # recipient users, team, classrooms, safe_responses, cycle, pct_complete_by_id, ) to_put.append(email) ndb.put_multi(to_put)