def register(): global player1 global player2 form = GameForm() if form.validate_on_submit(): player1 = Player(name=form.playerOne.data) player2 = Player(name=form.playerTwo.data) return redirect(url_for('pageGame')) return render_template('form.html', title='Form', form=form)
def game_create(): if current_user.is_admin: form = GameForm() if form.validate_on_submit(): new_game = Game(nama=form.nama.data, deskripsi=form.deskripsi.data, is_rental=False) db.session.add(new_game) db.session.commit() return redirect(url_for('game_index')) return render_template('game/create.html', form=form, current_user=current_user) else: return redirect(url_for('game_index'))
def create_game(): form = GameForm() if form.validate_on_submit(): game = Game(title=form.title.data, desc=form.desc.data, poster=form.poster.data, release_date=form.release_date.data, price=form.price.data, on_sale=form.on_sale.data) db.session.add(game) db.session.commit() return redirect(url_for('get_game', game_id=game.id)) return render_template('new_game.html', form=form)
def game_update(game_id): if current_user.is_admin: form = GameForm() if form.validate_on_submit(): updated_game = Game.query.filter_by(id=game_id).first() updated_game.nama = form.nama.data updated_game.deskripsi = form.deskripsi.data db.session.commit() return redirect(url_for('game_index')) else: game = Game.query.filter_by(id=game_id).first() form = GameForm(id=game.id, nama=game.nama, deskripsi=game.deskripsi) return render_template('game/update.html', form=form, current_user=current_user) else: return redirect(url_for('game_index'))
def game_edit(game_id): form = GameForm() form.genres.choices = models.Genre.query.with_entities(models.Genre.id, models.Genre.name) \ .order_by(models.Genre.name.asc()) game = models.Game.query.get_or_404(game_id) platform = game.platform if form.validate_on_submit(): game.name = form.name.data game.desc = form.desc.data game.id_genres = form.genres.data db.session.add(game) db.session.commit() return redirect("/Game/%s" % (game_id)) else: form.genres.default = game.id_genres form.process() return render_template("game_edit.html", title="Game Edit", platform=platform, game=game, form=form)
def game(): if 'user' not in session: return render_template("home.html", message="You are not logged in.") else: form = GameForm() if form.validate_on_submit(): new_game = Game(game_id=(Game.query.count()) + 1, title=form.game.data) db.session.add(new_game) try: db.session.commit() except Exception as e: print(e) db.session.rollback() return render_template("game.html", form=form, message="Something went wrong.") finally: db.session.close() return render_template("game.html", message="Successfully added a game.") return render_template('game.html', form=form)
def game(): form = GameForm() user = g.user games = Game.query.all() if form.validate_on_submit(): game_name = form.game_name.data game_description = form.game_description.data game = Game(game_name=game_name,game_description=game_description) db.session.add(game) db.session.commit() flash('Your game has been added') return redirect(url_for('game')) return render_template("game.html", title='Games', user=user, games=games, form=form)
def game_form(username): form = GameForm(request.form) print("request: ", request.method) if form.validate_on_submit(): game = { "nome": form.name.data, "categoria": form.categoria.data, "url": form.url_game.data, } if form.url_image.data: game["url_image"] = form.url_image.data if form.description.data: game["description"] = form.description.data game["autor"] = username flash(add_game(game)) return render_template('game_form.html', form=form, author=username)
def edit_game(id): """Edit extisting game""" check_admin() add_game = False game = Game.query.get_or_404(id) form = GameForm(obj=game) # Checks if form is valid if form.validate_on_submit(): game.name = form.name.data db.session.commit() flash('Game successfully edited') return redirect(url_for('admin.list_games')) form.name.data = game.name return render_template('admin/games/game.html', action='Edit', add_game=add_game, form=form, game=game, title='Edit Game')
def add_game(): """Adds game to database""" check_admin() add_game = True form = GameForm() # Checks if form is valid if form.validate_on_submit(): game = Game(name=form.name.data) try: db.session.add(game) db.session.commit() flash('Game successfully added') except: flash('Error: game name already exists') return redirect(url_for('admin.list_games')) return render_template('admin/games/game.html', action='Add', add_game=add_game, form=form, title='Add Game')
def get_calendar(): form = GameForm() today = request.args.get('month') if today == None: today = datetime.date(datetime.now()) print today # --------calendar begins---------# year = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] # by default the calendar begin the week with Monday (day 0) calendar.setfirstweekday(calendar.SUNDAY) #stiringify date and reorganize into integers current = re.split('-', str(today)) current_no = int(current[1]) current_month = year[current_no - 1] current_day = int(re.sub('\A0', '', current[2])) current_yr = int(current[0]) month = calendar.monthcalendar(current_yr, current_no) nweeks = len(month) each_week = [] for w in range(0, nweeks): week = month[w] each_week.append(week) #---------------calender ends-----------# #-----add matches--------# all_teams = model.current_teams() teams = {} for t in all_teams: teams[t.id] = t.teamname # render template to set games form = GameForm() games = model.session.query(model.Game).\ order_by(model.Game.game_date.desc()).all() if form.validate_on_submit(): if form.home_team.data == form.away_team.data: flash("Teams cannot be the same") return redirect('calendar') else: new_game= model.session.\ add(model.Game(game_date = form.game_date.data, home_team = form.home_team.data, away_team = form.away_team.data, home_score = form.home_score.data, away_score = form.away_score.data)) model.session.commit() flash('Game Added!') return redirect('calendar') #----------render form to change score---# form_s = ScoreForm() return render_template('calendar.html', title='Calendar', current_month=current_month, current_yr=current_yr, each_week=each_week, user=current_user, form=form, games=games, form_s=form_s, all_teams=all_teams, teams=teams)
def get_calendar(): form = GameForm() today = request.args.get('month') if today == None: today = datetime.date(datetime.now()) print today # --------calendar begins---------# year = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] # by default the calendar begin the week with Monday (day 0) calendar.setfirstweekday(calendar.SUNDAY) #stiringify date and reorganize into integers current = re.split('-', str(today)) current_no = int(current[1]) current_month = year[current_no - 1] current_day = int(re.sub('\A0', '',current[2])) current_yr = int(current[0]) month = calendar.monthcalendar(current_yr, current_no) nweeks = len(month) each_week=[] for w in range(0,nweeks): week = month[w] each_week.append(week) #---------------calender ends-----------# #-----add matches--------# all_teams = model.current_teams() teams={} for t in all_teams: teams[t.id]=t.teamname # render template to set games form= GameForm() games = model.session.query(model.Game).\ order_by(model.Game.game_date.desc()).all() if form.validate_on_submit(): if form.home_team.data == form.away_team.data: flash("Teams cannot be the same") return redirect('calendar') else: new_game= model.session.\ add(model.Game(game_date = form.game_date.data, home_team = form.home_team.data, away_team = form.away_team.data, home_score = form.home_score.data, away_score = form.away_score.data)) model.session.commit() flash('Game Added!') return redirect('calendar') #----------render form to change score---# form_s = ScoreForm() return render_template('calendar.html', title='Calendar', current_month= current_month, current_yr= current_yr, each_week = each_week, user= current_user, form=form, games=games, form_s=form_s, all_teams=all_teams, teams=teams )
def add_game(): form = GameForm() error = '' developers = '[' for developer in Developer.query.filter(Developer.id>0).order_by(Developer.type): developer.name = developer.name.replace("'", "\\'") developer.name = developer.name.replace('"', '\\"') developers += '"'+developer.name+'",' developers = developers[:-1] developers += ']' #creators = '["PunkCabbageRabbit","Akane","flowerthief","Lemma Soft","Zeiva Inc.","ATP Projects","Grey","American Bishoujo","Ren\'Ai Games","Chronoluminaire","Gloranor"]' if form.validate_on_submit(): game_title=form.game_title.data slug=form.slug.data homepage_link_url=form.homepage_link_url.data developer_name=form.creator.data maker=developer_name creator_type=form.creator_type.data description = form.description_.data age_rating_id=str(form.age_rating_id.data) categories = form.categories.data words = form.words.data words = words.replace(",", "") words = words.replace(".", "") try: words = int(re.search(r'(0|(-?[1-9][0-9]*))', words).group(0)) except: # Catch exception if re.search returns None words = 0 if not words: words = 0 playtime = 0 if form.playtime.data: try: playtime = float(form.playtime.data) except: try: playtime = int(re.search(r'(0|(-?[1-9][0-9]*))', form.playtime.data).group(0)) except: # Catch exception if re.search returns None playtime = 0 if form.playtime_unit.data == 'hours': playtime = playtime * 60 playtime = int(math.ceil(playtime)) else: playtime = playtime if words == 0: words_estimate = playtime*200 else: words_estimate = words listed_on = form.listed_on.data if listed_on: listed_on = 3 # both else: listed_on = 2 # games.renpy.org only game = Game(game_title=game_title, slug=slug, maker = maker, description = description, age_rating_id=age_rating_id, words = words, words_estimate=words_estimate, playtime = playtime, developer_id=1, user_id=g.user.id, approved=False, listed_on=listed_on) db.session.add(game) db.session.commit() release = Release(game_id=game.id, release_date=form.release_date.data, release_version=form.release_version.data, engine_id=form.engine_id.data, release_description = form.release_description.data, engine_version = form.engine_version.data, user_id=g.user.id) save_release(release, form.platforms.data) #save new creator if it doesn't exists: developer_name = developer_name.replace("'", "") developer = Developer.query.filter(Developer.name==developer_name).first() if not developer: if creator_type=='person': type=1 person = Person('') db.session.add(person) db.session.commit() developer = Developer (developer_name, type, g.user.id, person_id=person.id) if creator_type=='group': type=2 group = Group('') db.session.add(group) db.session.commit() developer = Developer (developer_name, type, g.user.id, group_id=group.id) db.session.add(developer) #save homepage link to link_game table: links_game= LinkGame(game_id=game.id, url=homepage_link_url, name = 'Home Page', link_type_id = '1') db.session.add(links_game) #save the categories to category_game: for category_id in categories: categories_game = CategoryGame(game_id=game.id, category_id=category_id) db.session.add(categories_game) db.session.commit() game.developer_id = developer.id db.session.commit() flash('New game was successfully added. The game must be approved by a moderator, before it will show up on the site. This might take a couple of days, depending on how busy we are.') return redirect(url_for("index")) return render_template('add_game.html', navigation=return_navigation(), error=error, site_data=site_data(), form=form, developers=developers, edit=False)