Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Dex
Raphael,

Exactly what you said. I'm trying to build a "Battleship" game app with 
Django, and I want to be able save the game state in the db so I can 
revisit it later if I quit the game before it is finished. 

Thanks for the links provided. I'm new to Django and still fairly new to 
programming overall, so I don't really know a lot about array handling with 
Django's ORM. Currently, I'm considering using a custom field to handle my 
array but I'm not really sure on this approach yet. I'll certainly let you 
know when I finish this project :)

On Saturday, January 19, 2013 10:57:53 AM UTC-5, Raphael wrote:
>
>  @ Dex,
>
> So you want to store the actual game state in the db to recover 
> game-session-data after a period of time
> and/or to perform game logic on the server side.
>
> well I am sure you already know it, but there are approaches to handle 
> array fields within the django ORM. 
> example: http://www.djangopackages.com/grids/g/arrayfield/landscape/
> or: https://github.com/ecometrica/django-dbarray
>
> but I have never tried one of them. 
> could be of interest one day!
>
> I am interested in your final solution. Maybe you can send me an email 
> once you decided a way to go.
>
> thx
>
>   -- 
>
> Raphaelhttp://develissimo.com
>
>
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/SZZTyELbYbMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Dex
@Raphael

Exactly what you said. I'm trying to build a "Battleship" game app with 
Django, and I want to be able save the game state in the db so I can 
revisit it later if I quit the game before it is finished. 

Thanks for the links provided. I'm new to Django and still fairly new to 
programming overall, so I don't really know a lot about array handling with 
Django's ORM. 

On Saturday, January 19, 2013 10:57:53 AM UTC-5, Raphael wrote:
>
>  @ Dex,
>
> So you want to store the actual game state in the db to recover 
> game-session-data after a period of time
> and/or to perform game logic on the server side. Currently, I'm  thinking 
> of maybe trying to go with a custom field to store arrays, but I'm not 
> quite sure yet. I'll certainly let you know when I finish this project :)
>
> well I am sure you already know it, but there are approaches to handle 
> array fields within the django ORM. 
> example: http://www.djangopackages.com/grids/g/arrayfield/landscape/
> or: https://github.com/ecometrica/django-dbarray
>
> but I have never tried one of them. 
> could be of interest one day!
>
> I am interested in your final solution. Maybe you can send me an email 
> once you decided a way to go.
>
> thx
>
>   -- 
>
> Raphaelhttp://develissimo.com
>
>
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/crnIQ6B7g68J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Raphael
@ Dex,

So you want to store the actual game state in the db to recover
game-session-data after a period of time
and/or to perform game logic on the server side.

well I am sure you already know it, but there are approaches to handle
array fields within the django ORM. 
example: http://www.djangopackages.com/grids/g/arrayfield/landscape/
or: https://github.com/ecometrica/django-dbarray

but I have never tried one of them. 
could be of interest one day!

I am interested in your final solution. Maybe you can send me an email
once you decided a way to go.

thx

-- 

Raphael
http://develissimo.com



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Dex
Raphael,

Seems like the problem might be in my models. My view code that tries to 
access the model is: 
@csrf_exempt
def target_spot(request, game_id, spot):
game = fetch_game(request.user, game_id)
game.creator_target_board[int(spot)] = "X"
return HttpResponse('/')

game.creator_target_board[int(spot)] = "X" tries to change a unicode 
object. creator_target_board is an attribute of my game object. In my 
model, creator_target_board = models.CharField(max_length=100, default=" " 
* 100). I was trying to replicate an array but since I couldn't figure out 
what type of field to use for an array I decided to use a CharField with a 
default value of " " * 100. The "spot" variable in my javascript is 
supposed to point to the position of creator_target_board to be modified.

On Saturday, January 19, 2013 10:16:54 AM UTC-5, Raphael wrote:
>
>  Hello Dex,
>
> forget my story about Chrome/Chromium issue if you have been testing with 
> FF.
> This was a first shot into the dark. sorry.
>
> Concerning your error message:
> 'unicode' object does not support item assignment
>
> This error pops up when you try to alter immutable string objects.
>
> Please check your code if you do so and tell us.
> +add traceback and view code.
>
> Thank you
>   -- 
>
> Raphaelhttp://develissimo.com
>
>
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/sBlVfmp9e6wJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Raphael

game.creator_target_board[int(spot)] = "X"


Exception Type: TypeError at /target_spot/1/0/
Exception Value: 'unicode' object does not support item assignment

So your trouble is that game.creator_target_board[int(spot)] is an immutable 
str object.
so you have to rethink your strategy.

create new str object or handle it completely different.


-- 

Raphael
http://develissimo.com



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Raphael
Hello Dex,

forget my story about Chrome/Chromium issue if you have been testing
with FF.
This was a first shot into the dark. sorry.

Concerning your error message:
'unicode' object does not support item assignment

This error pops up when you try to alter immutable string objects.

Please check your code if you do so and tell us.
+add traceback and view code.

Thank you
-- 

