Пример #1
0
    def insert_table_(self, ar, column_names=None, table_width=180):
        # logger.info("20160330 insert_table(%s)", ar)
        ar.setup_from(self.ar)
        columns, headers, widths = ar.get_field_info(column_names)
        widths = map(int, widths)
        tw = sum(widths)
        # specifying relative widths doesn't seem to work (and that's
        # a pity because absolute widths requires us to know the
        # table_width).
        use_relative_widths = False
        if use_relative_widths:
            width_specs = ["%d*" % (w * 100 / tw) for w in widths]
        else:
            width_specs = ["%dmm" % (table_width * w / tw) for w in widths]

        doc = OpenDocumentText()

        def add_style(**kw):
            st = Style(**cleankw(kw))
            doc.styles.addElement(st)
            self.my_styles.append(st)
            return st

        table_style_name = str(ar.actor)
        st = add_style(name=table_style_name, family="table",
                       parentstylename="Default")
        st.addElement(
            TableProperties(align="margins", maybreakbetweenrows="0"))

        # create some *visible* styles

        st = add_style(name="Table Contents", family="paragraph",
                       parentstylename="Default")
        st.addElement(ParagraphProperties(numberlines="false",
                                          linenumber="0"))

        st = add_style(name="Number Cell", family="paragraph",
                       parentstylename="Table Contents")
        st.addElement(ParagraphProperties(
            numberlines="false",
            textalign="end", justifysingleword="true",
            linenumber="0"))

        dn = "Table Column Header"
        st = self.stylesManager.styles.getStyle(dn)
        if st is None:
            st = add_style(name=dn, family="paragraph",
                           parentstylename="Table Contents")
            st.addElement(
                ParagraphProperties(numberlines="false", linenumber="0"))
            st.addElement(TextProperties(fontweight="bold"))

        dn = "Bold Text"
        st = self.stylesManager.styles.getStyle(dn)
        if st is None:
            st = add_style(name=dn, family="text", parentstylename="Default")
            #~ st = add_style(name=dn, family="text")
            st.addElement(TextProperties(fontweight="bold"))

        if False:
            dn = "L1"
            st = self.stylesManager.styles.getStyle(dn)
            if st is None:
                st = ListStyle(name=dn)
                doc.styles.addElement(st)
                p = ListLevelProperties(
                    listlevelpositionandspacemode="label-alignment")
                st.addElement(p)
                #~ label-followed-by="listtab" text:list-tab-stop-position="1.27cm" fo:text-indent="-0.635cm" fo:margin-left="1.27cm"/>
                p.addElement(ListLevelLabelAlignment(labelfollowedby="listtab",
                                                     listtabstopposition="1.27cm",
                                                     textindent="-0.635cm",
                                                     marginleft="1.27cm"
                                                     ))
                self.my_styles.append(st)

                #~ list_style = add_style(name=dn, family="list")
                bullet = text.ListLevelStyleBullet(
                    level=1, stylename="Bullet_20_Symbols", bulletchar=u"•")
                #~ bullet = text.ListLevelStyleBullet(level=1,stylename="Bullet_20_Symbols",bulletchar=u"*")
                #~ <text:list-level-style-bullet text:level="1" text:style-name="Bullet_20_Symbols" text:bullet-char="•">
                st.addElement(bullet)

        # create some automatic styles

        def add_style(**kw):
            st = Style(**cleankw(kw))
            doc.automaticstyles.addElement(st)
            self.my_automaticstyles.append(st)
            return st

        cell_style = add_style(name="Lino Cell Style", family="table-cell")
        cell_style.addElement(TableCellProperties(
            paddingleft="1mm", paddingright="1mm",
            paddingtop="1mm", paddingbottom="0.5mm",
            border="0.002cm solid #000000"))

        header_row_style = add_style(
            name="Lino Header Row", family="table-row",
            parentstylename=cell_style)
        header_row_style.addElement(
            TableRowProperties(backgroundcolor="#eeeeee"))

        total_row_style = add_style(
            name="Lino Total Row", family="table-row",
            parentstylename=cell_style)
        total_row_style.addElement(
            TableRowProperties(backgroundcolor="#ffffff"))

        table = Table(name=table_style_name, stylename=table_style_name)
        table_columns = TableColumns()
        table.addElement(table_columns)
        table_header_rows = TableHeaderRows()
        table.addElement(table_header_rows)
        table_rows = TableRows()
        table.addElement(table_rows)

        # create table columns and automatic table-column styles
        for i, fld in enumerate(columns):
            #~ print 20120415, repr(fld.name)
            name = str(ar.actor) + "." + str(fld.name)
            cs = add_style(name=name, family="table-column")
            if use_relative_widths:
                cs.addElement(
                    TableColumnProperties(relcolumnwidth=width_specs[i]))
            else:
                cs.addElement(
                    TableColumnProperties(columnwidth=width_specs[i]))
            #~ cs.addElement(TableColumnProperties(useoptimalcolumnwidth='true'))
            #~ k = cs.getAttribute('name')
            #~ renderer.stylesManager.styles[k] = toxml(e)
            #~ doc.automaticstyles.addElement(cs)
            #~ self.my_automaticstyles.append(cs)
            table_columns.addElement(TableColumn(stylename=name))

        def fldstyle(fld):
            #~ if isinstance(fld,ext_store.VirtStoreField):
                #~ fld = fld.delegate
            if isinstance(fld, NumberFieldElement):
                return "Number Cell"
            return "Table Contents"

        def value2cell(ar, i, fld, val, style_name, tc):
            # if i == 0:
            #     logger.info("20160330a value2cell(%s, %s)", fld.__class__, val)
            txt = fld.value2html(ar, val)
            # if i == 0:
            #     logger.info("20160330b value2cell(%s)", E.tostring(txt))

            p = text.P(stylename=style_name)
            html2odf(txt, p)

            try:
                tc.addElement(p)
            except Exception as e:
                dd.logger.warning("20120614 addElement %s %s %r : %s",
                                  i, fld, val, e)
                #~ print 20120614, i, fld, val, e

            #~ yield P(stylename=tablecontents,text=text)

        # create header row
        #~ hr = TableRow(stylename=HEADER_ROW_STYLE_NAME)
        hr = TableRow(stylename=header_row_style)
        table_header_rows.addElement(hr)
        for h in headers:
        #~ for fld in fields:
            #~ tc = TableCell(stylename=CELL_STYLE_NAME)
            tc = TableCell(stylename=cell_style)
            tc.addElement(text.P(
                stylename="Table Column Header",
                #~ text=force_text(fld.field.verbose_name or fld.name)))
                text=force_text(h)))
            hr.addElement(tc)

        sums = [fld.zero for fld in columns]

        for row in ar.data_iterator:
            #~ for grp in ar.group_headers(row):
                #~ raise NotImplementedError()
            tr = TableRow()

            has_numeric_value = False

            for i, fld in enumerate(columns):

                #~ tc = TableCell(stylename=CELL_STYLE_NAME)
                tc = TableCell(stylename=cell_style)
                #~ if fld.field is not None:
                v = fld.field._lino_atomizer.full_value_from_object(row, ar)
                stylename = fldstyle(fld)
                if v is None:
                    tc.addElement(text.P(stylename=stylename, text=''))
                else:
                    value2cell(ar, i, fld, v, stylename, tc)

                    nv = fld.value2num(v)
                    if nv != 0:
                        sums[i] += nv
                        has_numeric_value = True
                    #~ sums[i] += fld.value2num(v)
                tr.addElement(tc)

            if has_numeric_value or not ar.actor.hide_zero_rows:
                table_rows.addElement(tr)

        if not ar.actor.hide_sums:
            if sums != [fld.zero for fld in columns]:
                tr = TableRow(stylename=total_row_style)
                table_rows.addElement(tr)
                sums = {fld.name: sums[i] for i, fld in enumerate(columns)}
                for i, fld in enumerate(columns):
                    tc = TableCell(stylename=cell_style)
                    stylename = fldstyle(fld)
                    p = text.P(stylename=stylename)
                    e = fld.format_sum(ar, sums, i)
                    html2odf(e, p)
                    tc.addElement(p)
                    #~ if len(txt) != 0:
                        #~ msg = "html2odf() returned "
                        #~ logger.warning(msg)
                    #~ txt = tuple(html2odf(fld.format_sum(ar,sums,i),p))
                    #~ assert len(txt) == 1
                    #~ tc.addElement(text.P(stylename=stylename,text=txt[0]))
                    tr.addElement(tc)

        doc.text.addElement(table)
        return toxml(table)
