Esempio n. 1
0
def update_worksheetstate():
	user_id = session["user_data"]["user_id"]
	action_type = request.form.get('action_type')
	reject_reason = request.form.get('reject_reason') or None
	worksheet_id = request.form.get('worksheet_id')
	result = {'status': 1001, 'message': '请求失败'}
	try:
		user_data = User.objects.filter(id=user_id)[0]
	except:
		user_data = None
	try:
		worksheet_data = Worksheet.objects.filter(id=worksheet_id)[0]
	except:
		worksheet_data = None
	ISOTIMEFORMAT='%Y-%m-%d %X'
	now_time = time.strftime( ISOTIMEFORMAT, time.localtime( time.time() ) )
	if user_data and worksheet_data:
		if action_type == u"运维认领":
			worksheet_data.operator_id = user_id
			worksheet_data.save()
		if action_type == u"运维执行成功":
			worksheet_data.updated_at = now_time
			worksheet_data.save()
		if state_transfer(user_data, action_type, worksheet_data, reject_reason):
			result = {'status': 200, 'message': '请求成功'}
	return json.dumps(result)
Esempio n. 2
0
def update_worksheetstate():
    user_id = session["user_data"]["user_id"]
    action_type = request.form.get('action_type')
    reject_reason = request.form.get('reject_reason') or None
    worksheet_id = request.form.get('worksheet_id')
    result = {'status': 1001, 'message': '请求失败'}
    try:
        user_data = User.objects.filter(id=user_id)[0]
    except:
        user_data = None
    try:
        worksheet_data = Worksheet.objects.filter(id=worksheet_id)[0]
    except:
        worksheet_data = None
    ISOTIMEFORMAT = '%Y-%m-%d %X'
    now_time = time.strftime(ISOTIMEFORMAT, time.localtime(time.time()))
    if user_data and worksheet_data:
        if action_type == u"运维认领":
            worksheet_data.operator_id = user_id
            worksheet_data.save()
        if action_type == u"运维执行成功":
            worksheet_data.updated_at = now_time
            worksheet_data.save()
        if state_transfer(user_data, action_type, worksheet_data,
                          reject_reason):
            result = {'status': 200, 'message': '请求成功'}
    return json.dumps(result)
Esempio n. 3
0
def add_post():
	title = request.form.get('title')
	worksheet_type_id = request.form.get('worksheet_type_id')
	finish_at = request.form.get('finish_at')
	content = request.form.get('content')
	user_id = session['user_data'].get('user_id')
	email = session['user_data'].get('email')
	worksheet_id = request.form.get('worksheet_id')
	file = request.files.get('file')
	file_location = None
	if file:
		filename = file.filename
		UPLOAD_FOLDER = upload_path + email.split('@')[0] + '/'
		if not os.path.exists(UPLOAD_FOLDER):
			os.mkdir(UPLOAD_FOLDER)
		file_location = os.path.join(UPLOAD_FOLDER, filename)
		file.save(file_location)
	if worksheet_id:
		try:
			worksheet_data = Worksheet.objects.filter(id=worksheet_id)[0]
		except:
			worksheet_data = None
		if not worksheet_data:
			result = {'status': 1001, 'message': '数据不存在'}
			return json.dumps(result)
		if worksheet_data.applier_id == user_id:
			user_data = User.objects.filter(id=user_id)[0]
			worksheet_data.title = title
			worksheet_data.worksheet_type_id = worksheet_type_id
			worksheet_data.finish_at = finish_at
			if file_location:
				worksheet_data.attached_file_path = file_location
			worksheet_data.content = content
			# worksheet_data.attached_file_path = file_location
			state_transfer(user_data, WS_USER_ACTION_DEVELOPER_RESUBMIT, worksheet_data)
			result = {'status': 200, 'message': '保存成功' , 'data': {'worksheet_id': worksheet_data.id}}
		else:
			result = {'status': 1001, 'message': '没有权限'}
		return json.dumps(result)

	try:
		apply_user = User.objects.filter(id=user_id)[0]
	except:
		apply_user = None
	try:
		if file_location:
			worksheet_data = Worksheet(title=title, applier_id=user_id, content=content, worksheet_type_id=worksheet_type_id, attached_file_path=file_location, planned_at=finish_at)
		else:
			worksheet_data = Worksheet(title=title, applier_id=user_id, content=content, worksheet_type_id=worksheet_type_id, planned_at=finish_at)
		worksheet_data.save()
		if apply_user.is_manager():
			state_transfer(apply_user, WS_USER_ACTION_TEAM_LEADER_CREATED, worksheet_data)
		else:
			state_transfer(apply_user, WS_USER_ACTION_DEVELOPER_CREATED, worksheet_data)
		if worksheet_data:
			result = {'status': 200, 'message': '保存成功', 'data': {'worksheet_id': worksheet_data.id}}
		else:
			result = {'status': 1001, 'message': '保存失败'}
	except Exception,e:
		result = {'status': 1001, 'message': '数据库异常'}
