def register_team(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) team_form = TeamForm(request.POST, request.FILES) if user_form.is_valid(): if team_form.is_valid(): user = user_form.save() # do i need these two lines anymore? Django 1.5, i think, handles this automatically now. password = user.password user.set_password(password) user.save() t = team_form.save(commit=False) t.user = user t.save() registered = True user = authenticate(username=user.username, password=password) login(request, user) return HttpResponseRedirect('/showcase/team/'+str(t.id)+'/') else: print user_form.errors, team_form.errors else: user_form = UserForm() team_form = TeamForm() # Render the template depending on the context. return render_to_response( 'showcase/team_registration.html', {'user_form': user_form, 'team_form':team_form, 'registered': registered}, context)
def edit_team(team_id): team = Team.query.get(team_id) user = g.user teamform = TeamForm() if user.id != team.user_id: flash('Only the team creator can update the team information.') elif teamform.validate_on_submit(): team.name = request.form.get('teamname') for m in team.members: sqldb.session.delete(m) members = request.form.getlist('member') for m in members: if m!="": member = Member(team_id = team.id, member_name = m) sqldb.session.add(member) sqldb.session.commit() return redirect(url_for('team', team_id = team_id)) return render_template("team.html", team = team, form = teamform, n = team.event.max_member_per_team)
def add_team(event_id): event = Event.query.get(event_id) teamform = TeamForm() if event.teams.count() >= event.max_team: flash('Sorry, no more space available.') return redirect(url_for('event', event_id = event_id)) elif teamform.validate_on_submit(): user = g.user team = Team(user_id = user.id, event_id = event_id, name = request.form.get('teamname')) sqldb.session.add(team) sqldb.session.commit() members = request.form.getlist('member') for m in members: if m!="": member = Member(team_id = team.id, member_name = m) sqldb.session.add(member) sqldb.session.commit() return redirect(url_for('event', event_id = event_id)) return render_template("team.html", team = None, form = teamform, n = event.max_member_per_team)
def post(self, user_token): team = Team.all().filter('user_token =', user_token).get() if team is None: # just make sure this pledge exists user_info = config_NOCOMMIT.pledge_service.loadPledgeInfo( user_token) if user_info is None: return self.notfound() form = TeamForm(self.request.POST, team) if not form.validate(): return self.render_template("new_from_pledge.html", form=form) if team is None: gravatar = "https://secure.gravatar.com/avatar/%s?%s" % ( hashlib.md5(user_info['email'].lower()).hexdigest(), urllib.urlencode({'s': str('120')})) team = Team.create(title=form.title.data, description=form.description.data, zip_code=form.zip_code.data, user_token=user_token, gravatar=gravatar) else: form.populate_obj(team) self.add_to_user(team) team.primary_slug = Slug.new(team) try: result = config_NOCOMMIT.pledge_service.updateMailchimp(team) except Exception as e: logging.error('Exception updating mailChimp: ' + str(e)) logging.info(traceback.format_exc()) team.put() if self.logged_in: return self.redirect("/t/%s" % team.primary_slug) return self.redirect("/dashboard/add_admin_from_pledge/%s" % user_token)
def teams(): form = TeamForm() if 'username' not in session: return redirect(url_for('signin')) user = session['username'] teams = db.session.query(Team).order_by(Team.Number).all() if user is None: redirect(url_for('signin')) else: if request.method == 'POST': if not form.validate(): return render_template('teams.html', teams=teams, form=form) else: newteam = Team(number=form.number.data, name=form.name.data, website=form.website.data, timestamp=datetime.datetime.now()) db.session.add(newteam) db.session.commit() flash('Team successfully added.') return redirect(url_for('teams')) elif request.method == 'GET' : return render_template('teams.html', teams=teams, form=form)
def post(self, user_token): team = Team.all().filter('user_token =', user_token).get() if team is None: # just make sure this pledge exists user_info = config_NOCOMMIT.pledge_service.loadPledgeInfo(user_token) if user_info is None: return self.notfound() form = TeamForm(self.request.POST, team) if not form.validate(): return self.render_template("new_from_pledge.html", form=form) if team is None: gravatar = "https://secure.gravatar.com/avatar/%s?%s" % ( hashlib.md5(user_info['email'].lower()).hexdigest(), urllib.urlencode({'s': str('120')})) team = Team.create(title=form.title.data, description=form.description.data, zip_code=form.zip_code.data, user_token=user_token, gravatar=gravatar) else: form.populate_obj(team) self.add_to_user(team) team.primary_slug = Slug.new(team) try: result = config_NOCOMMIT.pledge_service.updateMailchimp(team) except Exception as e: logging.error('Exception updating mailChimp: ' + str(e)) logging.info(traceback.format_exc()) team.put() if self.logged_in: return self.redirect("/t/%s" % team.primary_slug) return self.redirect("/dashboard/add_admin_from_pledge/%s" % user_token)
def get(self, user_token): team = Team.all().filter('user_token =', user_token).get() if team is None: user_info = config_NOCOMMIT.pledge_service.loadPledgeInfo( user_token) if user_info is None: return self.notfound() user_pledge_dollars = int(user_info["pledge_amount_cents"]) / 100 goal_dollars = user_pledge_dollars * 10 if user_info["name"]: signature = "_Thank you,_\n\n_%s_" % user_info["name"] else: signature = "Thank you!" title = user_info["name"] or DEFAULT_TITLE form = TeamForm( data={ "goal_dollars": str(goal_dollars), "title": title, "zip_code": str(user_info["zip_code"] or ""), "description": PREVIOUS_PLEDGE_DESC.format( pledge_dollars=user_pledge_dollars, signature=signature, title=title) }) else: self.add_to_user(team) form = TeamForm(obj=team) self.render_template("new_from_pledge.html", form=form)
def create_new_team(): """We're gonna show a form and handle the business of folks who already registered,""" if not g.user: flash("Access unauthorized.", "danger") return redirect('/') user = g.user form = TeamForm() if form.validate_on_submit(): try: team = Team(name=form.name.data, team_image=form.team_image.data or Team.team_image.default.arg, user_id=user.username) db.session.add(team) db.session.commit() except IntegrityError: db.session.rollback() form.team_name.errors = ["Team name already exists"] return render_template('users/createTeam.html', form=form) return redirect(f'/users/{user.username}') return render_template('users/createTeam.html', form=form)
def edit_team(team_id): """Editing a teams id and photo""" if not g.user: flash("Access unauthorized.", "danger") return redirect('/') user = g.user team = Team.query.get(team_id) form = TeamForm(obj=team) if form.validate_on_submit(): try: team.name = form.name.data team.team_image = form.team_image.data or Team.team_image.default.arg db.session.commit() except IntegrityError: db.session.rollback() form.team_name.errors = ["Team name already exists"] return render_template('users/createTeam.html', form=form) return redirect(f'/users/{user.username}') return render_template('users/editTeam.html', form=form, team=team)
def post(self): user = tusers.get_current_user() form = TeamForm(self.request.POST) t_string = self.request.get('t') t_key = ndb.Key(urlsafe=t_string) team = t_key.get() institution = None t = None # If it is an institutional team, don't let them update the contact info # with this method, as that data belongs to the Institution if (isinstance(team, InstitutionTeam)): institution = team.key.parent().get() form.leadName.data = institution.leadName form.phone.data = institution.phone reg = institution.key.parent().get() elif (isinstance(team, RegisteredOpenTeam)): reg = t_key.parent().get() t = reg.key.parent().get() #Check if they are allowed to edit if team.authorised(user): #If valid, update the team object if (form.validate()): team.leadName = form.leadName.data team.phone = form.phone.data team.teamName = form.teamName.data team.sp1Name = form.sp1Name.data team.sp2Name = form.sp2Name.data team.sp1ESL = form.sp1ESL.data team.sp2ESL = form.sp2ESL.data team.sp1Novice = form.sp1Novice.data team.sp2Novice = form.sp2Novice.data team.put() self.redirect('/reg_control?t=' + str(t.key.id())) else: template_values = { 'user' : user, 't' : t, 'logout' : tusers.create_logout_url('/'), 'login' : tusers.create_login_url('/mod/team?j=' + t_key.urlsafe()), 'r' : reg, 'form' : form, 'team' : t_key.urlsafe(), 'institution' : institution } template = JINJA_ENVIRONMENT.get_template('view/modteam.html') self.response.write(template.render(template_values)) else: self.redirect(self.request.referer)
def add(): form = TeamForm() if request.method == 'POST' and form.validate_on_submit(): team = Team() form.populate_obj(team) db.session.add(team) db.session.commit() return redirect(url_for(".index")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("teams/team_form.html", form=form, id=None)
def team_setting(team_id): team = Team.query.get(team_id) if not current_user.in_team(team_id): abort(404) form = TeamForm(user=current_user, team_id=team.id, name=team.name) if form.validate_on_submit(): if form.team.status == 0: return redirect(url_for('team_show', team_id=form.team.id)) else: flash(u'团队已删除') return redirect(url_for('team_index')) return render_template('team/form.html', form=form, team=team)
def edit_team(team_id=None): model = get_object_or_404(Team, Team.id == team_id) if g.user not in model.members and not g.user.is_admin(): return redirect(url_for('index')) form = TeamForm(obj=model) if form.validate_on_submit(): form.populate_obj(model) db.session.add(model) db.session.commit() flash('Team updated', category='success') return redirect(url_for('team', team_id=model.id)) return render_template('edit_team.html', team=model, form=form)
def dashboard_create_team(): form = TeamForm(request.form) if request.method == 'POST' and form.validate(): team = Team() team.name = form.name.data user_ids = request.form.getlist('selected-users') users = User.query.filter(User.id.in_(user_ids)).all() for user in users: team.users.append(user) db_session.add(team) db_session.commit() return redirect(url_for('dashboard.dashboard_teams')) return render_template('create_team.html', form=form)
def team(request): #create/update team object team = None if Team.objects.filter(user=request.user).exists(): team = Team.objects.get(user=request.user) if request.method == 'POST': form = TeamForm(request.POST, instance=team or None) if form.is_valid(): team = form.save(commit=False) team.user = request.user team.save() return HttpResponseRedirect('/dashboard') if team: form = TeamForm(instance=team) else: form = TeamForm() args = {} args['form'] = form args['team'] = team #args.update(csrf(request)) return render(request, 'templates/showcase/team.html', args)
def view_team(request, team_id): team_id = int(team_id) try: team = Team.objects.get(pk=team_id) stats = [] stats.append(("Wins", tab_logic.tot_wins(team))) stats.append(("Total Speaks", tab_logic.tot_speaks(team))) stats.append(("Govs", tab_logic.num_govs(team))) stats.append(("Opps", tab_logic.num_opps(team))) stats.append(("Opp Wins", tab_logic.opp_strength(team))) stats.append(("Been Pullup", tab_logic.pull_up_count(team))) stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team))) except Team.DoesNotExist: return render_to_response('error.html', {'error_type': "View Team", 'error_name': str(team_id), 'error_info':"No such Team"}, context_instance=RequestContext(request)) if request.method == 'POST': form = TeamForm(request.POST,instance=team) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', {'error_type': "Team", 'error_name': "["+form.cleaned_data['name']+"]", 'error_info':"Team name cannot be validated, most likely a non-existent team"}, context_instance=RequestContext(request)) return render_to_response('thanks.html', {'data_type': "Team", 'data_name': "["+form.cleaned_data['name']+"]"}, context_instance=RequestContext(request)) else: form = TeamForm(instance=team) links = [('/team/'+str(team_id)+'/scratches/view/','Scratches for '+str(team.name), False), ('/team/'+str(team_id)+'/delete/', 'Delete', True)] for deb in team.debaters.all(): links.append(('/debater/'+str(deb.id)+'/', "View %s" % deb.name, False)) return render_to_response('data_entry.html', {'title':"Viewing Team: %s"%(team.name), 'form': form, 'links': links, 'team_obj':team, 'team_stats':stats}, context_instance=RequestContext(request)) return render_to_response('data_entry.html', {'form': form}, context_instance=RequestContext(request))
def edit(team_id): team = Team.query.get(team_id) form = TeamForm(obj=team) del form.number if request.method == 'POST' and form.validate_on_submit(): form.populate_obj(team) db.session.commit() return redirect(url_for(".index")) elif request.method == 'POST': flash('Failed validation', 'danger alert-auto-dismiss') return render_template("teams/team_form.html", form=form, number=team.number, id=team.id)
def create_team(): team_form = TeamForm() team_form.course_id.choices = course_choices() team_form.project_id.choices = all_project_choices() if team_form.validate_on_submit(): rowcount = db.create_team({ 'name': team_form.name.data, 'course_id': team_form.course_id.data, 'project_id': team_form.project_id.data }) if rowcount == 1: flash('Team {} created'.format(team_form.name.data)) return redirect(url_for('all_teams')) return render_template('teams/add.html', form=team_form)
def signup_team(): form = TeamForm(request.form, csrf_enabled=False) if request.method == 'POST' and form.validate(): # If there is already a matching email, check password and update/delete team = Team.query.filter(Team.email == form.email.data).first() if team: # check password if team.check_password(form.password.data): # delete this entry if that option is checked if form.delete.data: db_session.delete(team) db_session.commit() flash('Listing deleted') return redirect('/teams/') else: team.name = form.name.data team.abbrv = form.abbrv.data team.region = form.region.data team.contact = form.contact.data team.player1 = form.player1.data team.player2 = form.player2.data team.player3 = form.player3.data team.player4 = form.player4.data team.player5 = form.player5.data team.player6 = form.player6.data team.player7 = form.player7.data team.summary = form.summary.data db_session.commit() flash('Listing updated') return redirect('/teams/') else: # password is wrong flash('Incorrect credentials') return redirect('/teams/') else: # create a new entry team = Team(email=form.email.data, password=form.password.data, name=form.name.data, abbrv=form.abbrv.data, region=form.region.data, contact=form.contact.data, player1=form.player1.data, player2=form.player2.data, player3=form.player3.data, player4=form.player4.data, player5=form.player5.data, player6=form.player6.data, player7=form.player7.data, summary=form.summary.data) db_session.add(team) db_session.commit() flash('Thanks for registering your team') return redirect('/teams/') return render_template("signup-team.html", form=form)
def create(request): if request.method == 'POST': form = TeamForm(request.POST) if form.is_valid(): profile = request.user.teamprofile team = profile.create_team(form.cleaned_data['name']) return HttpResponseRedirect(reverse('teams_view', args=[team.id])) else: form = TeamForm() return render_to_response("teams/add.html", { "form": form, }, context_instance=RequestContext(request) )
def edit_team(team_id): if not current_user.is_admin and not current_user.team_id == team_id: abort(403) team = Team.query.get_or_404(team_id) form = TeamForm() if form.validate_on_submit(): team.name = form.name.data team.first_teammate_name = form.first_teammate_name.data team.second_teammate_name = form.second_teammate_name.data db.session.commit() flash('!פרטי הצוות עודכנו בהצלחה', 'success') return redirect(url_for('view_team', team_id=team.id)) elif request.method == 'GET': form.name.data = team.name form.first_teammate_name.data = team.first_teammate_name form.second_teammate_name.data = team.second_teammate_name return render_template('/edit_team.html', form=form, team_id=team_id)
def view_team(request, team_id): team_id = int(team_id) try: team = Team.objects.get(pk=team_id) stats = [] stats.append(("Wins", tab_logic.tot_wins(team))) stats.append(("Total Speaks", tab_logic.tot_speaks(team))) stats.append(("Govs", tab_logic.num_govs(team))) stats.append(("Opps", tab_logic.num_opps(team))) stats.append(("Opp Wins", tab_logic.opp_strength(team))) stats.append(("Been Pullup", tab_logic.pull_up_count(team))) stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team))) except Team.DoesNotExist: return render_to_response('error.html', { 'error_type': "View Team", 'error_name': str(team_id), 'error_info': "No such Team" }, context_instance=RequestContext(request)) if request.method == 'POST': form = TeamForm(request.POST, instance=team) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', { 'error_type': "Team", 'error_name': "[" + form.cleaned_data['name'] + "]", 'error_info': "Team name cannot be validated, most likely a non-existent team" }, context_instance=RequestContext( request)) return render_to_response( 'thanks.html', { 'data_type': "Team", 'data_name': "[" + form.cleaned_data['name'] + "]" }, context_instance=RequestContext(request)) else: form = TeamForm(instance=team) links = [('/team/' + str(team_id) + '/scratches/view/', 'Scratches for ' + str(team.name), False), ('/team/' + str(team_id) + '/delete/', 'Delete', True)] for deb in team.debaters.all(): links.append( ('/debater/' + str(deb.id) + '/', "View %s" % deb.name, False)) return render_to_response('data_entry.html', { 'title': "Viewing Team: %s" % (team.name), 'form': form, 'links': links, 'team_obj': team, 'team_stats': stats }, context_instance=RequestContext(request)) return render_to_response('data_entry.html', {'form': form}, context_instance=RequestContext(request))
def post(self, slug): team, _, is_admin = self.validate(slug) if team is None: return if not is_admin: return self.redirect("/t/%s" % team.primary_slug) form = TeamForm(self.request.POST, team) if not form.validate(): return self.render_template("edit_team.html", form=form) form.populate_obj(team) team.primary_slug = Slug.new(team) try: result = config_NOCOMMIT.pledge_service.updateMailchimp(team) except Exception as e: logging.error('Exception updating mailChimp: ' + str(e)) logging.info(traceback.format_exc()) team.put() self.redirect("/t/%s" % team.primary_slug)
def get(self, slug): team, primary, is_admin = self.validate(slug) if team is None: return if not primary: return self.redirect("/t/%s/edit" % team.primary_slug, permanent=True) if not is_admin: return self.redirect("/t/%s" % team.primary_slug) self.render_template("edit_team.html", form=TeamForm(obj=team))
def new(): form = TeamForm() if request.method == 'POST': if form.validate_on_submit(): name = request.form['name'] email = request.form['email'] mate_email = request.form['mate_email'] password = hashlib.md5( request.form['password'].encode('utf-8')).hexdigest() my_team = Team.query.filter_by(name=name).first() if not my_team: if request.form['password'] == request.form['password2']: my_team = Team(request.form['name'], request.form['email'], request.form['mate_email'], request.form['password']) db.session.add(my_team) try: db.session.commit() # Envio de email msg = Message("Hello", sender="*****@*****.**", recipients=[my_team.email]) link_token = f'http://localhost:5000/activate/{my_team.token}' msg.html = render_template('emails/access.html', link_token=link_token) mail.send(msg) # Informamos al usuario flash('Confirmar email en su bandeja de entrada', 'success') except: db.session.rollback() flash('Disculpe, ha ocurrido un error', 'danger') return redirect(url_for('new')) else: flash('Las contraseñas no coinciden', 'danger') else: flash('El email ya está registrado', 'danger') else: todos_errores = form.errors.items() for campo, errores in todos_errores: for error in errores: flash(error, 'danger') return render_template('items/new.html', form=form)
def new_team(): formpage = TeamForm() if formpage.validate_on_submit(): sport = formpage.sport.data team = Teams( name=formpage.name.data, description=formpage.description.data, members=current_user.name + ' Cel: ' + current_user.phone + ' ', players_number=formpage.players_number.data, vacant=formpage.players_number.data - 1, sport=formpage.sport.data, begginer=current_user, ) db.session.add(team) db.session.commit() flash('Your new team has been created!', 'success') return redirect(url_for(sport)) return render_template('new_team.html', title='Create New Team', formpage=formpage)
def teamname(): #Determinant for current season max_teams = 0 teams = None team_count = 0 current_season = model.session.query(model.SeasonCycle).\ order_by(model.SeasonCycle.id.desc()).first() print current_season.id if current_season is not None: # created teams by cycle.id teams = model.session.query(model.Team).\ filter(model.Team.seasoncycle == current_season.id).\ all() team_count = len(teams) # number of teams based on season cycle max_teams = current_season.num_of_teams #Create Team Names form = TeamForm() if form.validate_on_submit(): new_team = model.session.\ add(model.Team(teamname= form.teamname.data, seasoncycle= current_season.id)) model.session.commit() return redirect('team_names') return render_template('team_names.html', title='Teamname', form=form, max_teams=max_teams, teams=teams, team_count=team_count, current_season=current_season)
def teamname(): #Determinant for current season max_teams = 0 teams = None team_count = 0 current_season = model.session.query(model.SeasonCycle).\ order_by(model.SeasonCycle.id.desc()).first() print current_season.id if current_season is not None: # created teams by cycle.id teams = model.session.query(model.Team).\ filter(model.Team.seasoncycle == current_season.id).\ all() team_count= len(teams) # number of teams based on season cycle max_teams = current_season.num_of_teams #Create Team Names form = TeamForm() if form.validate_on_submit(): new_team = model.session.\ add(model.Team(teamname= form.teamname.data, seasoncycle= current_season.id)) model.session.commit() return redirect('team_names') return render_template('team_names.html', title='Teamname', form=form, max_teams=max_teams, teams= teams, team_count= team_count, current_season=current_season)
def post(self): form = TeamForm(self.request.POST) if not form.validate(): return self.render_template("new_team.html", form=form) team = Team.create(title=form.title.data, description=form.description.data, goal_dollars=form.goal_dollars.data, youtube_id=form.youtube_id.data, zip_code=form.zip_code.data) # TODO: can i reference a team before putting it in other reference # properties? should check team.primary_slug = Slug.new(team) try: result = config_NOCOMMIT.pledge_service.updateMailchimp(team) except Exception as e: logging.error('Exception updating mailChimp: ' + str(e)) logging.info(traceback.format_exc()) team.put() makeUserAdmin(self.current_user["user_id"], team) return self.redirect("/t/%s" % team.primary_slug)
def register_team(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) team_form = TeamForm(request.POST, request.FILES) if user_form.is_valid(): if team_form.is_valid(): user = user_form.save() # do i need these two lines anymore? Django 1.5, i think, handles this automatically now. password = user.password user.set_password(password) user.save() t = team_form.save(commit=False) t.user = user t.save() registered = True user = authenticate(username=user.username, password=password) login(request, user) return HttpResponseRedirect('/showcase/team/' + str(t.id) + '/') else: print user_form.errors, team_form.errors else: user_form = UserForm() team_form = TeamForm() # Render the template depending on the context. return render_to_response('showcase/team_registration.html', { 'user_form': user_form, 'team_form': team_form, 'registered': registered }, context)
def edit_team(request, id): team = get_object_or_404(Team, pk=id) subject = get_object_or_404(Subject, team_id=id) if request.method == "POST": form = TeamForm(request.POST, request.FILES, instance=team) second_form = SubjectFormDesc(request.POST, request.FILES, instance=subject) if form.is_valid() and second_form.is_valid(): team = form.save(commit=False) subject = second_form.save(commit=False) subject.name = team.name subject.team_id = team.id subject.save() team.save() messages.success(request, "the " + team.name + " was edited!") return redirect(reverse('get_team', args={team.pk})) else: messages.error(request, 'Please correct the errors below.') else: form = TeamForm(instance=team) second_form = SubjectFormDesc(instance=subject) return render( request, 'form.html', { 'form': form, 'cancelview': 'get_team', 'cancelid': team.id, 'second_form': second_form, 'heading_text': 'You are editing the ' + team.name + ' Team?', 'button_text': 'Save Changes', })
def dashboard_edit_team(team_id): team = Team.query.get(team_id) if team is None: abort(404) form = TeamForm(request.form, team) if request.method == 'POST' and form.validate(): team.name = form.name.data users_in = request.form.getlist('selected-users') users_out = request.form.getlist('available-users') users = User.query.filter(User.id.in_(users_in)).all() for user in users: if user not in team.users: team.users.append(user) users = User.query.filter(User.id.in_(users_out)).all() for user in users: if user in team.users: team.users.remove(user) return redirect(url_for('dashboard.dashboard_teams')) return render_template('create_team.html', form=form, team_id=team_id)
def create(request): if request.POST: form = TeamForm(request.POST) if form.is_valid(): team = form.save() user = request.user assign_perm('view_team', user, team) return HttpResponseRedirect('/team/all') else: form = TeamForm() args = {} args.update(csrf(request)) #form.fields['tournament'] = Tournament.objects.all() args['form'] = form args['form'].fields['tournament']= get_objects_for_user(request.user , 'tournament_creator.view_tournament') args['tournament'] = Tournament.objects.all() return render_to_response('create_team.html', args)
def login(): form = TeamForm() if request.args.get('name') and request.args.get('password'): name = request.args.get('name') password = hashlib.md5( request.args.get('password').encode('utf-8')).hexdigest() my_team = Team.query.filter_by(name=name, password=password).first() if my_team: # Existe session['team'] = my_team.name return redirect(url_for('home')) else: # Mostramos error flash('Su email o contraseña no es correcto', 'danger') return render_template('items/login.html', form=form)
def edit_team(request, tid=None): """ Add a new Group entity or edit an existing one, and a Team entity is saved along with it. """ if not tid: tid = request.REQUEST.get('tid', None) if tid: team = get_object_or_404(Group, pk=tid) else: team = None if request.method == 'POST': form = TeamForm(request.POST, instance=team) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form = TeamForm(instance=team) return render(request, 'team_edit', {'form':form, 'team':team}, 'staff/')
def new_team(request): if request.method == "POST": team_form = TeamForm(request.POST) subject_form_desc = SubjectFormDesc(request.POST) if team_form.is_valid() and subject_form_desc.is_valid(): team = team_form.save(commit=False) subject = subject_form_desc.save(commit=False) subject.name = team.name team.save( ) # needs to be here so team.id is created before subject.team_id subject.team_id = team.id subject.save() messages.success(request, "You have added the " + team.name + " Team!") return redirect("get_team", team.id) else: messages.error(request, 'Please correct the errors below.') else: team_form = TeamForm() subject_form_desc = SubjectFormDesc() '''delete this when im sure form.html working return render(request, 'team_subject_form.html', {'team_form': team_form, 'cancelview': 'profile', 'subject_form_desc': subject_form_desc, 'heading_text': 'You are creating a new Team!', 'button_text': 'Save Team', })''' return render( request, 'form.html', { 'form': team_form, 'second_form': subject_form_desc, 'cancelview': 'profile', 'heading_text': 'You are creating a new Team!', 'button_text': 'Save Team', })
def post(self): user = tusers.get_current_user() #Get the requested tournament tid = self.request.get('t') key = ndb.Key('Tournament', int(tid)) t = key.get() reg = t.preRegRecord().get() if user: form = TeamForm(self.request.POST) if (form.validate()): #If we are updating an existing registration, update it. if 'teamkey' in self.request.arguments(): teamkey = (self.request.get('teamkey')) team = ndb.Key(urlsafe=teamkey).get() #Check they own it if team.user != user.key: self.redirect('/reg?t=' + tid) #Otherwise, make a new team registration else: #Check they haven't registered already if reg.isRegistered(user): self.redirect('/reg?t=' + tid) return team = RegisteredOpenTeam(parent=reg.key) team.user = user.key team.teamName = form.teamName.data team.sp1Name = form.sp1Name.data team.sp2Name = form.sp2Name.data team.sp1ESL = form.sp1ESL.data team.sp2ESL = form.sp2ESL.data team.sp1Novice = form.sp1Novice.data team.sp2Novice = form.sp2Novice.data team.user = user.key team.put() self.redirect('/reg?t=' + tid) else: logging.info('invalid form') template_values = { 'user' : user, 't' : t, 'logout' : tusers.create_logout_url('/'), 'login' : tusers.create_login_url('/reg/team?t=' + tid), 'r' : reg, 'form' : form } template = JINJA_ENVIRONMENT.get_template('view/regteam.html') self.response.write(template.render(template_values)) else: self.redirect('/reg?t=' + tid)
def get(self): self.render_template("new_team.html", form=TeamForm())
def team_create(): form = TeamForm(user=current_user) if form.validate_on_submit(): return redirect(url_for('team_show', team_id=form.team.id)) return render_template('team/form.html', form=form)