Example #1
0
def stop(request, *args, **kwargs):
    if not request.session.get('is_login', False) or request.session['user_type'] != 'accounts':
        return redirect("/index")
    error_msg = ''
    project_id = utils.get_id(args)
    page = utils.get_page(args)
    if request.method == "GET":
        for id, item in utils.get_projects(request.session['account']):
            if id == project_id:
                project_info = item
        return render(request, "user_projectstop.html", {"project_info":project_info, "project_id":project_id, "page":page , "error_msg": error_msg})
    if request.method == "POST":
        data = {
            "name": request.POST.get("name"),
            "leader": request.POST.get("leader"),
            "teammates": request.POST.get("teammates"),
            "start": request.POST.get("start"),
            "cost": request.POST.get("cost"),
        }
        if int(data['cost']) < 0:
            data['cost'] = '0'
        if not error_msg:
            error_msg = "项目申停成功"
            _projects_dict = utils.get_projects(request.session['account'])
            page_list = utils.get_pages(page, _projects_dict)
            projects_dict, page, project_id = utils.adjust_info(_projects_dict, page, project_id)
            steps = utils.get_steps(project_id)
            step_path = utils.steps_path(utils.get_eva_info(project_id, top=True))
            return render(request, "user_projectprocess.html",
                          {"projects_dict": projects_dict, "project_id": project_id,
                           "steps": steps, "step_path": step_path, "page_list": page_list, "page": page,
                           'error_msg': error_msg})
Example #2
0
def initialize(args, request, is_pass=False):
    error_msg = ''
    project_id = utils.get_id(args)
    page = utils.get_page(args)  # 获取当前页面
    _projects_dict = utils.get_projects(request.session['account'], is_pass)
    page_list = utils.get_pages(page, _projects_dict)
    projects_dict, page, project_id = utils.adjust_info(_projects_dict, page, project_id)
    return error_msg, page, page_list, projects_dict, project_id
