Example #1
0
def add_actiongroup(request):
    '''
    新增操作组
    '''    
    actions = Action.objects.order_by('action_type')
    if request.POST:
        name = request.POST.get('name', None)  # 名称。如,LSE4部署。
        desc = request.POST.get('desc', None)  # 说明。
        actionids = request.POST.getlist('actionids', None)  # 操作
        
        actiongroup = ActionGroup.objects.filter(name__iexact=name)
        if actiongroup:
            return HttpResponse(simplejson.dumps({"statusCode": 302,
                                                  "navTabId": request.POST.get('navTabId', 'actiongroupindex'),
                                                  "callbackType": request.POST.get('callbackType', None),
                                                  "message": u'此操作组已存在,不能添加',
                                                  "info": u'此操作组已存在,不能添加',
                                                  "result": u'此操作组已存在,不能添加'}),
                                mimetype='application/json')
        actiongroup = ActionGroup(name=name, desc=desc)
        actiongroup.save()
        action_group = ActionGroup.objects.get(name=name, desc=desc)
        
        if actionids != None and len(actionids) != 0:
            order = 0
            for actionid in actionids:
                action = Action.objects.get(id__exact = actionid)
                action_order = ActionOrder(action = action, group = action_group, order = order)
                action_order.save()
                order = order + 1
        
        Log(username = request.user.username,
            content = u"操作组添加成功,组名称是:" + name).save()
        return HttpResponse(simplejson.dumps({"statusCode": 200,
                                              "navTabId": request.POST.get('navTabId', 'actiongroupindex'),
                                              "callbackType": request.POST.get('callbackType', 'closeCurrent'),
                                              "message": u'操作组' + name + u'添加成功'}),
                            mimetype='application/json')
    return render_to_response('action/add_actiongroup.html', {'actions': actions})
Example #2
0
def edit_actiongroup(request, id):
    '''
    编辑操作组
    '''
    actiongroup = get_object_or_404(ActionGroup, pk = int(id))
    actionorders = ActionOrder.objects.filter(group__id__exact = id).order_by('order')
    sql = ''
    for actionorder in actionorders:
        sql += '~Q(id=' + str(actionorder.action.id) + ') & '
    if sql != '':
        sql = sql[0:-2]
        actions = Action.objects.filter(eval(sql)).order_by('action_type')
    else :
        actions = Action.objects.order_by('action_type')   
    if request.POST:
        desc = request.POST.get('desc', None)  # 说明。
        actionids = request.POST.getlist('actionids', None)  # 操作        
        
        actiongroup.desc = desc
        if actionids != None and len(actionids) != 0:
            actionorders.delete()  # 删除操作组中已有的操作序列
            order = 0
            for actionid in actionids:
                action = Action.objects.get(id__exact = actionid)
                action_order = ActionOrder(action = action, group = actiongroup, order = order)
                action_order.save()
                order = order + 1
        actiongroup.save()
        Log(username = request.user.username,
            content = u"操作组编辑成功,组名称是:" + actiongroup.name).save()
        return HttpResponse(simplejson.dumps({"statusCode": 200,
                                              "navTabId": request.POST.get('navTabId', 'actiongroupindex'),
                                              "callbackType": request.POST.get('callbackType', 'closeCurrent'),
                                              "message": u'操作组“' + actiongroup.name + u'”编辑成功'}),
                            mimetype='application/json')
    return render_to_response('action/edit_actiongroup.html', 
                              {'actions': actions, 'actiongroup':actiongroup, 
                               'actionorders': actionorders})