def profile(request): characters = Character.objects.filter(player=request.user) new_character_form = NewCharacterForm() error_message = '' if request.method =='POST': char_form = NewCharacterForm(request.POST) if char_form.is_valid(): name = char_form.cleaned_data['name'] server = char_form.cleaned_data['server'] try: character = Character(name=name, server=server, player=request.user, level=0, ilvl=0, last_refresh = datetime.datetime.now(), last_refresh_request = datetime.datetime.now()) update_character(character) except Exception as e: error_message = "This character does not exist on this server." else: new_character_form = char_form return render_to_response('demo/profile.html', {'error_message': error_message, 'characters':characters, 'new_character_form':new_character_form}, context_instance=RequestContext(request))
def profile(request): characters = Character.objects.filter(player=request.user) new_character_form = NewCharacterForm() error_message = '' if request.method =='POST': char_form = NewCharacterForm(request.POST) if char_form.is_valid(): name = char_form.cleaned_data['name'] server = char_form.cleaned_data['server'] try: c = battlenet.Character(battlenet.UNITED_STATES, server, name) character = Character(name=name, server=server, player=request.user, level=0, ilvl=0) character.save() update_character(character) except Exception as e: error_message = "This character does not exist on this server." else: new_character_form = char_form return render_to_response('demo/profile.html', {'error_message': error_message, 'characters':characters, 'new_character_form':new_character_form}, context_instance=RequestContext(request))
def register_view(request): if request.method == 'POST': new_user_form = NewUserForm(request.POST) if new_user_form.is_valid(): # make this actually secure later if request.POST['secret_word'] != 'do not eat': error_message = "Please ask an officer in the guild for the secret word" return register_failed(request, error_message) username = request.POST['username'] for u in User.objects.all() : if username == u.username: error_message = "Username is taken." return register_failed(request, error_message) password = make_password(request.POST['password']) email = request.POST['email'] character = request.POST['character'] server = request.POST['server'] try: c = battlenet.Character(battlenet.UNITED_STATES, server, character) except Exception as e: error_message = "This character does not exist on this server." return register_failed(request, error_message) user = User(username=username, password=password, email=email) user.save() login_user = authenticate(username=username, password=request.POST['password']) login(request, login_user) character = Character(name=character, server=server, player=user, class_name='', level=0, ilvl=0) character.save() update_character(character) player = Player(user=user, main=character) player.save() return redirect('home') else: error_message = "There was a problem with your application." return register_failed(request, error_message) else: return redirect('home')
def execute(self): # executing empty sample job print "Updating character info now." for char in Character.objects.all(): update_character(char)