コード例 #1
0
def game_submit():
    form = GameSubmitForm()
    if form.validate_on_submit():
        if Game.query.filter(func.lower(Game.name) == func.lower(form.name.data)).first():
            flash("This game has already been submitted.", "danger")
            return render_template("submitgame.html", title="Game Submission", form=form)
        gameToAdd = Game(form.name.data)
        db.session.add(gameToAdd)
        db.session.commit()
        flash("The game was successfully submitted!", "success")
        return redirect(url_for("game_submit"))
    flash_errors(form)
    return render_template("submitgame.html", title="Game Submission", form=form)
コード例 #2
0
ファイル: views.py プロジェクト: hnphan/cerberus
def submitGame(request):
	if request.user.is_authenticated():
		if request.method == 'POST':
			form = GameSubmitForm(request.POST, request.FILES)
			if form.is_valid():
				# Process the data
				newgame = models.Package(title=request.POST['title'],
					developer = request.user,
					package_file = request.FILES['package_file'],
					category = cmodels.Category.objects.get(pk=request.POST['category']),
					square_icon=request.FILES['square_icon'],
					#caption_picture=request.FILES['caption_picture'],
					version=request.POST['version'])
				newgame.save()

				return HttpResponseRedirect('/')
		else:
			form = GameSubmitForm()
		return render(request, "games/submit.html", {'form': form})
	else:
		return HttpResponseRedirect('/accounts/login/')