From 384ddeb499d208593c4d44092d8f0c91e4aea503 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Wed, 26 Jul 2017 13:04:37 +0200 Subject: [PATCH] update to new format of cwiczenie wybor --- librarian/pyhtml.py | 31 +++++++--------------- librarian/pypdf.py | 13 +++------ librarian/res/styles/edumed/pdf/edumed.sty | 6 ++++- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/librarian/pyhtml.py b/librarian/pyhtml.py index 38e0829..67793f6 100644 --- a/librarian/pyhtml.py +++ b/librarian/pyhtml.py @@ -427,41 +427,30 @@ class Wybor(Exercise): if not pytania: pytania = [element] for p in pytania: - solutions = re.split(r"[, ]+", p.attrib.get('rozw', '')) + solutions = p.xpath(".//punkt[rozw='prawda']") if len(solutions) != 1: is_single_choice = False break - choices = p.xpath(".//*[@nazwa]") - uniq = set() - for n in choices: - uniq.add(n.attrib.get('nazwa', '')) - if len(choices) != len(uniq): - is_single_choice = False - break self.options = {'single': is_single_choice} return pre, post def handle_punkt(self, element): - if self.options['exercise'] and element.attrib.get('nazwa', None): + if self.options['exercise'] and element.attrib.get('rozw', None): qc = self.question_counter self.piece_counter += 1 no = self.piece_counter eid = "q%(qc)d_%(no)d" % locals() - aname = element.attrib.get('nazwa', None) + sol = element.attrib.get('rozw', None) + params = {'qc': qc, 'no': no, 'sol': sol, 'eid': eid} if self.options['single']: - return u""" -
  • - -
  • " + input_tag = u'' else: - return u""" -
  • - -
  • " - + input_tag = u'' + return (u""" +
  • + """ + input_tag + u""" +
  • " else: return super(Wybor, self).handle_punkt(element) diff --git a/librarian/pypdf.py b/librarian/pypdf.py index 5ba5131..7267b8a 100644 --- a/librarian/pypdf.py +++ b/librarian/pypdf.py @@ -535,24 +535,19 @@ class Wybor(Exercise): if not pytania: pytania = [element] for p in pytania: - solutions = re.split(r"[, ]+", p.attrib.get('rozw', '')) + solutions = p.xpath(".//punkt[rozw='prawda']") if len(solutions) != 1: is_single_choice = False break - choices = p.xpath(".//*[@nazwa]") - uniq = set() - for n in choices: - uniq.add(n.attrib.get('nazwa', '')) - if len(choices) != len(uniq): - is_single_choice = False - break self.options = {'single': is_single_choice} return pre, post def handle_punkt(self, element): - if self.options['exercise'] and element.attrib.get('nazwa', None): + if self.options['exercise'] and element.attrib.get('rozw', None): cmd = 'radio' if self.options['single'] else 'checkbox' + if element.attrib['rozw'] == 'prawda': + cmd += 'checked' return u'' % cmd, '' else: return super(Wybor, self).handle_punkt(element) diff --git a/librarian/res/styles/edumed/pdf/edumed.sty b/librarian/res/styles/edumed/pdf/edumed.sty index 0a18142..b0d7831 100644 --- a/librarian/res/styles/edumed/pdf/edumed.sty +++ b/librarian/res/styles/edumed/pdf/edumed.sty @@ -7,8 +7,12 @@ \newcommand{\activityform}[1]{Forma: #1 \\} \newcommand{\activitytools}[1]{#1 \\} -\newcommand*\checkbox{\item[\Square]} +\newcommand{\checked}{\rlap{$\square$}{\raisebox{2pt}{\large\hspace{1pt}\cmark}} + +\newcommand*\checkbox{\item[\square]} +\newcommand*\checkbox{\item[\checked]} \newcommand*\radio{\item[\Circle]} +\newcommand*\radiochecked{\item[\odot]} \renewcommand{\naglowekrozdzial}[1]{% -- 2.20.1