Beispiel #1
0
    def test_create(self):
        expected_detail = {'name':u"Testia", 'size_x': 9, 'size_y': 9, 'description' : u"A test world"}

        form = WorldForm(expected_detail, {})
        if form.is_valid():
            object = form.save()

        expected_detail['id'] = object.id
        expected_detail['status'] = 'new'
        world = World.objects.get(id=object.id)
        detail = world.getDetail()
        self.failUnlessEqual(detail, expected_detail)
Beispiel #2
0
def create(request):
    if request.method == 'POST':
        form = WorldForm(request.POST, request.FILES)
        if form.is_valid():
            object = form.save()
            context = object.getDetail()
        else:
            errors = form.errors
            context = {'errors': form.errors}
    else:
        form = WorldForm()
        context = form.as_json()

    response = simplejson.dumps(context)

    return HttpResponse(response)