Пример #2
0
    def insert_table_(self,ar,column_names=None,table_width=180):
        ar.setup_from(self.ar)
        columns, headers, widths = ar.get_field_info(column_names)
        widths = map(int,widths)
        tw = sum(widths)
        """
        specifying relative widths doesn't seem to work
        (and that's a pity because absolute widths requires us 
        to know the table_width). 
        """
        use_relative_widths = False
        if use_relative_widths:
            width_specs = ["%d*" % (w*100/tw) for w in widths]
            #~ width_specs = [(w*100/tw) for w in widths]
        else:
            #~ total_width = 180 # suppose table width = 18cm = 180mm
            width_specs = ["%dmm" % (table_width*w/tw) for w in widths]
        #~ else:
            #~ width_specs = []
            #~ for w in widths:
				#~ if w.endswith('%'):
					#~ mm = float(w[:-1]) * table_width / 100
					#~ width_specs.append("%dmm" % mm)
				#~ else:
        #~ print 20120419, width_specs 
        
        doc = OpenDocumentText()
        
        def add_style(**kw):
            st = Style(**kw)
            doc.styles.addElement(st)
            self.my_styles.append(st)
            return st
            

        table_style_name = str(ar.actor)
        st = add_style(name=table_style_name, family="table",parentstylename="Default")
        st.addElement(TableProperties(align="margins", maybreakbetweenrows="0"))
        
        # create some *visible* styles
        
        st = add_style(name="Table Contents", family="paragraph",parentstylename="Default")
        st.addElement(ParagraphProperties(numberlines="false", 
            linenumber="0"))
            
        st = add_style(name="Number Cell", family="paragraph",parentstylename="Table Contents")
        st.addElement(ParagraphProperties(numberlines="false", 
            textalign="end", justifysingleword="true",
            linenumber="0"))
        
        dn = "Table Column Header"
        st = self.stylesManager.styles.getStyle(dn)
        if st is None:
            st = add_style(name=dn, family="paragraph",parentstylename="Table Contents")
            st.addElement(ParagraphProperties(numberlines="false", linenumber="0"))
            st.addElement(TextProperties(fontweight="bold"))
        
        dn = "Bold Text"
        st = self.stylesManager.styles.getStyle(dn)
        if st is None:
            st = add_style(name=dn, family="text",parentstylename="Default")
            #~ st = add_style(name=dn, family="text")
            st.addElement(TextProperties(fontweight="bold"))

        if False:
            dn = "L1"
            st = self.stylesManager.styles.getStyle(dn)
            if st is None:
                st = ListStyle(name=dn)
                doc.styles.addElement(st)
                p = ListLevelProperties(listlevelpositionandspacemode="label-alignment")
                st.addElement(p)
                #~ label-followed-by="listtab" text:list-tab-stop-position="1.27cm" fo:text-indent="-0.635cm" fo:margin-left="1.27cm"/>
                p.addElement(ListLevelLabelAlignment(labelfollowedby="listtab",
                    listtabstopposition="1.27cm",
                    textindent="-0.635cm",
                    marginleft="1.27cm"
                  ))
                self.my_styles.append(st)
                
                #~ list_style = add_style(name=dn, family="list")
                bullet = text.ListLevelStyleBullet(level=1,stylename="Bullet_20_Symbols",bulletchar=u"•")
                #~ bullet = text.ListLevelStyleBullet(level=1,stylename="Bullet_20_Symbols",bulletchar=u"*")
                #~ <text:list-level-style-bullet text:level="1" text:style-name="Bullet_20_Symbols" text:bullet-char="•">
                st.addElement(bullet)
        
        # create some automatic styles
        
        def add_style(**kw):
            st = Style(**kw)
            doc.automaticstyles.addElement(st)
            self.my_automaticstyles.append(st)
            return st
            
        cell_style = add_style(name="Lino Cell Style",family="table-cell")
        cell_style.addElement(TableCellProperties(
            paddingleft="1mm",paddingright="1mm",
            paddingtop="1mm",paddingbottom="0.5mm",
            border="0.002cm solid #000000"))
            
        header_row_style = add_style(name="Lino Header Row",family="table-row",parentstylename=cell_style)
        header_row_style.addElement(TableRowProperties(backgroundcolor="#eeeeee"))
        
        total_row_style = add_style(name="Lino Total Row",family="table-row",parentstylename=cell_style)
        total_row_style.addElement(TableRowProperties(backgroundcolor="#ffffff"))
        
        table = Table(name=table_style_name,stylename=table_style_name)
        table_columns = TableColumns()
        table.addElement(table_columns)
        table_header_rows = TableHeaderRows()
        table.addElement(table_header_rows)
        table_rows = TableRows()
        table.addElement(table_rows)
        
        # create table columns and automatic table-column styles 
        for i,fld in enumerate(columns):
            #~ print 20120415, repr(fld.name)
            name = str(ar.actor)+"."+fld.name
            cs = add_style(name=name, family="table-column")
            if use_relative_widths:
                cs.addElement(TableColumnProperties(relcolumnwidth=width_specs[i]))
            else:
                cs.addElement(TableColumnProperties(columnwidth=width_specs[i]))
            #~ cs.addElement(TableColumnProperties(useoptimalcolumnwidth='true'))
            #~ k = cs.getAttribute('name')
            #~ renderer.stylesManager.styles[k] = toxml(e)
            #~ doc.automaticstyles.addElement(cs)
            #~ self.my_automaticstyles.append(cs)
            table_columns.addElement(TableColumn(stylename=name))
            
        from lino.ui import elems
        def fldstyle(fld):
            #~ if isinstance(fld,ext_store.VirtStoreField):
                #~ fld = fld.delegate
            if isinstance(fld,elems.NumberFieldElement):
                return "Number Cell"
            return "Table Contents"
        
        def value2cell(ar,i,fld,val,style_name,tc):
            #~ text = html2odt.html2odt(fld.value2html(ar,val))
            params = dict()
            #~ if isinstance(fld,ext_store.BooleanStoreField):
                #~ params.update(text=fld.value2html(ar,val))
            #~ else:
                #~ params.update(text=fld.format_value(ar,val))
            #~ params.update(text=fld.format_value(ar,val))
            txt = fld.value2html(ar,val)
            
            p = text.P(stylename=style_name)
            html2odf(txt,p)
            
            try:
                tc.addElement(p)
            except Exception as e:
                logger.warning("20120614 addElement %s %s %r : %s", i, fld, val, e)
                #~ print 20120614, i, fld, val, e
                
            #~ yield P(stylename=tablecontents,text=text)
            
        # create header row
        #~ hr = TableRow(stylename=HEADER_ROW_STYLE_NAME)
        hr = TableRow(stylename=header_row_style)
        table_header_rows.addElement(hr)
        for h in headers:
        #~ for fld in fields:
            #~ tc = TableCell(stylename=CELL_STYLE_NAME)
            tc = TableCell(stylename=cell_style)
            tc.addElement(text.P(
                stylename="Table Column Header",
                #~ text=force_unicode(fld.field.verbose_name or fld.name)))
                text=force_unicode(h)))
            hr.addElement(tc)
            
        sums  = [fld.zero for fld in columns]
          
        for row in ar.data_iterator:
            #~ for grp in ar.group_headers(row):
                #~ raise NotImplementedError()
            tr = TableRow()
            
            has_numeric_value = False
            
            for i,fld in enumerate(columns):
                #~ tc = TableCell(stylename=CELL_STYLE_NAME)
                tc = TableCell(stylename=cell_style)
                #~ if fld.field is not None:
                v = fld.field._lino_atomizer.full_value_from_object(row,ar)
                stylename = fldstyle(fld)
                if v is None:
                    tc.addElement(text.P(stylename=stylename,text=''))
                else:
                    value2cell(ar,i,fld,v,stylename,tc)
                    
                    
                    nv = fld.value2num(v)
                    if nv != 0:
                        sums[i] += nv
                        has_numeric_value = True
                    #~ sums[i] += fld.value2num(v)
                tr.addElement(tc)
            
            if has_numeric_value or not ar.actor.hide_zero_rows:
                table_rows.addElement(tr)
                
        if not ar.actor.hide_sums:
            if sums != [fld.zero for fld in columns]:
                tr = TableRow(stylename=total_row_style)
                table_rows.addElement(tr)
                for i,fld in enumerate(columns):
                    tc = TableCell(stylename=cell_style)
                    stylename = fldstyle(fld)
                    p = text.P(stylename=stylename)
                    e = fld.format_sum(ar,sums,i)
                    html2odf(e,p)
                    tc.addElement(p)
                    #~ if len(txt) != 0: 
                        #~ msg = "html2odf() returned "
                        #~ logger.warning(msg)
                    #~ txt = tuple(html2odf(fld.format_sum(ar,sums,i),p))
                    #~ assert len(txt) == 1
                    #~ tc.addElement(text.P(stylename=stylename,text=txt[0]))
                    tr.addElement(tc)
            

        doc.text.addElement(table)
        return toxml(table)
