def clean_game_id(self): game_id = self.cleaned_data.get('game_id', '') try: int(game_id) from film20.contest.contest_helper import ContestHelper contest_helper = ContestHelper() self.the_game = contest_helper.get_game_by_id(game_id) if self.the_game is None: logger.debug("Game not found for game_id="+str(game_id)) raise forms.ValidationError(_("Game not found for game_id="+str(game_id))) except ValueError: logger.debug("game_id must be integer!") raise forms.ValidationError(_("game_id must be integer!")) return int(game_id)
def clean_game_id(self): game_id = self.cleaned_data.get('game_id', '') try: int(game_id) from film20.contest.contest_helper import ContestHelper contest_helper = ContestHelper() self.the_game = contest_helper.get_game_by_id(game_id) if self.the_game is None: logger.debug("Game not found for game_id=" + str(game_id)) raise forms.ValidationError( _("Game not found for game_id=" + str(game_id))) except ValueError: logger.debug("game_id must be integer!") raise forms.ValidationError(_("game_id must be integer!")) return int(game_id)
def clean_character_id(self): character_id = self.cleaned_data.get('character_id', '') try: int(character_id) from film20.contest.contest_helper import ContestHelper contest_helper = ContestHelper() self.the_character = contest_helper.get_character_from_game(self.the_game, character_id) logger.debug(self.the_character) if self.the_character is None: logger.debug("Character not found in game, id="+str(character_id)) raise forms.ValidationError(_("Character not found in game, id="+str(character_id))) except ValueError: logger.debug("character_id must be integer!") raise forms.ValidationError(_("character_id must be integer!")) return int(character_id)
def show_contest(request, contest_permalink=None): """ Schedule for character contest """ the_contest = None the_games = None contest_helper = ContestHelper() try: if contest_permalink is None: the_contest = contest_helper.get_current_contest() else: the_contest = contest_helper.get_contest_by_permalink(contest_permalink) the_games = contest_helper.get_all_games_for_contest(the_contest.permalink) level32, level16, level8, quarter_final, semi_final, final = contest_helper.get_games_by_level(the_games) except NoOpenContestException, e: raise Http404
def clean_character_id(self): character_id = self.cleaned_data.get('character_id', '') try: int(character_id) from film20.contest.contest_helper import ContestHelper contest_helper = ContestHelper() self.the_character = contest_helper.get_character_from_game( self.the_game, character_id) logger.debug(self.the_character) if self.the_character is None: logger.debug("Character not found in game, id=" + str(character_id)) raise forms.ValidationError( _("Character not found in game, id=" + str(character_id))) except ValueError: logger.debug("character_id must be integer!") raise forms.ValidationError(_("character_id must be integer!")) return int(character_id)
def show_game(request, contest_permalink=None, game_permalink=None, ajax=None): """ Simple view that show a single game with options to vote for the characters """ the_contest = None the_game_vote = None contest_helper = ContestHelper() if request.POST: if (not request.user.is_authenticated()): if ajax==None: return HttpResponseRedirect(full_url('LOGIN') + '?next=%s' % request.path) elif ajax=='json': return json_error("LOGIN") voting_form = VotingForm(request.POST) if voting_form is not None: logger.debug("Voting form submitted.") if voting_form.is_valid(): logger.debug("Voting form valid.") contest_helper.vote(voting_form.the_game, voting_form.the_character, request.user) if ajax == "json": context = { 'success': True, 'data': request.user.id, } logger.debug("Sending ajax response.") return json_return(context) else: logger.debug("Voting form invalid.") else: logger.debug("Voting form not submitted.") try: if contest_permalink is None: the_contest = contest_helper.get_current_contest() else: the_contest = contest_helper.get_contest_by_permalink(contest_permalink) if game_permalink is None: the_game = contest_helper.get_game_for_date(the_contest, datetime.today()) else: the_game = contest_helper.get_game_by_permalink(game_permalink) if request.user.is_authenticated(): the_game_vote = contest_helper.get_vote_for_game(the_game, request.user) votes_for_character1 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character1) votes_for_character2 = contest_helper.get_votes_for_character_in_game(the_game, the_game.character2) if the_game_vote is None: voting_form1 = contest_helper.prepare_voting_form1(the_game) voting_form2 = contest_helper.prepare_voting_form2(the_game) else: # no need for forms if already voted voting_form1 = None voting_form2 = None except NoOpenContestException, e: raise Http404