Esempio n. 4
0
def add_post():
    title = request.form.get('title')
    worksheet_type_id = request.form.get('worksheet_type_id')
    finish_at = request.form.get('finish_at')
    content = request.form.get('content')
    user_id = session['user_data'].get('user_id')
    email = session['user_data'].get('email')
    worksheet_id = request.form.get('worksheet_id')
    file = request.files.get('file')
    file_location = None
    if file:
        filename = file.filename
        UPLOAD_FOLDER = upload_path + email.split('@')[0] + '/'
        if not os.path.exists(UPLOAD_FOLDER):
            os.mkdir(UPLOAD_FOLDER)
        file_location = os.path.join(UPLOAD_FOLDER, filename)
        file.save(file_location)
    if worksheet_id:
        try:
            worksheet_data = Worksheet.objects.filter(id=worksheet_id)[0]
        except:
            worksheet_data = None
        if not worksheet_data:
            result = {'status': 1001, 'message': '数据不存在'}
            return json.dumps(result)
        if worksheet_data.applier_id == user_id:
            user_data = User.objects.filter(id=user_id)[0]
            worksheet_data.title = title
            worksheet_data.worksheet_type_id = worksheet_type_id
            worksheet_data.finish_at = finish_at
            if file_location:
                worksheet_data.attached_file_path = file_location
            worksheet_data.content = content
            # worksheet_data.attached_file_path = file_location
            state_transfer(user_data, WS_USER_ACTION_DEVELOPER_RESUBMIT,
                           worksheet_data)
            result = {
                'status': 200,
                'message': '保存成功',
                'data': {
                    'worksheet_id': worksheet_data.id
                }
            }
        else:
            result = {'status': 1001, 'message': '没有权限'}
        return json.dumps(result)

    try:
        apply_user = User.objects.filter(id=user_id)[0]
    except:
        apply_user = None
    try:
        if file_location:
            worksheet_data = Worksheet(title=title,
                                       applier_id=user_id,
                                       content=content,
                                       worksheet_type_id=worksheet_type_id,
                                       attached_file_path=file_location,
                                       planned_at=finish_at)
        else:
            worksheet_data = Worksheet(title=title,
                                       applier_id=user_id,
                                       content=content,
                                       worksheet_type_id=worksheet_type_id,
                                       planned_at=finish_at)
        worksheet_data.save()
        if apply_user.is_manager():
            state_transfer(apply_user, WS_USER_ACTION_TEAM_LEADER_CREATED,
                           worksheet_data)
        else:
            state_transfer(apply_user, WS_USER_ACTION_DEVELOPER_CREATED,
                           worksheet_data)
        if worksheet_data:
            result = {
                'status': 200,
                'message': '保存成功',
                'data': {
                    'worksheet_id': worksheet_data.id
                }
            }
        else:
            result = {'status': 1001, 'message': '保存失败'}
    except Exception, e:
        result = {'status': 1001, 'message': '数据库异常'}