Esempio n. 1
0
def db_app_add(**kwargs):
    """
    add app to db
    添加应用时数据库操作函数
    """
    group_id_list = kwargs.pop('groups')
    app = App(**kwargs)
    app.save()

    group_select = []
    for group_id in group_id_list:
        group = AppGroup.objects.filter(id=group_id)
        group_select.extend(group)
    app.group = group_select
Esempio n. 2
0
def db_app_add(**kwargs):
    """
    add app to db
    添加应用时数据库操作函数
    """
    group_id_list = kwargs.pop('groups')
    app = App(**kwargs)
    app.save()

    group_select = []
    for group_id in group_id_list:
        group = AppGroup.objects.filter(id=group_id)
        group_select.extend(group)
    app.group = group_select
Esempio n. 3
0
    try:
        data = xlrd.open_workbook(filename=None, file_contents=excel_file.read())
    except Exception, e:
        return False
    else:
        table = data.sheets()[0]
        rows = table.nrows
        for row_num in range(1, rows):
            row = table.row_values(row_num)
            if row:
                group_instance = []
                value, name, use_default_auth, group = row
                if get_object(App, name=name):
                    continue
                use_default_auth = 1 if use_default_auth == u'默认' else 0
                if name:
                    app = App(value=value,
                                  name=name,
                                  use_default_auth=use_default_auth
                                  )
                    app.save()
                    group_list = group.split('/')
                    for group_name in group_list:
                        group = get_object(AppGroup, name=group_name)
                        if group:
                            group_instance.append(group)
                    if group_instance:
                        app.group = group_instance
                    app.save()
        return True
Esempio n. 4
0
    try:
        data = xlrd.open_workbook(filename=None,
                                  file_contents=excel_file.read())
    except Exception, e:
        return False
    else:
        table = data.sheets()[0]
        rows = table.nrows
        for row_num in range(1, rows):
            row = table.row_values(row_num)
            if row:
                group_instance = []
                value, name, use_default_auth, group = row
                if get_object(App, name=name):
                    continue
                use_default_auth = 1 if use_default_auth == u'默认' else 0
                if name:
                    app = App(value=value,
                              name=name,
                              use_default_auth=use_default_auth)
                    app.save()
                    group_list = group.split('/')
                    for group_name in group_list:
                        group = get_object(AppGroup, name=group_name)
                        if group:
                            group_instance.append(group)
                    if group_instance:
                        app.group = group_instance
                    app.save()
        return True