def new(request): title = "New Contest" if can_create_contest(request.user): if request.method == 'GET': form = ContestForm(initial=\ {'owner':request.user, 'user':request.user, 'method':request.method}) return render_index(request,'contest/editContest.html', {'form':form,'title':title}) if request.method == 'POST': form = ContestForm(request.POST, initial={'method':request.method}) if form.is_valid(): new_contest = form.save() logger.info('Contest: User %s Create a new contest %s!' % (request.user ,new_contest.id)) message = 'Contest %s- "%s" created!' % (new_contest.id, new_contest.cname) messages.success(request, message) return redirect('contest:contest', new_contest.id) else: message = 'Some fields are invalid!' messages.error(request, message) return render_index(request,'contest/editContest.html', {'form':form,'title':title}) raise PermissionDenied
def new(request): title = "New Contest" if can_create_contest(request.user): if request.method == "GET": form = ContestForm(initial={"owner": request.user, "user": request.user, "method": request.method}) return render_index(request, "contest/editContest.html", {"form": form, "title": title}) if request.method == "POST": form = ContestForm(request.POST, initial={"method": request.method}) if form.is_valid(): new_contest = form.save() logger.info("Contest: User %s Create a new contest %s!" % (request.user, new_contest.id)) message = 'Contest %s- "%s" created!' % (new_contest.id, new_contest.cname) messages.success(request, message) return redirect("contest:contest", new_contest.id) else: message = "Some fields are invalid!" messages.error(request, message) return render_index(request, "contest/editContest.html", {"form": form, "title": title}) raise PermissionDenied
def new(request): title = "New Contest" if can_create_contest(request.user): if request.method == 'GET': form = ContestForm( initial={ 'owner': request.user, 'user': request.user, 'method': request.method }) return render_index(request, 'contest/editContest.html', { 'form': form, 'title': title }) if request.method == 'POST': form = ContestForm(request.POST, initial={'method': request.method}) if form.is_valid(): new_contest = form.save() logger.info('Contest: User %s Create a new contest %s!' % (request.user, new_contest.id)) message = 'Contest %s- "%s" created!' % (new_contest.id, new_contest.cname) messages.success(request, message) return redirect('contest:contest', new_contest.id) else: message = 'Some fields are invalid!' messages.error(request, message) return render_index(request, 'contest/editContest.html', { 'form': form, 'title': title }) raise PermissionDenied
def can_create_contest(user): return contest_info.can_create_contest(user)