コード例 #1
0
def column_edit(request, response, column_id=None):
    user = get_request_user(request)
    instance = Column.objects.get(pk=column_id) if column_id else None
    model_log = ModelLogger(instance)
    Form = ColumnEditForm if instance and instance.model else ColumnForm
    form = Form(request.POST or None, instance=instance)
    if form.is_valid():
        if not instance:
            form.instance.create_user = user
        form.instance.update_user = user
        obj = form.save()
        log.success(request, model_log.message(obj), log.CREATE)
        messages.success(request, (instance and '修改' or '创建') + '栏目: ' + str(obj) + ' 成功')
        return redirect('admin:cms:column')
    return locals()
コード例 #2
0
ファイル: admin.py プロジェクト: HalberdBroken/jiango
def path_edit(request, response, path_id=None):
    user = get_request_user(request)
    instance = Path.objects.get(pk=path_id) if path_id else None
    model_log = ModelLogger(instance)
    form = PathForm(request.POST or None, instance=instance)
    if form.is_valid():
        if not instance:
            form.instance.create_user = user
        form.instance.update_user = user
        obj = form.save()
        log.success(request, model_log.message(obj), log.CREATE)
        messages.success(request, (instance and u'修改' or u'创建') + u'栏目: ' +
                         unicode(obj) + u' 成功')
        return redirect('admin:cms:path')
    return locals()
コード例 #3
0
def column_delete(request, response, column_id):
    user = get_request_user(request)
    instance = Column.objects.get(pk=column_id)
    # 删除确认表单
    form = ColumnDeleteForm(request.POST or None)
    if form.is_valid():
        msg = '删除栏目: ' + str(instance)
        logs = [msg, ModelLogger(instance).message()]
        # 删除子栏目
        for i in instance.children(-1):
            logs.append('子栏目: ' + str(i))
            logs.append(ModelLogger(i).message())
            i.delete()
        instance.delete()
        log.success(request, '\n'.join(logs), log.DELETE)
        messages.success(request, msg + ' 完成')
        return redirect('admin:cms:column')
    deleted_columns = [instance]
    deleted_columns.extend(list(instance.children(-1)))
    return locals()
コード例 #4
0
ファイル: admin.py プロジェクト: HalberdBroken/jiango
def path_delete(request, response, path_id):
    user = get_request_user(request)
    instance = Path.objects.get(pk=path_id)
    # 删除确认表单
    form = PathDeleteForm(request.POST or None)
    if form.is_valid():
        msg = u'删除栏目: ' + unicode(instance)
        logs = [msg, ModelLogger(instance).message()]
        # 删除子栏目
        for i in instance.children(-1):
            logs.append(u'子栏目: ' + unicode(i))
            logs.append(ModelLogger(i).message())
            i.delete()
        instance.delete()
        log.success(request, '\n'.join(logs), log.DELETE)
        messages.success(request, msg + u' 完成')
        return redirect('admin:cms:path')
    deleted_paths = [instance]
    deleted_paths.extend(list(instance.children(-1)))
    return locals()
