콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
5261 화면

so i want generate an excel, but when i print there is a little problem.

in module_one there have a participant type which is a type are selection.

in wizard_one i have to generate that selection into a string

but when i generate it what i got is selection value not a string

ex : i want Low Levy, what i got low_levy


So i tried to do this

if course.atnd_type_id.type == 'resident':

   course.atnd_type_id.type = 'Resident'

if course.atnd_type_id.type == 'worker_level':

    course.atnd_type_id.type = 'Worker Level'

if course.atnd_type_id.type == 'supervisor_level':

    course.atnd_type_id.type = 'Supervisor Level'

if course.atnd_type_id.type == 'shell':

      course.atnd_type_id.type = 'Shell'

 if course.atnd_type_id.type == 'em':

      course.atnd_type_id.type = 'EM'

 if course.atnd_type_id.type == 'low_levy':

    course.atnd_type_id.type = 'Low Levy'

if course.atnd_type_id.type == 'aop':

    course.atnd_type_id.type = 'AOP'    


what i got  ValueError: Wrong value for course.attendees.type.type: 'Low Levy'

아바타
취소
베스트 답변

Hi Chaanto,

You're getting this error because you're trying to set the value 'Low Levy' into the field of the selection but it doesn't exist. Selections need the key to set the value and not the value. You could get all the values from this selection field though:

selection_values = self._fields['your_selection_field'].selection

Then convert it to a dictionary and from there on you have all values available with both their key and value:

atnd_types = dict(selection_values)

You can then get out the value paired to the key like this:

for key, value in atnd_types.items():
print('key: ' + str(key) + ' value: ' + str(value))

You can find more information about dictionaries and how they work in the Python docs https://docs.python.org/2/tutorial/datastructures.html#dictionaries

Regards,
Yenthe

아바타
취소
작성자

Hi Yenthe Van Ginneken,

Thanks for answering but low levy is exist and i already solve it but. another problem come out

Regards,

Chaanto

관련 게시물 답글 화면 활동
2
4월 19
10043
0
9월 16
3405
1
6월 19
4675
0
12월 15
3190
0
3월 25
1179