def post(self, request, *args, **kwargs): form = CorpusForm() extra_context = dict() if request.method == 'POST': # try: # TODO - how to handle the robot under a user? form = CorpusForm(request.POST) if form.is_valid(): personal_user = get_account_user(request.user) if personal_user is None: raise Http404("用户不存在") #set_corpus_info(request.POST, personal_user) logger.debug('form.save personal_user') form.save(personal_user); extra_context['success'] = 'yes' return redirect(reverse('corpus_list')) # except: # info = "(corpusdef) %s || %s" % (sys.exc_info()[0], sys.exc_info()[1]) # print info # FIXME - currently I just log the exception extra_context['obj_list'] = self.get_queryset() extra_context['form'] = CorpusForm() return ExtraContextTemplateView.as_view(template_name=self.template_name, extra_context=extra_context)(request)
def uploadCorpus(request): """ Handles uploading of the corpus file. """ corpusForm = CorpusForm(request.POST, request.FILES) if corpusForm.is_valid(): newCorpus = CorpusFile( corpusFile = request.FILES['corpusFile'], fileName = request.FILES['corpusFile'].name, owner = getSessionId(request) ) newCorpus.save() else: return HttpResponse("Invalid file! Please try again!") return redirect("/")