def post(self): self._require_registration() user = self.user_bundle.account.key existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user).count(1) if existing_access > 0: self.redirect('/mod/redeem?status=already_linked') return team_number = self.request.get("team_number") if not team_number or not team_number.isdigit(): self.redirect('/mod/redeem?status=invalid_code') return team_number = int(team_number) auth_code = self.request.get("auth_code").strip() access = TeamAdminAccess.query( TeamAdminAccess.team_number == team_number, TeamAdminAccess.access_code == auth_code).fetch(1) if not access: self.redirect('/mod/redeem?status=invalid_code') return access = access[0] if access.account: self.redirect('/mod/redeem?status=code_used') return access.account = user access.put() self.redirect('/mod/redeem?status=success&team={}'.format( access.team_number))
def post(self): self._require_registration() user = self.user_bundle.account.key existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user).count(1) if existing_access > 0: self.redirect('/mod/redeem?status=already_linked') return team_number = self.request.get("team_number") if not team_number or not team_number.isdigit(): self.redirect('/mod/redeem?status=invalid_code') return team_number = int(team_number) auth_code = self.request.get("auth_code") access = TeamAdminAccess.query( TeamAdminAccess.team_number == team_number, TeamAdminAccess.access_code == auth_code).fetch(1) if not access: self.redirect('/mod/redeem?status=invalid_code') return access = access[0] if access.account: self.redirect('/mod/redeem?status=code_used') return access.account = user access.put() self.redirect('/mod/redeem?status=success&team={}'.format( access.team_number))
def giveTeamAdminAccess(self, expiration_days=1): access = TeamAdminAccess( id="test_access", team_number=1124, year=self.now.year, expiration=self.now + datetime.timedelta(days=expiration_days), account=self.account.key, ) return access.put()
def giveTeamAdminAccess(self, expiration_days=1): access = TeamAdminAccess( id="test_access", team_number=1124, year=self.now.year, expiration=self.now + datetime.timedelta(days=expiration_days), account=self.account.key, ) return access.put()
def addTeamAdminAccess(self, account, team_number=1124): access = TeamAdminAccess( id="test_access", access_code="abc123", team_number=team_number, year=self.now.year, expiration=self.now + datetime.timedelta(days=1), account=account, ) return access.put()
def addTeamAdminAccess(self, account, team_number=1124): access = TeamAdminAccess( id="test_access", access_code="abc123", team_number=team_number, year=self.now.year, expiration=self.now + datetime.timedelta(days=1), account=account, ) return access.put()
def addTeamAdminAccess(self, account, team_number=1124, year=None, access_code="abc123"): if not year: year = self.now.year access = TeamAdminAccess( id="test_access_{}".format(year), access_code=access_code, team_number=team_number, year=year, expiration=self.now + datetime.timedelta(days=1), account=account, ) return access.put()
def post(self, team_number, year): self._require_admin() team_number = int(team_number) year = int(year) access = TeamAdminAccess.query( TeamAdminAccess.year == year, TeamAdminAccess.team_number == team_number).fetch() if not access: self.abort(404) return access = access[0] access_code = self.request.get('access_code') expiration = self.request.get('expiration') account_email = self.request.get('account_email') account = None if account_email: accounts = Account.query(Account.email == account_email).fetch(1) if accounts: account = accounts[0] access.access_code = access_code access.expiration = datetime.strptime(expiration, "%Y-%m-%d") access.account = account.key if account else None access.put() self.redirect('/admin/media/modcodes/edit/{}/{}'.format( team_number, year))
def post(self): self._require_admin() year = int(self.request.get("year")) auth_codes_csv = self.request.get("auth_codes_csv") csv_data = list( csv.reader(StringIO.StringIO(auth_codes_csv), delimiter=',')) auth_codes = [] for row in csv_data: team_number = int(row[0]) auth_codes.append( TeamAdminAccess( id=TeamAdminAccess.renderKeyName(team_number, year), team_number=team_number, year=year, access_code=row[1], expiration=datetime(year=year, month=7, day=1), )) ndb.put_multi(auth_codes) self.redirect('/admin/media/modcodes/list/{}'.format(year))
def get(self, year=None, page_num=0): self._require_admin() page_num = int(page_num) if year: year = int(year) else: year = datetime.now().year if page_num < self.MAX_PAGE: start = self.PAGE_SIZE * page_num end = start + self.PAGE_SIZE auth_codes = TeamAdminAccess.query( TeamAdminAccess.year == year, TeamAdminAccess.team_number >= start, TeamAdminAccess.team_number < end).order( TeamAdminAccess.team_number).fetch() else: start = self.PAGE_SIZE * self.MAX_PAGE auth_codes = TeamAdminAccess.query( TeamAdminAccess.team_number >= start).order( TeamAdminAccess.team_number).fetch() page_labels = [] for page in xrange(self.MAX_PAGE): if page == 0: page_labels.append('1-999') else: page_labels.append('{}\'s'.format(1000 * page)) page_labels.append('{}+'.format(1000 * self.MAX_PAGE)) self.template_values.update({ "year": year, "auth_codes": auth_codes, "page_labels": page_labels, }) path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_media_mod_list.html') self.response.out.write(template.render(path, self.template_values))
def _require_team_admin_access(self, team_number, redirect_url=None): self._require_login(redirect_url) if self.user_bundle.is_current_user_admin: # Admins have this granted return user = self.user_bundle.account.key now = datetime.datetime.now() existing_access = existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user, TeamAdminAccess.team_number == team_number, TeamAdminAccess.expiration > now).fetch() if not existing_access: return self.abort(403)
def _require_team_admin_access(self, team_number, redirect_url=None): self._require_login(redirect_url) if self.user_bundle.is_current_user_admin: # Admins have this granted return user = self.user_bundle.account.key now = datetime.datetime.now() existing_access = existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user, TeamAdminAccess.team_number == team_number, TeamAdminAccess.expiration > now).fetch() if not existing_access: return self.abort(403)
def get(self): self._require_registration() user = self.user_bundle.account.key existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user).fetch() team_keys = [ ndb.Key(Team, "frc{}".format(access.team_number)) for access in existing_access ] teams = ndb.get_multi(team_keys) team_num_to_team = {team.team_number: team for team in teams} self.template_values.update({ "existing_access": existing_access, "status": self.request.get("status"), "team": self.request.get("team"), "teams": team_num_to_team, }) self.response.out.write( jinja2_engine.render('team_admin_redeem.html', self.template_values))
def get(self): self._require_registration() user = self.user_bundle.account.key existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user).fetch() team_keys = [ ndb.Key(Team, "frc{}".format(access.team_number)) for access in existing_access ] teams = ndb.get_multi(team_keys) team_num_to_team = {team.team_number: team for team in teams} self.template_values.update({ "existing_access": existing_access, "status": self.request.get("status"), "team": self.request.get("team"), "teams": team_num_to_team, }) self.response.out.write( jinja2_engine.render('team_admin_redeem.html', self.template_values))
def get(self, team_number, year): self._require_admin() team_number = int(team_number) year = int(year) access = TeamAdminAccess.query( TeamAdminAccess.year == year, TeamAdminAccess.team_number == team_number).fetch(1) if not access: self.abort(404) return access = access[0] account_email = None if access.account: account = access.account.get() account_email = account.email self.template_values.update({ 'access': access, 'account_email': account_email, }) path = os.path.join(os.path.dirname(__file__), '../../templates/admin/team_media_mod_edit.html') self.response.out.write(template.render(path, self.template_values))
def get(self): self._require_registration() user = self.user_bundle.account.key now = datetime.datetime.now() existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user, TeamAdminAccess.expiration > now).fetch() # If the current user is an admin, allow them to view this page for any # team/year combination forced_team = self.request.get("team") forced_year = self.request.get("year") if self.user_bundle.is_current_user_admin and forced_team and forced_year: existing_access.append( TeamAdminAccess( team_number=int(forced_team), year=int(forced_year), )) team_keys = [ ndb.Key(Team, "frc{}".format(access.team_number)) for access in existing_access ] if not team_keys: self.redirect('/mod/redeem') return years = set([access.year for access in existing_access]) teams_future = ndb.get_multi_async(team_keys) robot_keys = [ ndb.Key(Robot, Robot.renderKeyName(team.id(), now.year)) for team in team_keys ] robots_future = ndb.get_multi_async(robot_keys) social_media_futures = [ media_query.TeamSocialMediaQuery(team_key.id()).fetch_async() for team_key in team_keys ] team_medias_future = Media.query(Media.references.IN(team_keys), Media.year.IN(years)).fetch_async(50) suggestions_future = Suggestion.query( Suggestion.review_state == Suggestion.REVIEW_PENDING).filter( Suggestion.target_model.IN( self.ALLOWED_SUGGESTION_TYPES)).filter( Suggestion.target_key.IN([k.id() for k in team_keys ])).fetch_async(limit=50) team_num_to_team = { team.get_result().team_number: team.get_result() for team in teams_future } team_num_to_robot_name = { int(robot.get_result().team.id()[3:]): robot.get_result().robot_name for robot in robots_future if robot.get_result() is not None } team_medias = defaultdict(lambda: defaultdict(list)) for media in team_medias_future.get_result(): for reference in media.references: if reference in team_keys: team_num = reference.id()[3:] team_medias[int(team_num)][media.year].append(media) team_social_medias = defaultdict(list) for team_social_media_future in social_media_futures: social_medias = team_social_media_future.get_result() for media in social_medias: for reference in media.references: if reference in team_keys: team_num = reference.id()[3:] team_social_medias[int(team_num)].append(media) suggestions_by_team = defaultdict(lambda: defaultdict(list)) for suggestion in suggestions_future.get_result(): if not suggestion.target_key: continue # Assume all the keys are team keys team_num = suggestion.target_key[3:] suggestions_by_team[int(team_num)][suggestion.target_model].append( suggestion) self.template_values.update({ "existing_access": existing_access, "teams": team_num_to_team, "robot_names_by_team": team_num_to_robot_name, "team_medias": team_medias, "team_social_medias": team_social_medias, "suggestions_by_team": suggestions_by_team, "suggestion_names": self.SUGGESTION_NAMES, "suggestion_review_urls": self.SUGGESTION_REVIEW_URL, }) self.response.out.write( jinja2_engine.render('team_admin_dashboard.html', self.template_values))
def post(self): self._require_login() now = datetime.datetime.now() self.existing_access = TeamAdminAccess.query( TeamAdminAccess.account == self.user_bundle.account.key, TeamAdminAccess.expiration > now).fetch()
def get(self): self._require_registration() user = self.user_bundle.account.key now = datetime.datetime.now() existing_access = TeamAdminAccess.query( TeamAdminAccess.account == user, TeamAdminAccess.expiration > now).fetch() # If the current user is an admin, allow them to view this page for any # team/year combination forced_team = self.request.get("team") forced_year = self.request.get("year") if self.user_bundle.is_current_user_admin and forced_team and forced_year: existing_access.append( TeamAdminAccess( team_number=int(forced_team), year=int(forced_year), ) ) team_keys = [ ndb.Key(Team, "frc{}".format(access.team_number)) for access in existing_access ] if not team_keys: self.redirect('/mod/redeem') return years = set([access.year for access in existing_access]) teams_future = ndb.get_multi_async(team_keys) robot_keys = [ ndb.Key(Robot, Robot.renderKeyName(team.id(), now.year)) for team in team_keys ] robots_future = ndb.get_multi_async(robot_keys) social_media_futures = [ media_query.TeamSocialMediaQuery(team_key.id()).fetch_async() for team_key in team_keys ] team_medias_future = Media.query( Media.references.IN(team_keys), Media.year.IN(years)).fetch_async(50) suggestions_future = Suggestion.query( Suggestion.review_state == Suggestion.REVIEW_PENDING).filter( Suggestion.target_model.IN( self.ALLOWED_SUGGESTION_TYPES)).filter( Suggestion.target_key.IN([k.id() for k in team_keys ])).fetch_async(limit=50) team_num_to_team = { team.get_result().team_number: team.get_result() for team in teams_future } team_num_to_robot_name = { int(robot.get_result().team.id()[3:]): robot.get_result().robot_name for robot in robots_future if robot.get_result() is not None } team_medias = defaultdict(lambda: defaultdict(list)) for media in team_medias_future.get_result(): for reference in media.references: if reference in team_keys: team_num = reference.id()[3:] team_medias[int(team_num)][media.year].append(media) team_social_medias = defaultdict(list) for team_social_media_future in social_media_futures: social_medias = team_social_media_future.get_result() for media in social_medias: for reference in media.references: if reference in team_keys: team_num = reference.id()[3:] team_social_medias[int(team_num)].append(media) suggestions_by_team = defaultdict(lambda: defaultdict(list)) for suggestion in suggestions_future.get_result(): if not suggestion.target_key: continue # Assume all the keys are team keys team_num = suggestion.target_key[3:] suggestions_by_team[int(team_num)][suggestion.target_model].append( suggestion) self.template_values.update({ "existing_access": existing_access, "teams": team_num_to_team, "robot_names_by_team": team_num_to_robot_name, "team_medias": team_medias, "team_social_medias": team_social_medias, "suggestions_by_team": suggestions_by_team, "suggestion_names": self.SUGGESTION_NAMES, "suggestion_review_urls": self.SUGGESTION_REVIEW_URL, }) self.response.out.write( jinja2_engine.render('team_admin_dashboard.html', self.template_values))