View Issue Details

This bug affects 1 person(s).
 2
IDProjectCategoryView StatusLast Update
19148Bug reportsRemoteControlpublic2023-10-09 18:50
ReporterSESSOU Assigned To 
PrioritynoneSeverityminor 
Status acknowledgedResolutionopen 
Product Version5.6.x 
Summary19148: Accent problem when generating row answers by remote control for a single choice question (radio or menu)
Description

Hi,

One of our users uses remotecontrol API to generate a single choice question (with radio button or menu presentation) in a particular group of a form. We are in French language.

All seems to be OK (the text of the question and the help text are OK) except the accents of the row answers which are not well decoded and remain in a HTML encoding (HTML entity format) syntax through the Limesurvey admin web interface (please see screen capture attached to this ticket).

Tank you for your help ...

O.L.

Steps To Reproduce

Here is a sample of the python script used to generate the question via remotecontrol ...

class C_Question:
"""
Classe C_Question minimale
"""

listFields = []
sid = 0
qid = 0

def __init__(self, sid, gid, type, code, help, intitule, other='N', default="", mandatory="Y"):
    """
    Constructeur de la classe

    :param sid: id du questionnaire
    :param gid: id du groupe de question
    :param type: type de question 
    :param code: code de la question dans LS
    :param help: texte d'aide
    :param intitule: intiulé de la question
    """
    print("\t Création question ",code)
    self.sid = sid
    self.qid = 1
    self.gid = gid
    self.parent_qid = 0
    self.type = type
    self.help = help
    self.code = code
    self.other = other
    self.default=default
    self.mandatory=mandatory
    self.intitule = intitule
    self.fields_list = ['qid', 'sid', 'gid', 'type', 'title',
                        'question', 'preg', 'help', 'other',
                        'mandatory', 'encrypted', 'question_order', 'language',
                        'parent_qid', 'scale_id', 'same_default',
                        'relevance','defaultvalues', 'modulename']
    self.intitule = intitule
    self.questions = None
    self.attributes=None
    self.subquestions = None
    self.answers = None
    self.rows = None

    self.document = ET.Element('document')
    ET.SubElement(self.document, 'LimeSurveyDocType').text = 'Question'
    ET.SubElement(self.document, 'DBVersion').text = '263'
    lang = ET.SubElement(self.document, 'languages')
    ET.SubElement(lang, 'language').text = 'fr'
    self.questions = ET.SubElement(self.document, 'questions')
    self.questions.append(self.createFields())
    self.addQuestionsRows(self.code, self.help, self.intitule)

def setFieldsList(self, list):
    self.field_list = list

def createFields(self):
    """
    Créé un élément XML fields à partir d'une liste de champs
    Cet item fields contient tous les fieldname fournis dans la liste

    :param list_fields: listfields = Tableau des différents champs
           field à ajouter
    :type  list_fields: Array
    :return: Retourne un élément de type fields
    :rtype: ET.Element
    """

    fields = ET.Element('fields')
    for field in self.fields_list:
        ET.SubElement(fields, 'fieldname').text = field
    return fields

def addQuestionsRows(self, title, help, intitule):
    rows = ET.Element('rows')
    row = ET.SubElement(rows, 'row')
    ET.SubElement(row, 'qid').text = ET.CDATA(str(self.qid))
    ET.SubElement(row, 'sid').text = ET.CDATA(self.sid)
    ET.SubElement(row, 'gid').text = ET.CDATA(self.gid)
    ET.SubElement(row, 'type').text = ET.CDATA(self.type)
    ET.SubElement(row, 'title').text = ET.CDATA(title)
    ET.SubElement(row, 'question').text = ET.CDATA(intitule)
    ET.SubElement(row, 'preg')
    ET.SubElement(row, 'help').text = ET.CDATA(help)
    ET.SubElement(row, 'other').text = ET.CDATA(self.other)
    ET.SubElement(row, 'mandatory').text = ET.CDATA(self.mandatory)
    ET.SubElement(row, 'encrypted').text = ET.CDATA('N')
    ET.SubElement(row, 'question_order').text = ET.CDATA('1')
    ET.SubElement(row, 'language').text = ET.CDATA('fr')
    ET.SubElement(row, 'parent_qid').text = ET.CDATA('0')
    ET.SubElement(row, 'scale_id').text = ET.CDATA('0')
    ET.SubElement(row, 'same_default').text = ET.CDATA('0')
    ET.SubElement(row, 'relevance').text = ET.CDATA('1')
    ET.SubElement(row, 'defaultvalues').text = ET.CDATA(self.default)
    ET.SubElement(row, 'modulename')
    self.rows = rows
    self.questions.append(rows)

