I’m pretty new to Django and Japplet, this is my first project with them.
The Japplet takes some images from the django static folder, and permits the user to add some lines and markers.
At the end of this, when the button “save” on the JApplet is clicked, it should do some POST call to the Django server, to save the markes and lines.
Actually I’m only testing with markers, and I can’t get it done.
Here is the Model of a marker:
class Point(models.Model):
id_edificio = models.ForeignKey(Building)
RFID = models.CharField(max_length=200)
x = models.IntegerField()
y = models.IntegerField()
piano = models.IntegerField()
ingresso = models.BooleanField()
His View:
def point(request, id_edificio, RFID, x, y, piano):
point = csrf_exempt(point)
if request.method == 'POST':
get_object_or_404(Building, pk=id_edificio)
p = Point()
p.id_edificio = id_edificio
p.RFID = RFID
p.x = x
p.y= y
p.piano = piano
p.ingresso = True
p.save()
I haven’t implemented a template, because I don’t need access to this view with web browser.
Urls:
url(r'^buildings/generate/point', 'buildings.views.point'),
JApplet save method:
private void saveData(MarkerArrayList markers, PathArrayList paths) {
String response;
URL endpoint = null;
try {
endpoint = new URL("http://127.0.0.1:8000/buildings/generate/point");
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
for(Marker m: markers) {
Reader data = new StringReader("id_edificio="+id_building+"&"+m.toString());
try {
Post.postData(data, endpoint);
} catch (Exception e) {e.printStackTrace();}
}
}
Marker toString() method:
public String toString() {
return "RFID="+ RFID + "&" +
"x=" +
"y=" + y + "&" +
"piano=" + floor + "&";
}
I assume that my java method Post is correct. If you want to see it, ask me 😉
Error from Django server on POST:
[28/Sep/2012 07:21:46] "POST /buildings/generate/point HTTP/1.1" 403 2294
I don’t know wath to try know, I’m in your hands.
Tahnk you
The number of errors was totally incredible.
So this is the new View for markers, for now I will ignore csrf token:
And it works! There was also minor errors in Marker toString() method (as ‘X’ instead of ‘x’), but they were only minor errors.