7.3-7.5 JLL实习日志-实现DropDownBox的功能

来源:互联网 发布:淘宝自动发号软件 编辑:程序博客网 时间:2024/06/06 03:12

改动下拉框,没有实现这个功能,需要从view 端进行取数据得到新的
重点关注以下这两个函数怎么实现interface 的!

'''def getLabelSetting(request):    setting = settings(request)    return setting['label_setting']def formFieldLocalisation(Form, request):        label_setting_instance = getLabelSetting(request)    for field in Form:        tag_value = field.label        if not containsAny(tag_value, " "):                field.label = label_setting_instance[tag_value]    return Form

if selection:
for options:
option_label = option.label
option.label = label_setting_instance[option_label]


注意理解
default_label_setting=localisation.data_model_label_interface 为什么改成别的localisation.data_model_label_cn 会报错!


实现一个功能,但是怎么去实现改变form端里面的值呢?使用的标签有很多,现在不知道我在拿到form以后怎么取到<selection>里面的值并且保留这个变化呢???
  

def formDropDownBoxlocalisation(Form,request):    label_setting_instance =getLabelSetting(request)    print label_setting_instance.get('Map')    for field in Form:        print 'field.label',field.label,field.label_tag,'1',field.id_for_label,'2',field.html_name        #if field =     #print '2,',Form.fields    #a= list(Form.fields['property_form_type_choice'].choices)    reason = Form.fields['property_form_type_choice'].choices[0].get()    print 'reason',reason    reason = dict(Form.fields['property_form_type_choice'].choices)    print reason    for i in reason:        value = label_setting_instance.get(i)        Form.fields['property_form_type_choice'].choices[0].get(i)=label_setting_instance.get(i)            if j[0] ==        print i,label_setting_instance.get(i)        for j in Form.fields['property_form_type_choice'].choices:            if j.key == i        #print 'label_setting_instance',label_setting_instance[i]        #print 'reason[i]',reason[i]        #reason[i]= label_setting_instance.get(i)        Form.fields['property_form_type_choice'].choices.get(i) = label_setting_instance.get(i)    print Form    return Form

函数的完整版代码如下
第一步:label_setting_instance =getLabelSetting(request) 根据request里面的值获得对应的locasation.py的label_setting_instance 这个对象是一个dict类型的,所以取元素的时候,通过get的方式去拿label_setting_instance.get(i)
第二步:实现Form.fields['property_form_type_choice'].choices 获得是一个tuple类型的,从form里面取到名为property_form_type_choice的field的值,因为是一个下拉框,所以有choices的选项的,
第三步:怎么实现这个保存的功能呢? 我现在可以实现改动但是没有实现保存的效果,改完以后还是不会变化,我觉得还是我对于field.label,field.value,field.

def formDropDownBoxlocalisation(Form,request):    label_setting_instance =getLabelSetting(request)    reason = dict(Form.fields['property_form_type_choice'].choices)    print reason    for i in reason:        print i        value = label_setting_instance.get(i)        print value        #Form.fields['property_form_type_choice'].choices[0]=label_setting_instance.get(i)    print '1',Form.choice_type_object    return Form

总结:这个功能应该是碰到的最难理解的了,我一开始的时候没有办法去理解怎么通过view 端的formDropDownBoxlocalisation传过来的request,form两个参数改变form的值!

原创粉丝点击