def post(self, request): results = {'success': False} form = ChooseTeamForm(request, request.POST) if form.is_valid(): team = form.cleaned_data['team'] request.session['team'] = team results['success'] = True else: results['errors'] = form.errors.as_json() return JsonResponse(results)
def index(request): teamString = '' teamRaw = '' teams = [] logger = logging.getLogger("alliance") if request.method == 'POST': form = ChooseTeamForm(request, request.POST or None) if form.is_valid(): team = form.cleaned_data['team'] request.session['team'] = team else: team = request.session.get('team') if team is None: teams = [] teams2 = [] # The python_social_auth authentication pipeline puts the github user teams on the session # Here, we match those teams to ones recognized in our system and present a selection dropdown if > 1 logger.debug("These github teams are on the session: " + request.session['gh_teams']) if request.session['gh_teams'] == "unauthorized": return render(request, 'accounts/logged.html') gh_team_raw = request.session['gh_teams'] gh_team_chopped = gh_team_raw.rpartition(',')[0] gh_team_names = gh_team_chopped.split(",") for item in gh_team_names: logger.debug("matching on " + item) team_qs = Team.objects.filter(name=item) if team_qs: teams.append(team_qs[0]) teams2.append(team_qs[0].id) logger.debug("We matched %d system teams in the view", len(teams)) logger.debug(teams) logger.debug(teams2) if (len(teams) == 0): request.session['team'] = None request.session['teamName'] = None elif (len(teams) == 1): request.session['team'] = teams[0].id request.session['teamName'] = teams[0].name return redirect('backlogs') else: request.session['test-teams'] = teams2 request.session['teamName'] = None request.session['multiTeams'] = "True" form = ChooseTeamForm(request) context = RequestContext(request, {'teams': teams, 'form': form}) return render(request, 'core/index.html', context) return render(request, 'core/index.html')
def post(self, request): logger = logging.getLogger("alliance") results = {'success': False} form = ChooseTeamForm(request, request.POST) logger.debug("form in post") logger.debug(form) logger.debug(form.is_valid()) if form.is_valid(): team = form.cleaned_data['team'] request.session['team'] = team results['success'] = True logger.debug(form.fields['team']) choiceFieldObj = form.fields['team'] logger.debug(choiceFieldObj.choices) logger.debug("choiceFieldObj choices size : %d ", len(choiceFieldObj.choices)) teamId = int(team) logger.debug("Integer converted team id : %d ", teamId) i = 0 while (i < len(choiceFieldObj.choices)): if (teamId == choiceFieldObj.choices[i][0]): logger.debug("Match found in index %d for team id %d ", i, choiceFieldObj.choices[i][0]) logger.debug(choiceFieldObj.choices[i][1]) request.session['team'] = teamId request.session['teamName'] = choiceFieldObj.choices[i][1] else: logger.debug("Match Not found in index for %d team id %d", i, choiceFieldObj.choices[i][0]) i += 1 else: results['errors'] = form.errors.as_json() return JsonResponse(results)
def index(request): teamString = '' teamRaw = '' teams = [] logger = logging.getLogger("alliance") if request.method == 'POST': form = ChooseTeamForm(request, request.POST or None) if form.is_valid(): team = form.cleaned_data['team'] request.session['team'] = team else: team = request.session.get('team') if team is None: teams = [] # The python_social_auth authentication pipeline puts the github user teams on the session # Here, we match those teams to ones recognized in our system and present a selection dropdown if > 1 logger.debug("These github teams are on the session: " + request.session['gh_teams']) if request.session['gh_teams'] == "unauthorized": return render(request, 'accounts/logged.html') gh_team_raw = request.session['gh_teams'] gh_team_chopped = gh_team_raw.rpartition(',')[0] gh_team_names = gh_team_chopped.split(",") for item in gh_team_names: logger.debug("matching on " + item) team_qs = Team.objects.filter(name=item) if team_qs: teams.append(team_qs[0]) logger.debug("We matched %d system teams in the view", len(teams)) logger.debug(teams) if (len(teams) == 0): request.session['team'] = None elif (len(teams) == 1): request.session['team'] = teams[0].id else: form = ChooseTeamForm(request, teams) context = RequestContext(request, {'teams': teams, 'form': form}) return render(request, 'core/index.html', context) return render(request, 'core/index.html')
def index(request): if request.method == 'POST': form = ChooseTeamForm(request, request.POST or None) if form.is_valid(): team = form.cleaned_data['team'] request.session['team'] = team else: team = request.session.get('team') if team is None: user_email = request.user.email teams = Team.objects.filter(volunteers__email=user_email) if (len(teams) == 0): request.session['team'] = None elif (len(teams) == 1): request.session['team'] = teams[0].id else: form = ChooseTeamForm(request) context = RequestContext(request, {'teams': teams, 'form': form}) return render(request, 'core/index.html', context) return render(request, 'core/index.html')
def index(request): if request.method == 'POST': form = ChooseTeamForm(request, request.POST) if form.is_valid(): team = form.cleaned_data['team'] request.session['team'] = team else: team = request.session.get('team') if team is None: user_email = request.user.email teams = Team.objects.filter(volunteers__email=user_email) if (len(teams) == 0): request.session['team'] = None elif (len(teams) == 1): request.session['team'] = teams[0].id else: form = ChooseTeamForm(request) context = RequestContext(request, {'teams': teams, 'form': form}) return render(request, 'core/index.html', context) return render(request, 'core/index.html')