Ejemplo n.º 1
0
def add_job(request) :
    title = html.title([ _('Add job'), _('Jobs'), 'Ganymede' ])
    request.page = "job.add"

    if request.method == 'POST' :
        name = request.POST[ 'name' ]
        repo = request.POST[ 'repo' ]
        branch = request.POST[ 'branch' ]
        users = request.POST[ 'users' ]
        deploy = request.POST[ 'deploy' ]
        github = request.POST[ 'github' ]
        job_tests = json_to_tests(request.POST[ 'tests' ])
        whose = request.user.username
        job = Job(
            name=name, repo=repo,
            branch=branch, tests=job_tests,
            users=users, deploy=deploy,
            whose=whose, github=github
        )

        job.envs = json_to_envs( request.POST[ 'envs' ] )

        db.session.add(job)

        for env in job.envs :
            db.session.add( env )

        json_resp = json.dumps( { "status" : "ok" } )
        return HttpResponse(json_resp, mimetype="application/json")
    else :
        tests_data = tests.gather_tests_info()
        users_data = fetch_users_info()
        return render_to_response( 'job/add/add_job.html', {
            'title' : title,
            'tests' : tests_data,
            'users' : users_data,
            'repos' : [],
            'branches' : ['develop', 't-kz']
        }, context_instance=RequestContext(request) )
Ejemplo n.º 2
0
def update_job(request, job_id) :
    title = html.title( [ _('Update job') + " #" + str(job_id), _('Jobs'), 'Ganymede' ] )

    if request.method == 'POST' :
        job = db.session.query(Job).filter( Job.job_id == int(job_id) ).one()
        job.name = request.POST[ 'name' ]
        job.repo = request.POST[ 'repo' ]
        job.branch = request.POST[ 'branch' ]
        job.exec_time = request.POST[ 'exec_time' ] if request.POST[ 'exec_time' ] != "" else None
        job.tests = json_to_tests( request.POST[ 'tests' ] )
        job.users = request.POST[ 'users' ]
        job.deploy = request.POST[ 'deploy' ] if not request.POST[ 'deploy' ] == u'' else None
        job.github = request.POST[ 'github' ]

        for env in job.envs :
            db.session.delete( env )

        db.session.commit()

        new_envs = json_to_envs( request.POST[ 'envs' ], job.job_id )

        for env in new_envs :
            job.envs.append( env )

        try :
            db.session.commit()
            json_resp = json.dumps( { "status" : "ok" } )
        except Exception as e :
            db.session.rollback()
            json_resp = json.dumps( { "status" : "error", "content" : str(e) } )

        return HttpResponse(json_resp, mimetype="application/json")
    else :
        job_model = db.session.query( Job ).filter( Job.job_id == job_id ).one()
        job = {
            "job_id" : job_model.job_id,
            "name" : job_model.name,
            "repo" : job_model.repo,
            "branch" : job_model.branch,
            "envs" : job_model.envs,
            "exec_time" : job_model.exec_time.strftime("%H:%M") if not job_model.exec_time is None else "",
            "tests" : job_model.tests,
            "deploy" : job_model.deploy,
            "github" : job_model.github
        }

        tests_ids = []
        for x in job_model.tests :
            tests_ids.append( x.test_id )

        tests_data = tests.gather_tests_info( tests_ids )
        users_data = fetch_users_info( job_model )

        return render_to_response(
            'job/update/update_job.html', {
            'title' : title,
            'job' : job,
            'users' : users_data,
            'tests' : tests_data,
            'repos' : [],
            'branches' : ['develop', 't-kz']
        }, context_instance=RequestContext(request) )