Пример #3
0
def classe_resultats_odf(request, resultats):
    response = HttpResponse(
        content_type='application/vnd.oasis.opendocument.spreadsheet')
    response[
        'Content-Disposition'] = 'attachment; filename="resultats_{}.ods"'.format(
            resultats['classe'])

    ods = OpenDocumentSpreadsheet()

    # Style numérique pour les notes
    style_number_note = NumberStyle(name="Note")
    ods.styles.addElement(style_number_note)
    Number(parent=style_number_note, minintegerdigits=1, decimalplaces=2)
    style_note = Style(datastylename=style_number_note,
                       parent=ods.styles,
                       name="Note",
                       family='table-cell')

    # Style pour le rang
    style_number_rang = NumberStyle(name="Rang", parent=ods.styles)
    Number(parent=style_number_rang, minintegerdigits=1, decimalplaces=0)
    style_rang = Style(datastylename=style_number_rang,
                       parent=ods.styles,
                       name="Rang",
                       family='table-column')

    for matiere, ens_resultats in resultats['enseignements'].items():
        table = Table(name="{} - {}".format(resultats['classe'], matiere),
                      parent=ods.spreadsheet)

        # Création des colonnes
        table.addElement(TableColumn())  # Étudiant
        table.addElement(TableColumn())  # Moyenne
        table.addElement(TableColumn(stylename=style_rang))  # Rang
        for _ in range(len(resultats['semaines'])):
            table.addElement(TableColumn())

        # Ligne d'en-tête
        th = TableHeaderRows(parent=table)
        tr = TableRow(parent=th)
        P(parent=TableCell(parent=tr, valuetype='string'), text="Étudiant")
        P(parent=TableCell(parent=tr, valuetype='string'), text="Moyenne")
        P(parent=TableCell(parent=tr, valuetype='string'), text="Rang")
        for semaine in resultats['semaines']:
            P(parent=TableCell(parent=tr, valuetype='string'),
              text=semaine.numero)

        # Ligne pour chaque étudiant
        for etudiant, etu_resultats in ens_resultats['etudiants'].items():
            tr = TableRow(parent=table)

            # Nom de l'étudiant
            P(parent=TableCell(parent=tr, valuetype='string'),
              text=str(etudiant))

            # Moyenne de l'étudiant
            P(parent=TableCell(parent=tr,
                               valuetype='float',
                               value=etu_resultats['moyenne'],
                               stylename=style_note),
              text="{:.2f}".format(etu_resultats['moyenne']))

            # Rang de l'étudiant
            P(parent=TableCell(parent=tr,
                               valuetype='float',
                               value=etu_resultats['rang']),
              text="{}".format(etu_resultats['rang']))

            # Notes
            for note in etu_resultats['notes']:
                tc = TableCell(parent=tr)

                if isinstance(note, list) and len(note) == 1:
                    note = note[0]

                if isinstance(note, Note):
                    if note.est_note():
                        tc.setAttribute('valuetype', 'float')
                        tc.setAttribute('value', note.value)
                        tc.setAttribute('stylename', style_note)
                    P(text="{:.2f}".format(note), parent=tc)

                elif isinstance(note, list):
                    P(text=', '.join([
                        "{:.2f}".format(n) for n in note
                        if isinstance(n, Note)
                    ]),
                      parent=tc)

    ods.write(response)
    return response
