Пример #1
0
def submit_new_file(request, slug):

    if request.method != 'POST':
        raise Http403
    
    pofile = get_object_or_404(POFile, slug=slug)
    
    back = reverse('commit_queue')

    team = get_object_or_404(Team, language=pofile.language.pk, project=pofile.release.project.pk)
    if not team.can_commit(request.user):
        messages.warning(request, message=_("You are not authorized to perform this action."))        
        return HttpResponseRedirect(back)

    if pofile.submits.all_pending():
        s = pofile.submits.get_pending()
        if s.locked:
            messages.warning(request, message=_("This file is being processed. It can't be modified."))
            return back
        s.enabled = False
        s.save()    

    res = {}
    res['back']=back
    res['uploadfile']=pofile
    
    form = UploadFileForm(request.POST, request.FILES)
    
    if form.is_valid():
        try:
            logger.debug(request.FILES)
            # first we add the files to the queue
            submits = filehandler.handle_uploaded_file(request.FILES['file'], pofile.release, pofile.language, request.user, form.cleaned_data['comment'], pofile)
            messages.info(request, message=_("Your file was uploaded and added to the submission queue."))
            return HttpResponseRedirect(back)
        except Exception, e:
            s.enabled = True
            s.save()    
            logger.error(e)
            res['message']=e.message.split("$$")
            return render_to_response('files/upload_failed.html',
                                      res,
                                      context_instance = RequestContext(request))
Пример #2
0
def upload(request, release, language):
    res = {}
    if request.method == "POST":
        res['back'] = reverse('list_files',
                             kwargs={ 'release': release,
                                      'language': language})
        r = get_object_or_404(Release, slug=release)
        l = get_object_or_404(Language, code=language)
        form = UploadFileForm(request.POST, request.FILES)
        res['form'] = form
        if form.is_valid():
            try:
                logger.debug(request.FILES)
                # first we add the files to the queue
                submits = filehandler.handle_uploaded_file(request.FILES['file'], r, l, request.user, form.cleaned_data['comment'])
                # then we check if it is possible to commit now
                team = Team.objects.get(project=r.project,language=l)
                if r.project.auto_commit_enabled and team.submittype == 1 and team.can_commit(request.user):
                    if do_commit(request, submits, request.user, r.project.repo_user, r.project.get_repo_pwd()):
                        return JSONResponse({'success': True})
                    return JSONResponse({'success': False})
                else:
                    messages.success(request, _("Your file was uploaded and added to the submission queue."))
                    return JSONResponse({'success': True})
            except Exception, e:
                logger.error(e)
                msg = _('<b>Please, fix the following errors and upload the file again:</b><br/>%s') % "<br/>".join(str(e).split("$$"))
                messages.warning(request, msg)
                return JSONResponse({'success': False})
#                res['message']=e.message.split("$$")
#                return render_to_response('files/upload_failed.html',
#                                          res,
#                                          context_instance = RequestContext(request))
        #res.update(get_file_list(request, None, release, language))
        messages.error(request, _('Complete the required information and try again.'))
        return JSONResponse({'success': False})