- repo.in_branch(save_action, models.user_branch(request.user) )
-
- result = "ok"
- else:
- result = "error"
-
- errors = dict( (field[0], field[1].as_text()) for field in form.errors.iteritems() )
- return HttpResponse( json.dumps({'result': result, 'errors': errors}) );
+ # wczytaj dokument z repozytorium
+ document = parser.WLDocument.from_string(file_contents)
+ document.book_info.update(form.cleaned_data)
+
+ print "SAVING DC"
+
+ # zapisz
+ repo._add_file(path, document.serialize())
+ repo._commit( \
+ message=(form.cleaned_data['commit_message'] or 'Lokalny zapis platformy.'), \
+ user=request.user.username )
+
+ try:
+ repo.in_branch(save_action, models.user_branch(request.user) )
+ except (ParseError, ValidationError), e:
+ errors = [e.message]
+
+ if errors is None:
+ errors = ["Pole '%s': %s\n" % (field[0], field[1].as_text()) for field in form.errors.iteritems()]
+
+ return HttpResponse( json.dumps({'result': errors and 'error' or 'ok', 'errors': errors}) );