def changephoto(request): saved = None if request.method == "POST": form = ChangePhotoForm(request.POST, files=request.FILES) if form.is_valid() and form.is_bound == True: photo = form.cleaned_data["photo"] try: info_about_player = request.user.get_profile() except player.DoesNotExist: info_about_player = player(user=request.user) about_me = info_about_player.about_me city = info_about_player.city countryPart = info_about_player.countryPart date_of_birth = info_about_player.date_of_birth gender = info_about_player.gender phone = info_about_player.phone rank = info_about_player.rank street = info_about_player.street info_about_player.delete() new_player = player( user=request.user, gender=gender, date_of_birth=date_of_birth, countryPart=countryPart, city=city, street=street, phone=phone, about_me=about_me, photo=photo, rank=rank, ) new_player.save() return render_to_response( "players/changephoto.html", {"form": form, "saved": True, "changePass": True, "changephoto": True}, context_instance=RequestContext(request), ) else: return render_to_response( "players/changephoto.html", {"form": form, "fail": True, "changePass": True, "changephoto": True}, context_instance=RequestContext(request), ) else: form = ChangePhotoForm({}) return render_to_response( "players/changephoto.html", {"form": form, "changePass": True, "changephoto": True}, context_instance=RequestContext(request), )
def post(self): form = forms.NewGameForm(self.request.POST) form.color1.choices = [(key, key) for key in _primaryColors.keys()] form.color2.choices = [(key, key) for key in _bonusColors.keys()] if form.validate(): #player p = models.player() p.isAdmin = True p.score = 0 p.primaryColor = form.color1.data p.bonusColor = form.color2.data p.put() #game g = models.game() g.name = form.name.data g.password = security.generate_password_hash(form.password.data) g.primaryColorsChosen.append(form.color1.data) g.bonusColorsChosen.append(form.color2.data) g.players.append(p.key) g.put() #user self.user.players.append(p.key) self.user.put() self.redirect(self.uri_for('game', game_id=g.key.id())) context = {'form': form} self.render_response('NewGame.html', **context)
def get_current_user(self): user_id = self.get_secure_cookie('user') if user_id: self.current_user = models.player(user_id) return self.current_user self.clear_cookie('user') return None
def get_current_user(self): user_id = self.get_secure_cookie('user') if user_id: user_id = user_id.decode('utf-8') self.current_user = models.player(user_id) return self.current_user self.clear_cookie('user') return None
def tester(): engie = engine() rootfn = "..\\content\\" engie.populateItems(rootfn+"items.html") engie.populateActors(rootfn+"characters.html") engie.populateRooms(rootfn+"rooms.html") player = models.player(location=engie.allRooms['0']) return player
def get(self, player_id): self.render("player_stats.html", player=models.player(player_id), stats=self.db.player_stats(player_id), # For template all_players=models.players(), course_name_dict=self.db.course_name_dict(), active_games=models.games({'active':True}), user=self.get_current_user(), )
def client_enterance(self): client, adress = self.network.accept() player_id = False received = self.network.receive(client) player_name = received["data"] player_id = self.lastid + 1 self.lastid += 1 self.players[player_id] = [player(player_name), client] print(received["data"]+"katıldı") self.start_game()
def get(self, player_id): self.render( "player_stats.html", player=models.player(player_id), stats=self.db.player_stats(player_id), # For template all_players=models.players(), course_name_dict=self.db.course_name_dict(), active_games=models.games({'active': True}), user=self.get_current_user(), )
def aboutMe(request): try: info_about_player = request.user.get_profile() except player.DoesNotExist: info_about_player = player(user=request.user) age = calculate_age(info_about_player.date_of_birth) return render_to_response( "players/aboutMe.html", {"info_about_player": info_about_player, "age": age}, context_instance=RequestContext(request), )
def get(self, player_id): player = models.player(player_id) self.render("new_player.html", tittle="Pelaajan tiedot", player=player, message="", # For template all_players=models.players(), course_name_dict=self.db.course_name_dict(), active_games=models.games({'active':True}), user=self.get_current_user(), )
def get(self, player_id): player = models.player(player_id) self.render( "new_player.html", tittle="Pelaajan tiedot", player=player, message="", # For template all_players=models.players(), course_name_dict=self.db.course_name_dict(), active_games=models.games({'active': True}), user=self.get_current_user(), )
def post(self): form = forms.JoinGameForm(self.request.POST) try: game_id = int(form.game.data) game = models.game.get_by_id(game_id) except: game = None auth_error = None if game: form.game.value = form.game.data form.color1.choices = [(key, key) for key in _primaryColors.keys() if key not in game.primaryColorsChosen] form.color2.choices = [(key, key) for key in _bonusColors.keys() if key not in game.bonusColorsChosen] # to do: validate game exists # to do: validate colors are valid (i.e., not chosen allready) # to do: validate password? # to do: validate user cannot join game twice if form.validate: if security.check_password_hash(form.password.data, game.password): #player p = models.player() p.isAdmin = False p.score = 0 p.primaryColor = form.color1.data p.bonusColor = form.color2.data p.put() #user self.user.players.append(p.key) self.user.put() #game game.players.append(p.key) game.primaryColorsChosen.append(form.color1.data) game.bonusColorsChosen.append(form.color2.data) game.put() self.redirect(self.uri_for('game', game_id=game.key.id())) else: auth_error = "Invalid game password" context = { 'game': game, 'form': form, 'auth_error': auth_error } self.render_response('joingame.html', **context)
def profile(request): try: profile = request.user.get_profile() except player.DoesNotExist: profile = player(user=request.user) saved = None if request.method == "POST": form = PlayerForm(request.POST) if form.is_valid(): request.user.first_name = form.cleaned_data["first_name"] request.user.last_name = form.cleaned_data["last_name"] request.user.email = form.cleaned_data["email"] profile.gender = form.cleaned_data["gender"] profile.date_of_birth = form.cleaned_data["date_of_birth"] profile.countryPart = form.cleaned_data["countryPart"] profile.city = form.cleaned_data["city"] profile.street = form.cleaned_data["street"] profile.email = form.cleaned_data["email"] profile.phone = form.cleaned_data["phone"] profile.about_me = form.cleaned_data["about_me"] request.user.save() profile.save() saved = True return render_to_response( "players/profile.html", {"form": form, "saved": saved}, context_instance=RequestContext(request) ) else: return render_to_response( "players/profile.html", {"form": form, "fail": True}, context_instance=RequestContext(request) ) else: form = PlayerForm( initial={ "username": request.user.username, "first_name": request.user.first_name, "last_name": request.user.last_name, "city": profile.city, "street": profile.street, "email": request.user.email, "phone": profile.phone, "gender": profile.gender, "date_of_birth": profile.date_of_birth, "about_me": profile.about_me, "countryPart": profile.countryPart, } ) return render_to_response("players/profile.html", {"form": form}, context_instance=RequestContext(request))
def registration(request): emailPattern = "^([\\w\\-\\.]+)@((\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|(([\\w\\-]+\\.)+)([a-zA-Z]{2,4}))$" phoneNumberPattern = "^([+]|[0-9])?[/|[0-9]| ]+$" saved = None if request.method == "POST": form = RegistrationForm(data=request.POST, files=request.FILES) if form.is_valid() and form.is_bound == True: username = form.cleaned_data["username"] password1 = form.cleaned_data["password1"] email = form.cleaned_data["email"] new_user = User.objects.create_user(username, email, password1) new_user.first_name = form.cleaned_data["first_name"] new_user.last_name = form.cleaned_data["last_name"] gender = form.cleaned_data["gender"] date_of_birth = form.cleaned_data["date_of_birth"] countryPart = form.cleaned_data["countryPart"] city = form.cleaned_data["city"] street = form.cleaned_data["street"] phone = form.cleaned_data["phone"] about_me = form.cleaned_data["about_me"] photo = form.cleaned_data["photo"] new_user.save() new_player = player( user=new_user, gender=gender, date_of_birth=date_of_birth, countryPart=countryPart, city=city, street=street, phone=phone, about_me=about_me, photo=photo, rank=0, ) new_player.save() saved = True return render_to_response( "players/registration.html", {"form": form, "saved": saved, "reg": True}, context_instance=RequestContext(request), ) else: return render_to_response( "players/registration.html", {"form": form, "fail": True, "reg": True}, context_instance=RequestContext(request), ) else: form = RegistrationForm({}) return render_to_response( "players/registration.html", {"form": form, "reg": True}, context_instance=RequestContext(request) )
def __init__(self): self.protagonist = models.player() self.allActors={} self.allRooms={} self.allItems={}