Пример #4
0
def colloscope_odf(request, classe):
	"""
	Affichage du colloscope d'une classe au format OpenDocument
	"""
	semaines = classe.semaine_set.order_by('debut')
	creneaux = classe.creneau_set.order_by('enseignement', 'jour', 'debut')
	colles = classe.colle_set.filter(semaine__in=semaines,
			creneau__in=creneaux)

	# On crée le dictionnaire qui à chaque créneau puis à chaque semaine
	# associe les groupes de colle
	colloscope = defaultdict(lambda: defaultdict(list))
	for colle in colles:
		colloscope[colle.creneau][colle.semaine].append(colle)

	ods = OpenDocumentSpreadsheet()
	# Styles
	style_entete = Style(parent=ods.automaticstyles,
			name='cell_entete', family='table-cell')
	TextProperties(parent=style_entete, fontweight='bold')
	style_col_semaine = Style(parent=ods.automaticstyles,
			name='col_semaine', family='table-column')
	TableColumnProperties(parent=style_col_semaine, columnwidth='1cm')
	style_col_matiere = Style(parent=ods.automaticstyles,
			name='col_matiere', family='table-column')
	TableColumnProperties(parent=style_col_matiere, columnwidth='5cm')
	style_col_colleur = Style(parent=ods.automaticstyles,
			name='col_colleur', family='table-column')
	TableColumnProperties(parent=style_col_colleur, columnwidth='5cm')
	style_col_salle = Style(parent=ods.automaticstyles,
			name='col_salle', family='table-column')
	TableColumnProperties(parent=style_col_salle, columnwidth='2cm')

	table = Table(name=str(classe), parent=ods.spreadsheet)

	# Ajout des colonnes d'en-tête fixes
	entetes_fixes = ("ID", "Matière", "Colleur", "Jour", "Horaire", "Salle")
	table.addElement(TableColumn(stylename=style_col_semaine)) # ID
	table.addElement(TableColumn(stylename=style_col_matiere)) # Matière
	table.addElement(TableColumn(stylename=style_col_colleur)) # Colleur
	table.addElement(TableColumn()) # Jour
	table.addElement(TableColumn()) # Horaire
	table.addElement(TableColumn(stylename=style_col_salle)) # Salle

	# Ajout des colonnes d'en-tête des semaines
	for _ in semaines:
		table.addElement(TableColumn(stylename=style_col_semaine))

	# Container pour les lignes d'en-tête
	th = TableHeaderRows(parent=table)
	# Ligne d'en-tête avec les semestres au-dessus des semaines
	tr = TableRow(parent=th)
	for entete in entetes_fixes:
		P(parent=TableCell(parent=tr, valuetype='string',
			numberrowsspanned=2, numbercolumnsspanned=1,
			stylename=style_entete), text=entete)

	# On doit savoir combien de semaines se trouvent sur chaque période
	# pour afficher les en-têtes sur le bon nombre de colonnes
	nb_semaines = dict([
		(
			periode[0],
			0,
		)
		for periode in constantes.PERIODE_CHOICES
	])
	for semaine in semaines:
		nb_semaines[semaine.periode] += 1

	# Insertion des titres des périodes
	for periode_id, periode_nom in constantes.PERIODE_CHOICES:
		if nb_semaines[periode_id] > 0:
			P(parent=TableCell(parent=tr, valuetype='string',
				numbercolumnsspanned=nb_semaines[periode_id],
				numberrowsspanned=1,
				stylename=style_entete), text=periode_nom.capitalize())
			CoveredTableCell(parent=tr,
					numbercolumnsrepeated=nb_semaines[periode_id] - 1)

	tr = TableRow(parent=th)
	# Ligne d'en-tête avec seulement les semaines
	# On doit placer des cellules vides pour les case d'en-tête situées
	# avant les semaines
	CoveredTableCell(parent=tr, numbercolumnsrepeated=len(entetes_fixes))
	# Puis on ajoute les semaines
	for semaine in semaines:
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text=semaine.numero)

	# Colles par créneau
	for creneau in creneaux:
		tr = TableRow(parent=table)
		P(parent=TableCell(parent=tr, valuetype='float', value=creneau.pk),
			text=creneau.pk)
		P(parent=TableCell(parent=tr, valuetype='string'),
				text=creneau.matiere)
		P(parent=TableCell(parent=tr, valuetype='string'),
				text=creneau.colleur)
		P(parent=TableCell(parent=tr, valuetype='string'),
				text=creneau.get_jour_display())
		P(parent=TableCell(parent=tr, valuetype='time',
				timevalue=creneau.debut.strftime("PT%HH%MM%SS")),
				text=creneau.debut.strftime("%H:%M"))
		P(parent=TableCell(parent=tr, valuetype='string'),
				text=creneau.salle)
		for semaine in semaines:
			groupes_texte = ','.join([str(c.groupe) for c in
					colloscope[creneau][semaine] if c.groupe])
			cell = TableCell(parent=tr)
			if groupes_texte:
				cell.valuetype="string"
				P(parent=cell, text=groupes_texte)

	return OdfResponse(ods, filename="colloscope_{}.ods".format(classe.slug))
