- if form.is_valid():
- def save_action():
- file_contents = repo._get_file(path)
-
- # wczytaj dokument z repozytorium
- document = parser.WLDocument.from_string(file_contents)
-
- rdf_ns = dcparser.BookInfo.RDF
- dc_ns = dcparser.BookInfo.DC
-
- rdf_attrs = {rdf_ns('about'): form.cleaned_data.pop('about')}
- field_dict = {}
-
- for key, value in form.cleaned_data.items():
- field_dict[ dc_ns(key) ] = value if isinstance(value, list) else [value]
-
- print field_dict
-
- new_info = dcparser.BookInfo(rdf_attrs, field_dict)
- document.book_info = new_info
-
- 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 = dict( (field[0], field[1].as_text()) for field in form.errors.iteritems() )
-
- return HttpResponse( json.dumps({'result': errors and 'error' or 'ok', 'errors': errors}) );
-
- fulltext = repo.get_file(path, models.user_branch(request.user))
- form = forms.DublinCoreForm(text=fulltext)
- return HttpResponse( json.dumps({'result': 'ok', 'content': fulltext}) )
-
-# Display the main editor view
+ if response.status_code == 201:
+ return HttpResponseRedirect( \
+ reverse("editor_view", args=[ data['name'] ]) )
+ else:
+ bookform = DocumentUploadForm(request.POST, request.FILES)
+ bookform.is_valid()
+
+ return direct_to_template(request, 'explorer/file_upload.html',
+ extra_context={'bookform': bookform } )
+