def list(request, project, status): user, email, usernum = request.user.username.split("|")[:] if Account.objects.filter(user=user).values()[0]['is_supper_user'] != 1: return render_to_response("workflow_error.html", {"config":config}) data['project'] = project data['current_group'] = get_approve_group(project, status) data['group'] = [] for row in get_group_all(): data['group'].append(row['name']) data['status'] = status data['user_current'] = [] data['user'] = [] #user list ====================================================================== user_result = {} data['user_current_group'] = get_approve_group(project, status) for g in data['user_current_group']: u_name = get_group_user(g) if u_name: for username in u_name: user_result[username] = 0 for userid in Configuration.objects.filter(project=project, status=status).values()[0]['approve_user'].strip().split(","): if userid: user_result[get_user_name(userid)] = 0 #print user_result for username in user_result.keys(): data['user_current'].append(username) for row in get_alluser(): data['user'].append(row['user']) #=============================================================== if request.method == 'POST': result = "" print request.POST print status if request.POST.get('method') == 'group': group_list = request.POST.getlist("group_list[]") group_dict = {} approve_group_id = [] for g in group_list: group_dict[Group.objects.filter(name=g).values()[0]['id']] = 0 for id in Configuration.objects.filter(status=status, project=project).values()[0]['approve_group'].strip().split(","): if id: approve_group_id.append(int(id)) for row in group_dict.keys(): if row in approve_group_id: continue else: approve_group_id.append(int(row)) approve_group_id = sorted(approve_group_id) for r in approve_group_id: result += "%d," % r result = re.sub(",$" , "" , result) if status == '100': Configuration.objects.filter(status=102, project=project).update(approve_group=result) Configuration.objects.filter(status=103, project=project).update(approve_group=result) Configuration.objects.filter(status=status, project=project).update(approve_group=result) return HttpResponseRedirect("/workflow/config/%s/" % project) elif request.POST.get('method') == 'user': user_list = request.POST.getlist("user_list[]") user_dict = {} approve_user_id = [] current_user_id = [] result = "" result_unique = {} for u in user_list: user_dict[u] = 0 for appid in Configuration.objects.filter(status=status, project=project).values()[0]['approve_user'].strip().split(","): current_user_id.append(appid) for user, t in user_dict.iteritems(): approve_user_id.append(Account.objects.filter(user=user).values()[0]['id']) for id in approve_user_id: if id in current_user_id: continue else: result += "%d," % id for o_id in Configuration.objects.filter(status=status, project=project).values()[0]['approve_user'].strip().split(","): if o_id: result += "%d," % int(o_id) result = re.sub(",$", "", result) for r in result.split(","): result_unique[r] = 0 result = "" for k,v in result_unique.iteritems(): result += "%d," % int(k) result = re.sub(",$", "", result) print result if result.split(): Configuration.objects.filter(status=status, project=project).update(approve_user=result) if status == '100': Configuration.objects.filter(status=102, project=project).update(approve_user=result) Configuration.objects.filter(status=103, project=project).update(approve_user=result) return HttpResponseRedirect("/workflow/config/%s/" % project) return render_to_response("workflow_list.html", {"config":config, "data":data, "js":js})
def configuration(request, pjt=""): user, email, usernum = request.user.username.split("|")[:] config['user'] = user unique = {} data['project'] = "[" for row in Node.objects.all().values(): if unique.has_key(row['project']): continue unique[row['project']] = "" data['project'] += '"%s",' % row['project'] data['project'] = re.sub(",$" , "" , data['project']) data['project'] += "]" project = "" project = request.POST.get('project', '') if pjt != '': project = pjt contents = {} result_table = {} unique_user_name = {} if project: index = 1 index_table = 1 for row in Configuration.objects.filter(project=project).order_by('status').values(): if index == 1: row['name'] = u"新建" contents[index] = {} contents[index][row['name']] = 1000 index += 1 continue if row['status'] == 0 or row['status'] == 102 or row['status'] == 103 or row['status'] > 103: continue if row['status'] > 0 and row['status'] < 100: row['name'] += u"审批" contents[index] = {} contents[index][row['name']] = row['status'] index += 1 #table for row in Configuration.objects.filter(project=project).order_by('status').values(): if row['status'] > 0 and row['status'] < 101: unique_user_name = {} result_table[index_table] = {} result_table[index_table]['approve_group'] = "" result_table[index_table]['approve_user'] = "" for id in row['approve_group'].strip().split(","): if id: result_table[index_table]['approve_group'] += "%s<br>" % get_group_name(id) for name, id in get_group_user_name_id(id).iteritems(): unique_user_name[name] = 0 #print unique_user_name for id in row['approve_user'].strip().split(","): if id: unique_user_name[get_user_name(id)] = 0 for user in unique_user_name.keys(): result_table[index_table]['approve_user'] += "%s<br>" % user result_table[index_table]['name'] = row['name'] result_table[index_table]['project'] = row['project'] result_table[index_table]['status'] = row['status'] index_table += 1 else: pass #print contents #print result_table return render_to_response("sys_workflow_view.html", {"config":config, "data":data, "contents":contents, "project":project, "result_table" : result_table })