Пример #1
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})
Пример #2
0
def confirm_submit(request):    

    if request.method != 'POST':
        raise Http403

    if request.POST.has_key('reject') and request.POST.get('reject')=='True':
        reject = True;
    else:
        reject = False
    if request.POST.has_key('needuser') and request.POST.get('needuser')=='False':
        needuser = False;
    else:
        needuser = True

    if reject:
        form = RejectSubmitForm(request.POST)
    else:
        if needuser: 
            form = HttpCredForm(request.POST)
        else:
            form = CommentForm(request.POST)

    fileSet = get_object_or_404(POFileSubmitSet, pk=request.POST.get('file'))        
    if not form.is_valid():
#         files = []
#         for fid in request.POST.getlist('file'):
#             try:
#                 sfile = POFileSubmit.objects.get(pk=fid)
#                 files.append(sfile)
#             except:
#                 pass            
        messages.warning(request, message=_("Complete the form and try again."))
        return render_to_response("files/file_submit_confirm.html",
                                   {'files': fileSet,
                                    'back': request.POST['back'],
                                    'form': form,
                                    'reject': reject},
                                   context_instance = RequestContext(request))

    files = []
    for submfile in fileSet.files.all():
        if reject:
            send_pm(submfile.owner, _("Submit rejected"), message=_("The file %(file)s (%(project)s) was rejected by %(user)s [%(comment)s]") % 
                                    {'file': submfile.pofile.filename,
                                     'user': request.user.username,
                                     'project': submfile.pofile.release.project.name,
                                     'comment': form.cleaned_data.get('message')},)
            POFileLog.objects.create(pofile=submfile.pofile,
                                     user=request.user, action='X',
                                     comment=form.cleaned_data.get('message'))
            submfile.status = SUBMIT_STATUS_ENUM.REJECTED
            submfile.save()
        else:
            files.append(submfile)
    
#     for fid in request.POST.getlist('file'):
#         try:
#             submfile = POFileSubmit.objects.get(pk=fid)
#             if reject:
#                 send_pm(submfile.owner, _("Submit rejected"), message=_("The file %(file)s (%(project)s) was rejected by %(user)s [%(comment)s]") % 
#                                         {'file': submfile.pofile.filename,
#                                          'user': request.user.username,
#                                          'project': submfile.pofile.release.project.name,
#                                          'comment': form.cleaned_data.get('message')},)
#                 POFileLog.objects.create(pofile=submfile.pofile,
#                                          user=request.user, action='X',
#                                          comment=form.cleaned_data.get('message'))
#                 submfile.status = SUBMIT_STATUS_ENUM.REJECTED
#                 submfile.save()
#             else:
#                 files.append(submfile)
#         except:
#             pass

    if reject:
        messages.info(request, message=_("The files were rejected."))
                
    if len(files)>0:
        if needuser:
            puser = form.cleaned_data.get('user')
            ppass = form.cleaned_data.get('password')
        else:
            p = get_object_or_404(Project,pk=request.POST.get('p'))
            puser = p.repo_user
            ppass = p.get_repo_pwd()
            
        do_commit(request, files,
                 request.user,
                 puser,
                 ppass,
                 form.cleaned_data.get('message'))

    fileSet.delete()
    
    return HttpResponseRedirect(request.POST['back'])