Example #3
0
def test_get_projects(temp_app, temp_db):
    '''Tests getting all projects by an authenticated user'''
    login_res = login_hello(temp_app)
    auth_token = login_res['accessToken']
    res = get_projects(auth_token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 200
    assert res_data['message'] == 'Success'
    assert isinstance(res_data['projects'], list)
Example #4
0
def test_get_projects_none(temp_app, temp_db):
    '''Tests getting all projects by a user with no projects'''
    login_res = login_mackland(temp_app)
    auth_token = login_res['accessToken']
    res = get_projects(auth_token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 200
    assert res_data['message'] == 'Success'
    assert isinstance(res_data['projects'], list)
    assert not res_data['projects'], '"projects" should be an empty list here'
Example #5
0
def compute(shift):
    before_after = pandas.DataFrame()
    
    for key in list(itertools.product(utils.get_projects(), utils.get_class_models(), utils.get_experiments(), ['ideal'], utils.get_smote(), utils.get_approaches(), utils.get_classifiers())):
        data = utils.get_item(key, 'data')

        before_after_local = compute_before_after_series(data, shift)
        before_after_local['project'] = key[0]
        before_after_local['approach'] = key[5]

        before_after = before_after.append(before_after_local, sort=False)

    utils.boxplot_approaches(before_after, 'before_after_fix_' + str(shift), 'difference', '', True, [-1, 1])
def index(request):
	if request.user.is_anonymous() or not request.user.is_user:
		return shortcuts.redirect('/horizon/auth/login/')

	instances = utils.get_instances(request)
	user = utils.get_user(request)
	projects = utils.get_projects(request,user)

	for instance in instances:
		instance['console_url'] = utils.get_console_url(request,instance)

	limit = utils.get_project_limit(request)

	return shortcuts.render_to_response('index.html',{"user":user,"instances":instances,"projects":projects,"tenant_name":request.user.tenant_name,'limit':limit})
Example #7
0
def test_get_projects_fail(temp_app, temp_db):
    '''Tests getting projects with various failure cases'''

    # Tests trying to get projects with no auth header
    res = temp_app.get('/projects')
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'No authentication provided'

    # Tests trying to get projects with no auth header
    res = temp_app.get('/projects', headers=dict(Authorization='Bearer '))
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'No authentication provided'

    # Tests trying to get projects with an expired token
    token = generate_expired_token('access',
                                   temp_app.application.config['SECRET_KEY'])
    res = get_projects(token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'Invalid token'

    # Tests trying to get projects with a token signed with the wrong key
    token = generate_invalid_token('access')
    res = get_projects(token, temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'Invalid token'

    # Tests trying to use a refresh token to access projects
    token = encode_auth_token('refresh', 1, datetime.timedelta(days=3),
                              temp_app.application.config['SECRET_KEY'])
    res = get_projects(token.decode(), temp_app)
    res_data = json.loads(res.data)
    assert res.status_code == 401
    assert res_data['error'] == 'Invalid token type'
def log(request,instance_id):
	if request.user.is_anonymous() or not request.user.is_user:
		return shortcuts.redirect('/horizon/auth/login/')

	instances = utils.get_instances(request,overview=True)
	user = utils.get_user(request)
	projects = utils.get_projects(request,user)
	for instance in instances:
		if getattr(instance,'id','') == instance_id:
			ins = instance

	try:
		console_log = utils.get_log_data(request,instance_id)
	except Exception:
		console_log = "Unable to get log data!"

	console_url = utils.get_console_url(request,ins)
	
	return shortcuts.render_to_response('log.html',{"user":user,"instances":instances,"projects":projects,"tenant_name":request.user.tenant_name,"current_instance":ins,"console_log":console_log})
Example #9
0
def summary(request, *args, **kwargs):
    if not request.session.get('is_login', False) or request.session['user_type'] != 'accounts':
        return redirect("/index")
    error_msg = ''
    page = utils.get_page(args)  # 获取当前页面
    _projects_dict = utils.get_projects(request.session['account'])
    page_list = utils.get_pages(page, _projects_dict)
    projects_dict, page, project_id = utils.adjust_info(_projects_dict, page, 1)
    if request.method == 'GET':
        return render(request, 'user_projectsum.html',
                      {'projects_dict':projects_dict, "page_list":page_list, "page":page})
    if request.method == "POST":
        if request.POST.get("edit"):
            project_id = int(request.POST.get("edit"))
            for key, data in projects_dict:
                if key == project_id:
                    project_data = data
            return render(request, 'user_edit.html', {"project_id": project_id,
                "project_data":project_data, "error_msg":error_msg, "page":page,
            })
Example #10
0
def user_edit(request, *args, **kwargs):
    if not request.session.get('is_login', False) or request.session['user_type'] != 'accounts':
        return redirect("/index")
    error_msg = ''
    page = utils.get_page(args)  # 获取当前页面
    _projects_dict = utils.get_projects(request.session['account'])
    page_list = utils.get_pages(page, _projects_dict)
    projects_dict, page, project_id = utils.adjust_info(_projects_dict, page, 1)
    if request.method == 'POST':
        project_id = int(request.POST.get("project_id"))
        for key, data in projects_dict:
            if key == project_id:
                project_data = data
        data = {
            "name": request.POST.get("name").strip(),
            "leader": request.POST.get("leader").strip(),
            "teammates": request.POST.get("teammates").strip().split(',') if request.POST.get("teammates") else None
        }
        data, error_msg = utils.check_error(data, budget=False)
        if error_msg:
            return render(request, 'user_edit.html', {
                "project_id": project_id,
                "project_data": project_data, "error_msg": error_msg, "page": page,
            })
        else:
            if request.FILES.get('file'):
                utils.save_file(id, request, save_name="applyingFile", new=True)
            project_data['name'] = data['name']
            project_data['leader'] = data['leader']
            project_data['teammates'] = data['teammates']
            with open("database/projects.pk", 'rb') as f:
                _projects_dict = pickle.load(f)
            _projects_dict[project_id] = project_data
            with open("database/projects.pk", 'wb') as f:
                f.write(pickle.dumps(_projects_dict))
            return redirect("/account/summary&page=%d" % page)