def send_contractor_on_game(self, character): game = Game( scenario=self.scenario, title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=WIN, attending_character=character, ) game_invite = Game_Invite(invited_player=character.player, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() return attendance
def accept_invite(request, game_id): game = get_object_or_404(Game, id=game_id) if not game.player_can_rsvp(request.user): raise PermissionDenied(game.reason_player_cannot_rsvp(request.user)) invite = get_object_or_none( request.user.game_invite_set.filter(relevant_game=game.id)) if request.method == 'POST': if not invite: # player self-invite invite = Game_Invite(invited_player=request.user, relevant_game=game) if game.scenario in request.user.scenario_set.all(): invite.as_ringer = True form = make_accept_invite_form(invite)(request.POST) if form.is_valid(): game_attendance = invite.attendance with transaction.atomic(): invite.save() if game_attendance: game_attendance.attending_character = form.cleaned_data[ 'attending_character'] game_attendance.save() else: game_attendance = Game_Attendance( attending_character=form. cleaned_data['attending_character'], relevant_game=game, ) game_attendance.save() invite.is_declined = False invite.attendance = game_attendance invite.save() if invite.as_ringer and not form.cleaned_data[ 'attending_character']: #Reveal scenario to ringer game.scenario.played_discovery(request.user) return HttpResponseRedirect( reverse('games:games_view_game', args=(game.id, ))) else: print(form.errors) return None else: can_view_scenario = False if request.user.has_perm("view_scenario", game.scenario): can_view_scenario = True # Build a accept form. if not invite: # if game is open for self-invites, make a temp invite that we don't save so we can make a form invite = Game_Invite(invited_player=request.user, relevant_game=game) if game.scenario in request.user.scenario_set.all(): invite.as_ringer = True form = make_accept_invite_form(invite) context = { 'form': form, 'game': game, 'invite': invite, 'can_view_scenario': can_view_scenario, } return render(request, 'games/accept_invite.html', context)
def test_archive_game_gm_rewards_ratio(self): self.assertEquals(self.user2.experiencereward_set.filter(rewarded_character=None).all().count(), 0) self.assertEquals( self.user2.rewarded_player.filter(rewarded_character=None, is_charon_coin=False).filter(is_void=False).all().count(), 0) game = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=WIN, attending_character=self.char_user1_cell, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=DEATH, attending_character=self.char_user2_cell, ) game_invite = Game_Invite(invited_player=self.user2, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() self.assertEquals(self.user2.experiencereward_set.filter(rewarded_character=None).all().count(), 1) self.assertEquals(self.user2.rewarded_player.filter(rewarded_character=None, is_charon_coin=False).filter(is_void=False).all().count(), 1)
def test_archive_game_death(self): self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 0) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals( self.user1.rewarded_player .filter(rewarded_character=None, is_charon_coin=True) .filter(is_void=False).all().count(), 0) game = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=OUTCOME[2][0], # death attending_character=self.char_user1_cell, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 1) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.char_user1_cell.is_dead(), True) self.assertEquals( self.user1.rewarded_player .filter(rewarded_character=None, is_charon_coin=True) .filter(is_void=False).all().count(), 1)
def test_archive_game_victory_not_in_cell(self): self.assertEquals(self.char_user2_nocell.unspent_rewards().count(), 0) self.assertEquals(self.char_user2_nocell.unspent_gifts().count(), 0) self.assertEquals(self.char_user2_nocell.completed_games().count(), 0) self.assertEquals(self.char_user2_nocell.number_of_victories(), 0) self.assertEquals(self.char_user2_nocell.number_of_losses(), 0) self.assertEquals(self.char_user2_nocell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user2_nocell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.user2.game_invite_set.filter(attendance__is_confirmed=False).exclude(is_declined=True).all().count(), 0) game = Game( title="title", creator=self.user1, gm=self.user1, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=OUTCOME[0][0], # victory attending_character=self.char_user2_nocell, is_confirmed = False, ) game_invite = Game_Invite(invited_player=self.user2, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() self.assertEquals(self.char_user2_nocell.unspent_rewards().count(), 0) self.assertEquals(self.char_user2_nocell.unspent_gifts().count(), 0) self.assertEquals(self.char_user2_nocell.completed_games().count(), 0) self.assertEquals(self.char_user2_nocell.number_of_victories(), 0) self.assertEquals(self.char_user2_nocell.number_of_losses(), 0) self.assertEquals(self.char_user2_nocell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user2_nocell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.user2.game_invite_set.filter(attendance__is_confirmed=False).exclude(is_declined=True).all().count(), 1)
def setUp(self): self.user1 = User.objects.create_user(username='******', email='jacob@…', password='******') make_profile_for_new_user(None, self.user1) self.user2 = User.objects.create_user(username='******', email='jacob@2…', password='******') make_profile_for_new_user(None, self.user2) self.cell_owner = User.objects.create_user(username='******', email='jacob@23…', password='******') self.cell = Cell.objects.create(name="cell name", creator=self.cell_owner, setting_name="world name", setting_description="Test description") self.char1 = Character.objects.create( name="testchar1", tagline="they test so bad!", player=self.user1, appearance="they're ugly because that's better.", age="13 years", sex="taco bell", concept_summary="generic but relatable", ambition="eat a dragon's heart", private=True, pub_date=timezone.now(), edit_date=timezone.now(), cell=self.cell) self.char2 = Character.objects.create( name="testchar2", tagline="they test so bad!", player=self.user1, appearance="they're ugly because that's better.", age="13 years", sex="taco bell", concept_summary="generic but relatable", ambition="eat a dragon's heart", private=True, pub_date=timezone.now(), edit_date=timezone.now(), cell=self.cell) self.game1 = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) self.game1.save() self.attendance_game1_char1 = Game_Attendance( relevant_game=self.game1, notes="notes", outcome=WIN, attending_character=self.char1, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=self.game1, as_ringer=False) self.attendance_game1_char1.save() game_invite.attendance = self.attendance_game1_char1 game_invite.save() self.game1.give_rewards() self.game2 = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) self.game2.save() self.attendance_game2_char1 = Game_Attendance( relevant_game=self.game2, notes="notes", outcome=WIN, attending_character=self.char1, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=self.game2, as_ringer=False) self.attendance_game2_char1.save() game_invite.attendance = self.attendance_game2_char1 game_invite.save() self.game1.give_rewards() self.games = [] self.char1_attendances = [] for x in range(10): new_game = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) self.games.append(new_game) new_game.save() new_attendance = Game_Attendance( relevant_game=self.games[x], notes="notes", outcome=WIN, attending_character=self.char1, ) self.char1_attendances.append(new_attendance) new_attendance.save() game_invite = Game_Invite(invited_player=self.user1, relevant_game=new_game, as_ringer=False) game_invite.attendance = new_attendance game_invite.save() new_game.give_rewards()
def test_archive_game_recalculate_golden_ratio(self): with transaction.atomic(): game = Game( title="title", creator=self.user2, gm=self.cell_owner, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=WIN, attending_character=self.char_user1_cell, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() self.assertFalse(game.achieves_golden_ratio()) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.user2.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_improvements().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_exp_rewards().count(), 1) # cell_owner gmed the game attendance2 = Game_Attendance( relevant_game=game, notes="notes", outcome=DEATH, attending_character=self.char_user2_cell, ) game_invite = Game_Invite(invited_player=self.user2, relevant_game=game, as_ringer=False, ) attendance2.save() game_invite.attendance = attendance2 game_invite.save() attendance2.give_reward() game.refresh_from_db() game.recalculate_golden_ratio(False) self.assertTrue(game.achieves_golden_ratio()) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.user2.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 1) # from dying self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_improvements().count(), 1) # from ratio self.assertEquals(self.cell_owner.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_exp_rewards().count(), 1) # cell_owner gmed the game attendance2.refresh_from_db() attendance2.change_outcome(new_outcome=WIN, is_confirmed=True) game.refresh_from_db() game.recalculate_golden_ratio(True) self.assertFalse(game.achieves_golden_ratio()) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.user2.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_improvements().count(), 0) # no more ratio reward self.assertEquals(self.cell_owner.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.cell_owner.profile.get_avail_exp_rewards().count(), 1) # cell_owner gmed the game
def test_archive_game_change_attendance_confirmed(self): with transaction.atomic(): game = Game( title="title", creator=self.user2, gm=self.user2, created_date=timezone.now(), scheduled_start_time=timezone.now(), actual_start_time=timezone.now(), end_time=timezone.now(), status=GAME_STATUS[6][0], cell=self.cell, ) game.save() attendance = Game_Attendance( relevant_game=game, notes="notes", outcome=WIN, attending_character=self.char_user1_cell, ) game_invite = Game_Invite(invited_player=self.user1, relevant_game=game, as_ringer=False, ) attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 1) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 1) self.assertEquals(self.char_user1_cell.completed_games().count(), 1) self.assertEquals(self.char_user1_cell.number_of_victories(), 1) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR + EXP_WIN) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) attendance.refresh_from_db() attendance.change_outcome(new_outcome = WIN, is_confirmed = False, attending_character = self.char_user2_cell) self.assertEquals(self.char_user1_cell.is_dead(), False) self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 0) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.char_user2_cell.is_dead(), False) self.assertEquals(self.char_user2_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user2_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user2_cell.completed_games().count(), 0) self.assertEquals(self.char_user2_cell.number_of_victories(), 0) self.assertEquals(self.char_user2_cell.number_of_losses(), 0) self.assertEquals(self.char_user2_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user2_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.user2.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 1) # User 2 gmed the game attendance.refresh_from_db() attendance.change_outcome(new_outcome=WIN, is_confirmed=True, attending_character=self.char_user2_cell) self.assertEquals(self.char_user1_cell.is_dead(), False) self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 0) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.char_user2_cell.is_dead(), False) self.assertEquals(self.char_user2_cell.unspent_rewards().count(), 1) self.assertEquals(self.char_user2_cell.unspent_gifts().count(), 1) self.assertEquals(self.char_user2_cell.completed_games().count(), 1) self.assertEquals(self.char_user2_cell.number_of_victories(), 1) self.assertEquals(self.char_user2_cell.number_of_losses(), 0) self.assertEquals(self.char_user2_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user2_cell.exp_earned(), EXP_NEW_CHAR + EXP_WIN) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.user2.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 1) # User 2 gmed the game attendance.refresh_from_db() attendance.change_outcome(new_outcome = RINGER_VICTORY, is_confirmed = False) # We switched the character to one owned by user2, so now user2 gets the rewards self.assertEquals(self.char_user1_cell.is_dead(), False) self.assertEquals(self.char_user1_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user1_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user1_cell.completed_games().count(), 0) self.assertEquals(self.char_user1_cell.number_of_victories(), 0) self.assertEquals(self.char_user1_cell.number_of_losses(), 0) self.assertEquals(self.char_user1_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user1_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.char_user2_cell.is_dead(), False) self.assertEquals(self.char_user2_cell.unspent_rewards().count(), 0) self.assertEquals(self.char_user2_cell.unspent_gifts().count(), 0) self.assertEquals(self.char_user2_cell.completed_games().count(), 0) self.assertEquals(self.char_user2_cell.number_of_victories(), 0) self.assertEquals(self.char_user2_cell.number_of_losses(), 0) self.assertEquals(self.char_user2_cell.stats_snapshot.sources.count(), 0) self.assertEquals(self.char_user2_cell.exp_earned(), EXP_NEW_CHAR) self.assertEquals(self.user1.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user1.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user1.profile.get_avail_exp_rewards().count(), 0) self.assertEquals(self.user2.profile.get_avail_improvements().count(), 0) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 1) # User 2 gmed the game attendance.refresh_from_db() attendance.change_outcome(new_outcome=RINGER_VICTORY, is_confirmed=True) # We switched the character to one owned by user2, so now user2 gets the rewards self.assertEquals(self.user2.profile.get_avail_improvements().count(), 1) self.assertEquals(self.user2.profile.get_avail_charon_coins().count(), 0) self.assertEquals(self.user2.profile.get_avail_exp_rewards().count(), 2) # User 2 gmed the game
def finalize_create_ex_game_for_cell(request, cell_id, gm_user_id, players): if not request.user.is_authenticated: raise PermissionDenied("Log in, yo") cell = get_object_or_404(Cell, id=cell_id) if not cell.player_can_manage_games(request.user): raise PermissionDenied( "You do not have permission to manage Game Events for this Cell") gm = get_object_or_404(User, id=gm_user_id) player_list = [ get_object_or_404(User, id=player_id) for player_id in players.split('+') if not player_id == str(gm.id) ] GenInfoForm = make_archive_game_general_info_form(gm) ArchivalOutcomeFormSet = formset_factory(ArchivalOutcomeForm, extra=0) if request.method == 'POST': general_form = GenInfoForm(request.POST, prefix="general") outcome_formset = ArchivalOutcomeFormSet(request.POST, prefix="outcome", initial=[{ 'player_id': x.id, 'invited_player': x } for x in player_list]) if general_form.is_valid() and outcome_formset.is_valid(): form_gm = get_object_or_404(User, id=general_form.cleaned_data['gm_id']) if not cell.get_player_membership(form_gm): raise PermissionDenied( "Only players who are members of a Cell can GM games inside it." ) with transaction.atomic(): occurred_time = general_form.cleaned_data['occurred_time'] if "timezone" in general_form.cleaned_data: account = request.user.account account.timezone = general_form.cleaned_data["timezone"] account.save() occurred_time = change_time_to_current_timezone( occurred_time) #TODO: check to see if the game has the exact same time as existing game and fail. game = Game( title=general_form.cleaned_data['title'], creator=request.user, gm=form_gm, created_date=timezone.now(), scheduled_start_time=occurred_time, actual_start_time=occurred_time, end_time=occurred_time, status=GAME_STATUS[6][0], cell=cell, ) if general_form.cleaned_data['scenario']: game.scenario = general_form.cleaned_data['scenario'] game.save() for form in outcome_formset: player = get_object_or_404( User, id=form.cleaned_data['player_id']) attendance = Game_Attendance( relevant_game=game, notes=form.cleaned_data['notes'], outcome=form.cleaned_data['outcome'], ) game_invite = Game_Invite( invited_player=player, relevant_game=game, as_ringer=False, ) game_invite.save() if 'attending_character' in form.cleaned_data \ and not form.cleaned_data['attending_character'] is None: if hasattr(form.cleaned_data['attending_character'], 'cell'): attendance.attending_character = form.cleaned_data[ 'attending_character'] if not form.cleaned_data[ 'attending_character'].cell == cell: attendance.is_confirmed = False else: attendance.is_confirmed = False else: game_invite.as_ringer = True attendance.is_confirmed = False if game.creator.id == player.id: attendance.is_confirmed = True attendance.save() game_invite.attendance = attendance game_invite.save() game.give_rewards() return HttpResponseRedirect( reverse('cells:cells_view_cell', args=(cell.id, ))) else: print(general_form.errors) print(outcome_formset.errors) return None else: general_form = GenInfoForm(prefix="general") outcome_formset = ArchivalOutcomeFormSet(prefix="outcome", initial=[{ 'player_id': x.id, 'invited_player': x } for x in player_list]) context = { 'general_form': general_form, 'outcome_formset': outcome_formset, 'cell': cell, 'cell_id': cell_id, 'gm_user_id': gm_user_id, 'players': players, 'gm': gm, } return render(request, 'games/edit_archive_game.html', context)
def accept_invite(request, game_id): if not request.user.is_authenticated or request.user.is_anonymous: raise PermissionDenied("You must log in to accept this Game invite") game = get_object_or_404(Game, id=game_id) if not game.is_scheduled( ) or game.creator.id == request.user.id or game.gm.id == request.user.id: raise PermissionDenied( "This Game has already started, or you're the GM!") invite = get_object_or_none( request.user.game_invite_set.filter(relevant_game=game)) if not invite and not game.open_invitations: raise PermissionDenied( "This is awkward. . . You, uh, haven't been invited to this Game") if request.method == 'POST': if not invite: # player self-invite invite = Game_Invite(invited_player=request.user, relevant_game=game) if game.scenario in request.user.scenario_set.all(): invite.as_ringer = True form = make_accept_invite_form(invite)(request.POST) if form.is_valid(): game_attendance = invite.attendance with transaction.atomic(): invite.save() if game_attendance: game_attendance.attending_character = form.cleaned_data[ 'attending_character'] game_attendance.save() else: game_attendance = Game_Attendance( attending_character=form. cleaned_data['attending_character'], relevant_game=game, ) game_attendance.save() invite.is_declined = False invite.attendance = game_attendance invite.save() if invite.as_ringer and not form.cleaned_data[ 'attending_character']: #Reveal scenario to ringer game.scenario.played_discovery(request.user) return HttpResponseRedirect( reverse('games:games_view_game', args=(game.id, ))) else: print(form.errors) return None else: can_view_scenario = False if request.user.has_perm("view_scenario", game.scenario): can_view_scenario = True # Build a accept form. if not invite: # if game is open for self-invites, make a temp invite that we don't save so we can make a form invite = Game_Invite(invited_player=request.user, relevant_game=game) if game.scenario in request.user.scenario_set.all(): invite.as_ringer = True form = make_accept_invite_form(invite) context = { 'form': form, 'game': game, 'invite': invite, 'can_view_scenario': can_view_scenario, } return render(request, 'games/accept_invite.html', context)