示例#1
0
def move_rep(id, to_pos="+1"):
    obj = models.Report.objects.get(pk=id)
    url = make_path('ok')
    if not obj.parent:
        return HttpResponseRedirect(url)

    if type(to_pos) == str:
        if to_pos == "+1":
            objects = models.Report.objects.filter(parent=obj.parent).filter(
                order__gt=obj.order)
            if len(objects) > 0:
                obj2 = objects[0]
            else:
                return HttpResponseRedirect(url)
        elif to_pos == '-1':
            objects = models.Report.objects.filter(parent=obj.parent).filter(
                order__lt=obj.order)
            if len(objects) > 0:
                obj2 = list(objects)[-1]
            else:
                return HttpResponseRedirect(url)

        tmp_order = obj.order
        obj.order = obj2.order
        obj2.order = tmp_order
        obj.save()
        obj2.save()

    elif type(to_pos) == int:
        obj2 = models.Report.objects.get(pk=to_pos)
        order = obj2.order
        if obj.order < order:
            objects = models.Report.objects.filter(parent=obj.parent).filter(
                order__gt=obj2.order).update(order=F('order') + 2)
            obj.order = order + 1
        else:
            objects = models.Report.objects.filter(parent=obj.parent).filter(
                order__gte=obj2.order).update(order=F('order') + 2)
            obj.order = order
        obj.save()

    url = make_path('ok')
    return HttpResponseRedirect(url)
示例#2
0
def edit__group(request, group_id):

    group = models.CommonGroup.objects.get(pk=group_id)
    group_def = models.CommonGroupDef.objects.get(name=group.group_def_name)

    if group_def.declaration:
        form_class = form_from_str(group_def.declaration)
    else:
        return HttpResponse("ERROR")

    if request.POST or request.FILES:
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES)
            if form.is_valid():
                if group_def.save_fun:
                    exec(group_def.save_fun)
                    data = locals()['save'](form, group)
                else:
                    data = form.cleaned_data
                if 'title' in data:
                    group.title = data['title']
                    del data['title']
                group._data = data
                group._data['json_update'] = True
                group.save()
                url = make_path('ok')
                return HttpResponseRedirect(url)

    if not request.POST:
        data = group.get_json_data()

        if group_def.load_fun:
            exec(group_def.load_fun)
            data_form = locals()['load'](data)
        else:
            data_form = data
        data_form['title'] = group.title
        form = form_class(initial=data_form)

    t = Template(ihtml_to_html(None, group_def.template))
    c = RequestContext(request, {
        'form': form,
        'group': group,
        'group_def': group_def
    })

    return HttpResponse(t.render(c))
示例#3
0
文件: views.py 项目: JdeH/pytigon
def duplicate_rep(request, parm):
    def copy_rep(source, dest):
        dest.parent = source.parent
        dest.order = source.order
        dest.report_def_name = source.report_def_name
        dest.date = source.date
        dest.jsondata = source.jsondata

    id = int(parm)
    doc = DocHead.objects.filter(pk=id)

    if len(doc) == 1:
        d = doc[0]
        rep = Report.objects.filter(order=d.id)
        if len(rep) == 1:
            doc2 = DocHead()
            doc2.doc_type_parent = d.doc_type_parent
            doc2.org_chart_parent = d.org_chart_parent
            doc2.description = d.description
            doc2.date = datetime.datetime.now()
            doc2.status = 'edit'
            doc2.operator = request.user.username
            doc2.param1 = d.param1
            doc2.param2 = d.param2
            doc2.param3 = d.param3
            doc2.jsondata = d.jsondata
            doc2.save()

            rep2 = Report()
            copy_rep(rep[0], rep2)
            rep2.order = doc2.id
            rep2.save()

            subreps = Report.objects.filter(parent=rep[0])
            if len(subreps) > 0:
                for subrep in subreps:
                    subrep2 = Report()
                    copy_rep(subrep, subrep2)
                    subrep2.parent = rep2
                    subrep2.save()

    url = make_path('ok')
    return HttpResponseRedirect(url)
示例#4
0
def edit__rep(request, rep_id):

    rep = models.Report.objects.get(pk=rep_id)
    rep_def = models.ReportDef.objects.get(name=rep.report_def_name)

    if rep_def.declaration:
        form_class = form_from_str(rep_def.declaration)
    else:
        return "ERROR"

    if request.POST or request.FILES:
        if request.method == 'POST':
            form = form_class(request.POST, request.FILES)
            if form.is_valid():
                if rep_def.save_fun:
                    exec(rep_def.save_fun)
                    data = locals()['save'](form, rep)
                else:
                    data = form.cleaned_data
                rep._data = data
                rep._data['json_update'] = True
                rep.save()
                url = make_path('ok')
                return HttpResponseRedirect(url)

    if not request.POST:
        data = rep.get_json_data()

        if rep_def.load_fun:
            exec(rep_def.load_fun)
            data_form = locals()['load'](data)
        else:
            data_form = data
        form = form_class(initial=data_form)

    t = Template(ihtml_to_html(None, rep_def.template))
    c = RequestContext(request, {'form': form, 'rep': rep, 'rep_def': rep_def})

    return HttpResponse(t.render(c))
示例#5
0
def edit_page_object(request):

    name = request.GET.get('name', None)
    if name:
        name = name.replace('\r', '').strip()
        name0 = name.split('_')[0]
        object_list = models.PageObjectsConf.objects.filter(name=name0)
        if len(object_list) > 0:
            obj = object_list[0]
            pk = request.GET.get('page_id', 0)
            page = models.Page.objects.get(pk=pk)

            if obj.edit_form:
                form_class = form_from_str(obj.edit_form)
            else:
                form_class = None
                form = None

            context = {'conf': obj, 'page': page, 'request': request}

            if request.POST or request.FILES:
                if request.method == 'POST':
                    if form_class:
                        form = form_class(request.POST, request.FILES)
                        if form.is_valid():
                            if obj.save_fun:
                                try:
                                    context['old_data'] = page.get_json_data(
                                    )[name]
                                except:
                                    pass
                                exec(obj.save_fun)
                                data = locals()['save'](form, context)
                            else:
                                data = form.cleaned_data
                            page._data = {name: data}
                            page._data['json_update'] = True
                            page.operator = request.user.username
                            page.update_time = datetime.datetime.now()
                            page.save()
                            url = make_path('ok')
                            return HttpResponseRedirect(url)
                    else:
                        url = make_path('ok')
                        return HttpResponseRedirect(url)

            if not request.POST:
                if form_class:
                    data = page.get_json_data()

                    if obj.load_fun:
                        exec(obj.load_fun)
                        data_form = locals()['load'](data, context)
                    else:
                        if name in data:
                            data_form = data[name]
                        else:
                            data_form = {}
                    form = form_class(initial=data_form)

            template_name1 = (obj.app + "/" +
                              obj.name).lower() + "_wikiobj_edit.html"
            template_name2 = "schwiki/wikiobj_edit.html"

            t = select_template([
                template_name1,
                template_name2,
            ])
            c = {'form': form, 'object': obj, 'page': page}

            return HttpResponse(t.render(c, request))

    url = make_path('ok')
    return HttpResponseRedirect(url)