def handle_task_approval(current_task, current_handler, handle_option, trustee_id, handle_remarks): _trustee = None if handle_option.do == "TRANSFER": if trustee_id: _trustee = User.objects.get(id=trustee_id) current_task.current_handler = _trustee elif handle_option.do == "APPROVE": current_task.status = current_task.status.next_status current_task.current_handler = get_user_by_task_role( current_task, current_task.status.handler_role) elif handle_option.do == "RETURN": current_task.status = current_task.status.pre_status current_task.current_handler = get_user_by_task_role( current_task, current_task.status.handler_role) if current_task.status.ready_state == "DONE": current_task.done_time = datetime.datetime.now() if handle_option.do != "UPDATE": current_task.save() clear_task_cache_by_id(current_task.id) TaskApproval.objects.create(handler=current_handler, task=current_task, option=handle_option, remarks=handle_remarks, trustee=_trustee) task_url = pmp.settings.SAAS_PORTAL + '/tasklist/' + str(current_task.id) msg_body = '我处理了任务【%s】 %s 补充意见:%s 链接: %s' % ( current_task.name, handle_option.opinion, handle_remarks, task_url) send_circle_msg(current_handler, msg_body) if current_task.current_handler: if current_task.current_handler != current_handler: send_msg(current_handler, current_task.current_handler, msg_body) return
def TeamChange(request): _user=get_valid_user(request) if _user and request.method=="POST": _do=request.POST.get("do","") _tid=request.POST.get("tid") _team=Team.objects.get(id=_tid) if _user not in _team.members.all(): messages.add_message(request, messages.INFO, '您没有权限修改团队资料!') return render(request, 'index.html', {'current_user':_user}) if _do=="addmember": _username=request.POST.get("username") if not _username: messages.add_message(request, messages.INFO, '请输入真实有效的用户名(电子邮件地址中@前面的部分)!') return render(request,'teaminfo.html',{'current_user':_user,'team':_team}) _email=_username+"@"+_user.company.top_domain_name try: _new_member=User.objects.get(email=_email) except: _new_member=User.objects.create(username=_username,email=_email,company=_user.company, need_modify_pwd=True,default_team=_team) _fail_silently=(not pmp.settings.DEBUG) mail_body='''您好! %s 将您添加到团队【%s】 ,初始口令为: Flzx3000c 请及时登录并修改口令: %s SDL SaaS''' % (_user.username, _team.name, pmp.settings.SAAS_PORTAL) send_mail('您已加入【%s】团队!' % _team.name, mail_body, pmp.settings.EMAIL_FROM,[_new_member.email], fail_silently=_fail_silently) if _new_member not in _team.members.all(): _team.members.add(_new_member) send_msg(_user, _new_member, '我已将您加入【%s】团队' % _team.name) send_circle_msg(_user, '热烈欢迎 %s 加入【%s】团队' % (_new_member.username, _team.name)) elif _do=="addadmin": _uid=int(request.POST.get("uid")) _new_admin=User.objects.get(id=_uid) _team.admins.add(_new_admin) elif _do=="removemember": _uid=int(request.POST.get("uid")) _member=User.objects.get(id=_uid) _team.members.remove(_member) elif _do=="removeadmin": _uid=int(request.POST.get("uid")) _admin=User.objects.get(id=_uid) if _team.admins.count()>1: _team.admins.remove(_admin) else: messages.add_message(request, messages.INFO, '请先添加一名管理员然后才能删除!') return render(request,'teaminfo.html',{'current_user':_user,'team':_team}) elif _do=="del": if _user in _team.admins.all() and _team.members.count()<2 and _team.team_projects.count()==0: for member in _team.default_team_users.all(): member.default_team=None member.save() _team.delete() messages.add_message(request, messages.INFO, '已删除指定的团队!') return HttpResponseRedirect("/team") _team.save() return HttpResponseRedirect("/team/"+str(_team.id)) return HttpResponseRedirect('/login')
def handle_project_approval(current_project, current_handler, handle_option, trustee_id, handle_remarks): _trustee = None if handle_option.do == "TRANSFER": if trustee_id: _trustee = User.objects.get(id=trustee_id) current_project.current_handler = _trustee elif handle_option.do == "SUBMIT": current_project.status = current_project.phase.phase_statuses.get( status='IN_APPROVAL') current_project.current_handler = get_user_by_project_role( current_project, current_project.status.handler_role) elif handle_option.do == "APPROVE": current_project.phase = current_project.phase.next_phase if current_project.phase.ready_state == 'CLOSE': project_status = current_project.phase.phase_statuses.get( status='IN_OPERATION') current_project.actual_end_date = datetime.date.today() else: project_status = current_project.phase.phase_statuses.get( status='IN_PROCESS') current_project.status = project_status current_project.current_handler = get_user_by_project_role( current_project, current_project.status.handler_role) elif handle_option.do == "RETURN": current_project.status = current_project.phase.phase_statuses.get( status='IN_PROCESS') current_project.current_handler = get_user_by_project_role( current_project, current_project.status.handler_role) current_project.save() ProjectApproval.objects.create(handler=current_handler, project=current_project, option=handle_option, remarks=handle_remarks, trustee=_trustee) project_url = pmp.settings.SAAS_PORTAL + '/projectlist/' + str( current_project.id) msg_body = '我审批了项目【%s】%s 审批意见:%s 补充意见:%s 链接: %s ' % ( current_project.no, current_project.name, handle_option.opinion, handle_remarks, project_url) send_circle_msg(current_handler, msg_body) if current_project.current_handler: send_msg(current_handler, current_project.current_handler, msg_body + ' 请您查看并处理或审批!') return
def TaskCreate(request): _user = get_valid_user(request) if _user: if request.method == "POST": _team_id = request.POST.get("team_id", "") if _team_id: _default_team = Team.objects.get(id=_team_id) _user.default_team = _default_team _user.save() else: _project = None _pid = int(request.POST.get("pid", "")) if _pid: _project = Project.objects.get(id=_pid) _name = request.POST.get("name") _description = request.POST.get("description") _plan_mandays = float(request.POST.get("plan_mandays")) _done_in_project_phase = None if _project: _done_in_project_phase = _project.phase _deadline = datetime.datetime.strptime( request.POST.get("deadline"), '%Y-%m-%d') _leader = User.objects.get(id=request.POST.get("leader_id")) _need_review = request.POST.get("need_review", None) if _need_review: _flow = get_task_flow_by_type('GEN') _reviewer = User.objects.get( id=request.POST.get("reviewer_id")) else: _flow = get_task_flow_by_type('TEAMWORK') _reviewer = _user _task = Task.objects.create( name=_name, description=_description, flow=_flow, assigner=_user, leader=_leader, reviewer=_reviewer, current_handler=_leader, plan_mandays=_plan_mandays, project=_project, is_kcp=False, is_subtask=False, done_in_project_phase=_done_in_project_phase, deadline=_deadline, team=_user.default_team, status=_flow.first_status) _members = request.POST.getlist("members", []) for member_id in _members: if member_id: _member = User.objects.get(id=member_id) _task.members.add(_member) TaskApproval.objects.create(handler=_user, task=_task, remarks='分配任务') _task_link = pmp.settings.SAAS_PORTAL + '/tasklist/' + str( _task.id) _msg = '我创建了任务:%s %s' % (_task.name, _task_link) send_circle_msg(_user, _msg) send_msg(_user, _task.current_handler, _msg) return HttpResponseRedirect('/tasklist') _projects = Project.objects.filter(team=_user.default_team).exclude( phase__ready_state='CLOSE') _teams = _user.member_teams.all() _flows = TaskFlow.objects.filter( team__isnull=True) | TaskFlow.objects.filter( team=_user.default_team) _deadline = (datetime.date.today() + datetime.timedelta(days=2)).strftime("%Y-%m-%d") return render( request, 'taskcreate.html', { 'current_user': _user, 'projects': _projects, 'teams': _teams, 'flows': _flows, 'deadline': _deadline }) return HttpResponseRedirect('/login')
def ProjectEdit(request, pid): _user = get_valid_user(request) if _user: _id = int(pid) try: _project = Project.objects.get(id=_id) except: messages.add_message(request, messages.INFO, '指定的项目不存在!') return render(request, 'index.html', {'current_user': _user}) if request.method == 'GET': return render(request, 'projectedit.html', { 'current_user': _user, 'project': _project }) _project.no = request.POST.get("no", "") _project.name = request.POST.get("name", "") _project.manager = User.objects.get(id=request.POST.get("manager_id")) _project.security_rep = User.objects.get( id=request.POST.get("security_rep_id")) _project.op_rep = User.objects.get(id=request.POST.get("op_rep_id")) _project.objective = request.POST.get("objective") _project.introduction = request.POST.get("introduction") _project.sponsor = User.objects.get(id=request.POST.get("sponsor_id")) _project.business_rep = User.objects.get( id=request.POST.get("business_rep_id")) _project.chief_reviewer = User.objects.get( id=request.POST.get("chief_reviewer_id")) _project.peer_reviewer = User.objects.get( id=request.POST.get("peer_reviewer_id")) _project.purchasing_rep = User.objects.get( id=request.POST.get("purchasing_rep_id")) _project.user_rep = User.objects.get( id=request.POST.get("user_rep_id")) _project.qa = User.objects.get(id=request.POST.get("qa_id")) _project.qc = User.objects.get(id=request.POST.get("qc_id")) _project.plan_start_date = datetime.datetime.strptime( request.POST.get("plan_start_date"), '%Y-%m-%d') _project.plan_end_date = datetime.datetime.strptime( request.POST.get("plan_end_date"), '%Y-%m-%d') _project.mandays = request.POST.get("mandays") _project.manday_cost = request.POST.get("manday_cost") _project.currency_unit = request.POST.get("currency_unit") _project.hardware_cost = request.POST.get("hardware_cost") _project.software_cost = request.POST.get("software_cost") _project.other_cost = request.POST.get("other_cost") _project.annual_license_cost = request.POST.get("annual_license_cost") _project.other_annual_cost = request.POST.get("other_annual_cost") # project members _members = request.POST.getlist("members", []) _project.members.clear() for member_id in _members: if member_id: _member = User.objects.get(id=member_id) _project.members.add(_member) # project stakeholders _stakeholders = request.POST.getlist("stakeholders") _project.stakeholders.clear() for stakeholder_id in _stakeholders: if stakeholder_id: _stakeholder = User.objects.get(id=stakeholder_id) _project.stakeholders.add(_stakeholder) _project.save() # create log _logtime = datetime.datetime.now() _action = 'edit' _project_url = pmp.settings.SAAS_PORTAL + '/projectlist/' + str( _project.id) _msg = "[" + _logtime.strftime( "%Y-%m-%d %H:%M:%S" ) + "] " + "我修改了项目【" + _project.no + "】" + _project.name + " " + _project_url send_circle_msg(_user, _msg) ProjectApproval.objects.create(handler=_user, project=_project, remarks='编辑项目') return HttpResponseRedirect('/projectlist/' + str(_project.id)) return HttpResponseRedirect('/login')
def ProjectCreate(request): _user = get_valid_user(request) if _user: _team = _user.get_default_team() if request.method == "GET": if not _team: messages.add_message(request, messages.INFO, '您目前不属于任何团队,请先创建团队或加入现有团队!') return render(request, 'teamlist.html', {'current_user': _user}) _step = request.POST.get("nextstep", "1") if _step == "1": _agl_flow_id = ProjectFlow.objects.get(type="AGL").id _app_flow_id = ProjectFlow.objects.get(type="APP").id _inf_flow_id = ProjectFlow.objects.get(type="INF").id _flow_id_dict = { 'AGL': _agl_flow_id, 'APP': _app_flow_id, 'INF': _inf_flow_id } _cus_flows = _team.team_flows.all() return render( request, 'pcreate_1.html', { 'current_user': _user, 'team': _team, 'cus_flows': _cus_flows, 'flow_id_dict': _flow_id_dict }) elif _step == "2": _default_project_no = '%03d' % (_team.team_projects.count() + 1) _flow_id = int(request.POST.get("fid", "")) _flow = ProjectFlow.objects.get(id=_flow_id) _curdate = datetime.date.today().strftime("%Y-%m-%d") _default_end_date = ( datetime.date.today() + datetime.timedelta(days=30)).strftime("%Y-%m-%d") return render( request, 'pcreate_2.html', { 'current_user': _user, 'project_flow': _flow, 'team': _team, 'default_project_no': _default_project_no, 'curdate': _curdate, 'default_end_date': _default_end_date }) elif _step == "3": _flow_id = int(request.POST.get("fid", "")) _flow = ProjectFlow.objects.get(id=_flow_id) _product_type = request.POST.get("product_type", "GEN") _tid = request.POST.get("tid", "") _team = Team.objects.get(id=_tid) _manager_id = request.POST.get("manager_id", "") _manager = User.objects.get(id=_manager_id) _architect_id = request.POST.get("architect_id", "") _architect = User.objects.get(id=_architect_id) _dev_rep_id = request.POST.get("dev_rep_id", "") _dev_rep = User.objects.get(id=_dev_rep_id) _test_rep_id = request.POST.get("test_rep_id", "") _test_rep = User.objects.get(id=_test_rep_id) _security_reviewer_id = request.POST.get("security_reviewer_id", _manager_id) _security_reviewer = User.objects.get(id=_security_reviewer_id) _op_rep_id = request.POST.get("op_rep_id", _manager_id) _op_rep = User.objects.get(id=_op_rep_id) _qa_id = request.POST.get("qa_id", _manager_id) _qa = User.objects.get(id=_qa_id) _no = request.POST.get("no", "") _name = request.POST.get("name", "") _objective = request.POST.get("objective") _introduction = request.POST.get("introduction") _plan_start_date = datetime.datetime.strptime( request.POST.get("plan_start_date"), '%Y-%m-%d') _plan_end_date = datetime.datetime.strptime( request.POST.get("plan_end_date"), '%Y-%m-%d') _mandays = request.POST.get("mandays") _manday_cost = request.POST.get("manday_cost") _currency_unit = request.POST.get("currency_unit") _phase = _flow.first_phase isCreateProject = True if pmp.settings.DEBUG: try: _project = Project.objects.get(no=_no) isCreateProject = False except: pass if isCreateProject: _project = Project.objects.create( no=_no, name=_name, flow=_flow, team=_team, product_type=_product_type, creator=_user, manager=_manager, architect=_architect, dev_rep=_dev_rep, test_rep=_test_rep, security_reviewer=_security_reviewer, op_rep=_op_rep, sponsor=_manager, business_rep=_manager, chief_reviewer=_manager, purchasing_rep=_manager, peer_reviewer=_manager, user_rep=_manager, qa=_qa, qc=_manager, objective=_objective, introduction=_introduction, plan_start_date=_plan_start_date, plan_end_date=_plan_end_date, actual_start_date=_plan_start_date, mandays=_mandays, manday_cost=_manday_cost, currency_unit=_currency_unit, current_handler=_manager, phase=_phase, status=_phase.phase_statuses.get(status='IN_PROCESS')) ProjectApproval.objects.create(handler=_user, project=_project, remarks='创建了项目') # Create KCP Task for AGL if _flow.type == "AGL": create_kcp_tasks(_project) _member_ids = request.POST.getlist("members", []) for _memberid in _member_ids: if _memberid: _member = User.objects.get(id=_memberid) _project.members.add(_member) _project.team.members.add(_member) _project.save() _project.team.save() if _flow.type == "AGL": messages.add_message(request, messages.INFO, '项目创建成功!') _msg = '我创建了项目【%s】%s %s' % (_project.no, _project.name, pmp.settings.SAAS_PORTAL + '/projectlist/' + str(_project.id)) send_circle_msg(_user, _msg) return HttpResponseRedirect('/projectlist/' + str(_project.id)) else: messages.add_message(request, messages.INFO, '根据您选择的项目管理流程类型,请继续补充完善如下信息:') return render(request, 'pcreate_3.html', { 'current_user': _user, 'project': _project }) elif _step == "4": _project = Project.objects.get(id=request.POST.get("pid")) _sponsor = User.objects.get( id=request.POST.get("sponsor_id", _user.id)) _business_rep = User.objects.get( id=request.POST.get("business_rep_id", _user.id)) _chief_reviewer = User.objects.get( id=request.POST.get("chief_reviewer_id", _user.id)) _purchasing_rep = User.objects.get( id=request.POST.get("purchasing_rep_id", _user.id)) _peer_reviewer = User.objects.get( id=request.POST.get("peer_reviewer_id", _user.id)) _user_rep = User.objects.get( id=request.POST.get("user_rep_id", _user.id)) _qc = User.objects.get(id=request.POST.get("qc_id", _user.id)) _project.sponsor = _sponsor _project.current_handler = _sponsor _project.business_rep = _business_rep _project.chief_reviewer = _chief_reviewer _project.purchasing_rep = _purchasing_rep _project.peer_reviewer = _peer_reviewer _project.user_rep = _user_rep _project.qc = _qc _hardware_cost = request.POST.get("hardware_cost", "0.0") _software_cost = request.POST.get("software_cost", "0.0") _other_cost = request.POST.get("other_cost", "0.0") _annual_license_cost = request.POST.get("annual_license_cost", "0.0") _other_annual_cost = request.POST.get("other_annual_cost", "0.0") _project.hardware_cost = _hardware_cost _project.software_cost = _software_cost _project.other_cost = _other_cost _project.annual_license_cost = _annual_license_cost _project.other_annual_cost = _other_annual_cost # project stakeholders _stakeholders = request.POST.getlist("stakeholders", []) for _stakeholder_id in _stakeholders: if _stakeholder_id: _stakeholder = User.objects.get(id=_stakeholder_id) _project.stakeholders.add(_stakeholder) _project.save() create_kcp_tasks(_project) _msg = '我创建了项目【%s】%s %s' % (_project.no, _project.name, pmp.settings.SAAS_PORTAL + '/projectlist/' + str(_project.id)) send_circle_msg(_user, _msg) return HttpResponseRedirect('/projectlist/' + str(_project.id)) # Show create UI for GET request _curdate = datetime.date.today().strftime("%Y-%m-%d") _default_end_date = (datetime.date.today() + datetime.timedelta(days=30)).strftime("%Y-%m-%d") return render( request, 'pcreate_1.html', { 'current_user': _user, 'curdate': _curdate, 'default_end_date': _default_end_date }) return HttpResponseRedirect('/login')