Raphael
http://develissimo.com



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Dex
I typed typed the url of my ajax POST and I get the message "unicode object 
does not support item assignment". Here is the traceback link: 
http://dpaste.com/882866/

On Saturday, January 19, 2013 8:05:06 AM UTC-5, ke1g wrote:
>
> What happens if you type the url in directly in the browser's location bar 
> (you will
> have to disable the request.is_ajax() test temporarily)?  If the server is 
> in debug
> mode, you should get a stack trace that is more informative.
>
> Also, assuming that you've shown us all of the view code, you may need to
> return something other than None (which is what gets returned if you don't
> use the return statement).  (But I'm not sure of that.  I've always had 
> something
> to return.)
>
> Bill
>
> On Sat, Jan 19, 2013 at 5:35 AM, Raphael 
> 
> > wrote:
>
>> ** 
>> hello Dex,
>>
>> you did not tell us what browser you are testing your AJAX request on.
>> Maybe you experience this Chrome behavior:
>> http://develissimo.com/blog/2013/ajax-not-working-chrome-ie8/
>>
>> Good luck
>> >Raphael
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/GNSWQH0qhvAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Bill Freeman
What happens if you type the url in directly in the browser's location bar
(you will
have to disable the request.is_ajax() test temporarily)?  If the server is
in debug
mode, you should get a stack trace that is more informative.

Also, assuming that you've shown us all of the view code, you may need to
return something other than None (which is what gets returned if you don't
use the return statement).  (But I'm not sure of that.  I've always had
something
to return.)

Bill

On Sat, Jan 19, 2013 at 5:35 AM, Raphael wrote:

> **
> hello Dex,
>
> you did not tell us what browser you are testing your AJAX request on.
> Maybe you experience this Chrome behavior:
> http://develissimo.com/blog/2013/ajax-not-working-chrome-ie8/
>
> Good luck
> >Raphael
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Raphael
hello Dex,

you did not tell us what browser you are testing your AJAX request on.
Maybe you experience this Chrome behavior:
http://develissimo.com/blog/2013/ajax-not-working-chrome-ie8/

Good luck
>Raphael

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-19 Thread Iñigo Medina

On Fri, Jan 18, 2013 at 12:50:26PM -0800, Dex wrote:
> From my server log, i get the following message when I click on a cell: 
> "POST /target_spot/1/0/ HTTP/1.1" 500. Any ideas on how to solve this? 
> Thanks!

Don't you have debug enabled? It should give you a more complete track of the
error.

Iñigo

> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/Aux0I4-eUNMJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Getting error 500 when using jquery/ajax

2013-01-18 Thread Mario Gudelj
Replicate this error in chrome, then go to network tab in dev tools, look
at the request that gets 500 and check the response. You should be able to
see the stack trace if debug is on.
On 19 Jan, 2013 8:01 AM, "Dex"  wrote:

> Hi, I'm new to Django. I'm creating a game that has a 10x10 board and when
> a cell is clicked upon, it will be marked with an "X". Marking the cells
> works in jquery but I want to send data to server side to let it know that
> the cell is marked. That way when I quit the  game and come back later, it
> will have an "X" on that cell. Currenly, my jquery code is this:
> $('.target_cell').click(function(){
> if ($(this).text() != "X" && $(this).text() != "H"){
> $(this).text("X");
> var spot = $(this).attr('name'); //Cell index number like
> in an array but in string format
> $.ajax({
> type: "POST",
> url: "/target_spot/{{game.id}}/" + spot + "/",
> data: spot
> });
> }
>
> And my view code is this:
> @csrf_exempt
> def target_spot(request, game_id, spot):
> if request.is_ajax():
> game = fetch_game(request.user, game_id)
> game.creator_target_board[int(spot)] = "X"
> game.save()
>
> From my server log, i get the following message when I click on a cell:
> "POST /target_spot/1/0/ HTTP/1.1" 500. Any ideas on how to solve this?
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/Aux0I4-eUNMJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Getting error 500 when using jquery/ajax

2013-01-18 Thread Dex
Hi, I'm new to Django. I'm creating a game that has a 10x10 board and when 
a cell is clicked upon, it will be marked with an "X". Marking the cells 
works in jquery but I want to send data to server side to let it know that 
the cell is marked. That way when I quit the  game and come back later, it 
will have an "X" on that cell. Currenly, my jquery code is this:
$('.target_cell').click(function(){ 
if ($(this).text() != "X" && $(this).text() != "H"){
$(this).text("X");
var spot = $(this).attr('name'); //Cell index number like 
in an array but in string format
$.ajax({
type: "POST",
url: "/target_spot/{{game.id}}/" + spot + "/",
data: spot
});
}

And my view code is this: 
@csrf_exempt
def target_spot(request, game_id, spot):
if request.is_ajax():
game = fetch_game(request.user, game_id)
game.creator_target_board[int(spot)] = "X"
game.save()

>From my server log, i get the following message when I click on a cell: 
"POST /target_spot/1/0/ HTTP/1.1" 500. Any ideas on how to solve this? 
Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Aux0I4-eUNMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.