Exemple #1
0
def query_edit(request, query_id=0, log_type=0):
    '''查询类编辑
    '''
    if request.REQUEST.get('edit_type', ''):
        return QueryTemplateEdit(request)()
    is_copy = request.REQUEST.get('is_copy', '')
    query_id = int(request.REQUEST.get('query_id', '') or 0)
    log_key = request.REQUEST.get('log_key', '')

    if query_id:
        model = Query.objects.using('read').get(id=query_id)
        if model.cache_validate == None:
            model.cache_validate = 0
        if is_copy:
            model.id = 0
            model.name = '%s-copy' % model.name
    else:
        model = Query()
        model.id = query_id
        model.name = ''
        model.cache_validate = 0
        model.log_key = log_key

    log_defs = LogDefine.objects.using('read').all()
    return render_to_response('query/query_edit.html', locals())
Exemple #2
0
def query_save(request, query_id=0):
    _g = request.REQUEST.get
    query_id = int(_g('query_id', '') or 0)

    if query_id:
        model = Query.objects.get(id=query_id)
    else:
        model = Query()

    err_msg = ''
    model.log_type = 0
    model.log_key = request.REQUEST.get('log_key', '0')
    model.select = request.REQUEST.get('select', '')
    model.remark = request.REQUEST.get('remark', '')
    model.name = request.REQUEST.get('name', '')
    model.where = request.REQUEST.get('where', '')
    model.group = request.REQUEST.get('group', '')
    model.order = request.REQUEST.get('order', '')
    model.cache_validate = int(request.REQUEST.get('cache_valid', 0))
    model.order_type = int(request.REQUEST.get('order_type', '0'))
    model.sql = request.REQUEST.get('sql', '')
    model.other_sql = request.REQUEST.get('other_sql', '')
    model.field_config = request.REQUEST.get("field_config", "")
    model.template_name = request.REQUEST.get('template_name', '')
    try:
        save_id = int(_g('save_id', '') or 0)
        if save_id != query_id and Query.objects.filter(id=save_id):
            err_msg = 'ID 已经存在'
        else:
            if save_id:
                model.id = save_id
                query_id = save_id
            model.save(using='write')
    except Exception, e:
        err_msg = trace_msg()
        print('query save error:', e)