Пример #5
0
	def get(self, request, queryset, annee=None):
		creneaux_ods = OpenDocumentSpreadsheet()

		# Styles
		style_entete = Style(parent=creneaux_ods.automaticstyles,
				name='cell_entete', family='table-cell')
		TextProperties(parent=style_entete, fontweight='bold')
		style_col_colleur = Style(parent=creneaux_ods.automaticstyles,
				name='col_colleur', family='table-column')
		TableColumnProperties(parent=style_col_colleur, columnwidth='5cm')
		style_col_matiere = Style(parent=creneaux_ods.automaticstyles,
				name='col_matiere', family='table-column')
		TableColumnProperties(parent=style_col_matiere, columnwidth='5cm')
		style_col_standard = Style(parent=creneaux_ods.automaticstyles,
				name='col_standard', family='table-column')
		TableColumnProperties(parent=style_col_standard, columnwidth='2cm')

		table = Table(name="Créneaux de colles",
				parent=creneaux_ods.spreadsheet)

		# Définition des colonnes
		table.addElement(TableColumn(stylename=style_col_colleur)) # Colleur
		table.addElement(TableColumn(stylename=style_col_standard)) # Classe
		table.addElement(TableColumn(stylename=style_col_matiere)) # Matière
		table.addElement(TableColumn(stylename=style_col_standard)) # Jour
		table.addElement(TableColumn(stylename=style_col_standard)) # Début
		table.addElement(TableColumn(stylename=style_col_standard)) # Fin
		table.addElement(TableColumn(stylename=style_col_standard)) # Salle

		# En-tête de tableau
		# Container pour les lignes d'en-tête
		th = TableHeaderRows(parent=table)
		# Ligne d'en-tête
		tr = TableRow(parent=th)
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Colleur")
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Classe")
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Matière")
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Jour")
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Début")
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Fin")
		P(parent=TableCell(parent=tr, valuetype='string',
			stylename=style_entete), text="Salle")

		for creneau in queryset:
			tr = TableRow(parent=table)
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.colleur))
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.classe))
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.matiere))
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.get_jour_display()))
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.debut))
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.fin))
			P(parent=TableCell(parent=tr, valuetype='string'), text=str(creneau.salle))

		return OdfResponse(creneaux_ods,
			filename="creneaux-{annee}.ods".format(annee=annee))