def post(self, mandatory='Y'):
    root = ET.ElementTree(self.document)
    chaine = ET.tostring(self.document)
    encoded = base64.b64encode(chaine)
    res = send('import_question', [token, sid, gid, encoded.decode('utf-8'), 'lsq', mandatory])
    self.qid = res.json()['result']

class C_Question_Liste(C_Question):
"""
Classe C_Question par défaut de type ! (menu déroulant) ou L (Bouton radio)
"""

def __init__(self, sid, gid, typeQ, code, help, intitule, answersList, other='N', default="", mandatory="Y"):
    super().__init__(sid, gid, typeQ, code, help, intitule, other, default, mandatory)
    self.answers = None
    self.answersList = answersList
    self.fields_list = ['qid', 'code', 'answer',
                        'assessment_value', 'sortorder', 'language', 'scale_id']
    self.addAnswersRows(self.qid)

def addAnswersRows(self, qid):
    subQuestions = ET.SubElement(self.document, 'answers')
    subQuestions.append(self.createFields())
    rows = ET.Element('rows')
    intqid = 1
    for elt in self.answersList:
        intqid = intqid+1
        row = ET.SubElement(rows, 'row')
        ET.SubElement(row, 'qid').text = ET.CDATA(str(self.qid))
        ET.SubElement(row, 'code').text = ET.CDATA("A"+str(intqid-1))
        ET.SubElement(row, 'answer').text = ET.CDATA(elt)
        ET.SubElement(row, 'assessment_value').text = ET.CDATA('0')
        ET.SubElement(row, 'sortorder').text = ET.CDATA(str(intqid-1))
        ET.SubElement(row, 'language').text = ET.CDATA('fr')
        ET.SubElement(row, 'scale_id').text = ET.CDATA('0')
    self.answers = rows
    subQuestions.append(self.answers)

############################################################################
#

Programme principal

#
############################################################################

token = init_session_key()

boutonRadio=C_Question_Liste(str(sid), str(gid), 'L',
'qBouton',
'Quel est le type de votre structure d\'appartenance ?',
'Type de structure',
['UFR, institut ou école', 'Laboratoire',
'Service'])
boutonRadio.post()

TagsNo tags attached.
Attached Files
Bug heat2
Complete LimeSurvey version number (& build)5.6.39+230926
I will donate to the project if issue is resolvedNo
BrowserFirefox 118.0.1
Database type & versionPostgresql 13
Server OS (if known)Debian 11.7
Webserver software & version (if known)Apache 2.4
PHP Version7.4.33

Users monitoring this issue

There are no users monitoring this issue.

Activities

gabrieljenik

gabrieljenik

2023-10-09 18:50

manager   ~77588

Sorry, as to clarify, can you please express this in a more Requst by request way?
Ex:

  • Did this API request, with this params.
  • Got this.

That way we will have a more clear case as well as to make sure the bug is not on the python code.

Issue History

Date Modified Username Field Change
2023-10-03 11:05 SESSOU New Issue
2023-10-03 11:05 SESSOU File Added: Capture d’écran 2023-10-03 à 11.03.49.png
2023-10-09 18:50 gabrieljenik Note Added: 77588
2023-10-09 18:50 gabrieljenik Bug heat 0 => 2
2023-10-09 18:50 gabrieljenik Status new => acknowledged