コード例 #5
0
def content_edit(request, response, column_select, content_id=None):
    user = get_request_user(request)
    is_content_edit = True
    column = column_select.selected
    
    Model = column.get_model_object('model')
    Form = column.get_model_object('form')
    if Model is None or Form is None:
        raise Alert(Alert.ERROR, '此栏目 %s 不可添加内容' % column)
    
    content = Model.objects.get(column=column, pk=content_id) if content_id else None
    model_log = ModelLogger(content)
    
    # 权限检查
    if not content:
        has_perm(request, 'cms.content.create')
    elif content.create_user == user:
        has_perm(request, 'cms.content.update.self')
    else:
        has_perm(request, 'cms.content.update.other')
    
    # 删除操作
    delete_id = request.GET.get('delete')
    if content and not content.is_deleted and content_id == delete_id:
        has_perm(request, 'cms.action.delete')
        update_instance(content, is_deleted=True)
        log.success(request, model_log.message(content), log.DELETE)
        messages.success(request, '删除内容: %s 成功' % str(content))
        return redirect('admin:cms:content-path', column.path)
    
    # 删除恢复
    recover_id = request.GET.get('recover')
    if content and content.is_deleted and content_id == recover_id:
        has_perm(request, 'cms.content.recover')
        update_instance(content, is_deleted=False)
        log.success(request, model_log.message(content), log.UPDATE)
        messages.success(request, '恢复删除内容: %s 成功' % str(content))
        return redirect('admin:cms:content-path', column.path)
    
    if request.method == 'POST':
        form = Form(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.instance.column = column
            form.instance.column_path = column.path
            form.instance.column_depth = column.depth
            if not form.instance.create_user:
                form.instance.create_user = user
            form.instance.update_user = user
            obj = form.save()
            
            log.success(request, model_log.message(obj), log.CREATE)
            messages.success(request, (content and '修改' or '创建') + '内容: ' + str(obj) + ' 成功')
            if request.GET.get('next'):
                return HttpResponseRedirect(request.GET.get('next'))
            return redirect('admin:cms:content-path', column.path)
    else:
        form = Form(instance=content)
    
    # 表单字段分离
    main_fields = []
    meta_fields = []
    meta_fields_name = ['is_hidden']
    _t = column.get_model_object('form_meta_fields')
    if _t:
        meta_fields_name.extend(_t)
    
    for i in form.visible_fields():
        if i.name in meta_fields_name:
            meta_fields.append(i)
        else:
            main_fields.append(i)
    
    return 'content', locals()
コード例 #6
0
ファイル: admin.py プロジェクト: HalberdBroken/jiango
def _content_edit(request, response, current_path=None, content_id=None):
    user = get_request_user(request)
    is_content_edit = True

    if content_id:
        content_base = ContentBase.objects.get(pk=content_id)
        Model = content_base.model_class
        Form = content_base.form_class
        path = content_base.path
        content = Model.objects.get(pk=content_id)
        current_path = get_current_path(path.path)
    elif current_path:
        path = current_path.selected
        Model = path.model_class
        Form = path.form_class
        content = None
    else:
        raise Alert(Alert.ERROR, u'缺少必要参数')

    if Form is None:
        raise Alert(Alert.ERROR, u'此栏目 %s 不可添加内容' % path)

    model_log = ModelLogger(content)

    # 权限检查
    if not content:
        has_perm(request, 'cms.content.create')
    elif content.create_user == user:
        has_perm(request, 'cms.content.update.self')
    else:
        has_perm(request, 'cms.content.update.other')

    # 删除操作
    delete_id = request.GET.get('delete')
    if content and not content.is_deleted and content_id == delete_id:
        has_perm(request, 'cms.action.delete')
        update_instance(content, is_deleted=True)
        log.success(request, model_log.message(content), log.DELETE)
        messages.success(request, u'删除内容: %s 成功' % unicode(content))
        return redirect('admin:cms:content-path', path.path)

    # 删除恢复
    recover_id = request.GET.get('recover')
    if content and content.is_deleted and content_id == recover_id:
        has_perm(request, 'cms.content.recover')
        update_instance(content, is_deleted=False)
        log.success(request, model_log.message(content), log.UPDATE)
        messages.success(request, u'恢复删除内容: %s 成功' % unicode(content))
        return redirect('admin:cms:content-path', path.path)

    if request.method == 'POST':
        form = Form(request.POST, request.FILES, instance=content)
        if form.is_valid():
            form.instance.path = path
            form.instance.path_value = path.path
            form.instance.path_depth = path.depth
            if not form.instance.model:
                form.instance.model = path.model
            if not form.instance.create_user:
                form.instance.create_user = user
            form.instance.update_user = user
            obj = form.save()

            log.success(request, model_log.message(obj), log.CREATE)
            messages.success(request, (content and u'修改' or u'创建') + u'内容: ' +
                             unicode(obj) + u' 成功')
            if request.GET.get('next'):
                return HttpResponseRedirect(request.GET.get('next'))
            return redirect('admin:cms:content-path', path.path)
    else:
        form = Form(instance=content)

    # 表单字段分离
    main_fields = []
    meta_fields = []
    meta_fields_name = ['flag', 'collections', 'is_hidden']
    _t = path.model_config.get('form_meta_fields')
    if _t:
        meta_fields_name.extend(_t)

    for i in form.visible_fields():
        if i.name in meta_fields_name:
            meta_fields.append(i)
        else:
            main_fields.append(i)

    return 'content_edit', locals()