Ejemplo n.º 1
0
def updateform_view(request, dtype):
    eid = request.POST.get('doc_id')
    data, doc, baseform, template = get_basics(request, doctype)
    append_key = check_append(data)

    if append_key:
        context = add_compoundfield_doc(doc, baseform, data, append_key, eid)
    else:
        context = update_doc(doc, baseform, data)
    if not context:
        raise Http404

    context.update({
        'type' : dtype,
        'doc' : json.dumps(doc),
        'doc_id': eid,
        "description" : doc.get("description").capitalize(),
        'languages' : supported_languages(),
        'tab_ids'     : prepare_tabs(context['form']),
        'skip_js': True,
        'request': request
    })
    s = template_render(template, context)

    return HttpResponse(s)
Ejemplo n.º 2
0
def add_linkdata_view(request, doctype, exdoctype, linkfield):
    """
    Function adds given given exdoc_id's to given target field and
    sets given linkfield with the modeldocs eid

    TODO: reliable way to find where to put the eid of linked doc in form
          reasonable way to loop the model docs with their id's

    building the form is ever so slightly different when one wants to
    update it with some values and replace with others (linkfield and modeldoc)
    """
    #append_data = conn.get(settings.INDEX_NAME, doctype, exdoc_id)
    exdoc_ids = request.GET.getlist('exdoc_id')
    if not exdoc_ids:
        raise Http404
    append_key = request.GET.get('target')
    if not append_key:
        raise Http404
    template = None
    if doctype == 'organisation':
        template = env.get_template('organisation_form.html')

    eid = request.POST.get('doc_id')
    data, doc, baseform, template = get_basics(request, doctype, template=template)
    example_data = searcher.get_docs(exdoctype, exdoc_ids)
    #if is_compoundfield(doc, append_key):
    #    append_data = example_data
    #else:
    #    append_data = create_exampledoc(doc, append_key, example_data[0])
    #TODO: plz fix.. doclist and eid list are in same order, but not pretty
    for eid_num, modeldoc in enumerate(example_data):
        #TODO: plz fix.. linkfield might not be at first level of subdoc
        modeldoc[linkfield] = exdoc_ids[eid_num]
    context = add_linkdata_doc(doc, baseform, data, append_key, example_data)
    if not context:
        raise Http404

    path = request.path_info + '?doc_id={0}'.format(eid)

    context.update({
        'type' : doctype,
        'doc' : json.dumps(doc),
        'user': request.user,
        'doc_id' : eid,
        'title': data.get('name_fi'),
        "description" : doc.get("description").capitalize(),
        'reload_path': '/add/{dt}/?doc_id={eid}'.format(dt=doctype, eid=eid),
        'languages' : supported_languages(),
        'tab_ids'     : prepare_tabs(context['form']),
        'skip_js': True,
        'request': request
    })
    s = template_render(template, context)
    sr = re.sub(r'\s+', ' ', s)
    return HttpResponse(sr)
Ejemplo n.º 3
0
def add_exampledata_view(request, doctype, exdoctype, append_key):
    #append_data = conn.get(settings.INDEX_NAME, doctype, exdoc_id)
    exdoc_ids = request.GET.getlist('exdoc_id')

    if not exdoc_ids:
        raise Http404

    template = None

    eid = request.POST.get('doc_id')

    if doctype == 'organisation':
        template = env.get_template('organisation_form.html')
    data, doc, baseform, template = get_basics(request, doctype, template=template)
    example_data = searcher.get_docs(exdoctype, exdoc_ids)
    if is_compoundfield(doc, append_key):
        append_data = example_data
    else:
        append_data = create_exampledoc(doc, append_key, example_data[0])
    context = add_fielddata_doc(doc, baseform, data, append_key, append_data)
    if not context:
        raise Http404

    path = request.path_info + '?doc_id={0}'.format(eid)

    context.update({
        'type' : doctype,
        'doc' : json.dumps(doc),
        'user': request.user,
        'doc_id' : eid,
        'title': data.get('name_fi'),
        "description" : doc.get("description").capitalize(),
        'reload_path': '/add/{dt}/?doc_id={eid}'.format(dt=doctype,
                                                                    eid=eid),
        'languages' : supported_languages(),
        'tab_ids'     : prepare_tabs(context['form']),
        'skip_js': True,
        'request': request})
    s = template_render(template, context)
    return HttpResponse(s)
Ejemplo n.º 4
0
def add_view(request, dtype, entity_id=None):
    data, doc, baseform, template = get_basics(request, dtype)
    remove_key = check_remove(data)
    append_key = check_append(data)
    eid = entity_id

    if remove_key:
        context = remove_field_doc(doc, baseform, data, remove_key)
        context['doc_id'] = eid
    elif append_key:
        context = add_compoundfield_doc(doc, baseform, data, append_key, eid)
    else:
        if eid and not data:
            context = open_doc(doc, baseform, request.user, eid)
        elif data:
            context = save_doc(doc, baseform, data, request.user, eid)
            eid = context['doc_id']

            if context['saved'] and context['errors'] == None:
                store_context(context, request.session)
                return redirect('kir.views.add_view', dtype, eid)
        else:
            context = new_doc(doc, baseform)

    if not context:
        raise Http404

    context = restore_context(context, request.session)
    context = process_metafields(context)

    if 'doc_id' in context:
        path = request.path_info
    else:
        path = None

    context.update({
        'type'        : dtype,
        'doc'         : json.dumps(doc),
        'request'     : request,
        'time_separator' : time_separator,
        'image_url'   : settings.MEDIA_URL + settings.UPLOADED_IMAGES_FOLDER + 'medium/',
        'description' : doc.get('description'),
        'languages'   : supported_languages(),
        'tab_ids'     : prepare_tabs(context['form']),
        'title'       : doc_presentation(context['form'].data,
                                         basedoc = doc),
        'reload_path' : path,
        'user': request.user,
    })

    if context['type'] != 'organisation':
        if type(context['title']) == str:
            context['title'] = context['title'].decode('utf-8')

    if dtype == 'period': # todo: generalize as hook?
        context.update(PeriodWidget.template_params(form = context['form']))

    #print(context)

    context['parents'] = parent_chain(doc, context['form'].data, request.user)
    response = HttpResponse(template_render(template, context))
    response['Cache-Control'] = 'no-store'

    print(context.keys())

    return response