예제 #1
0
 def generate():
     # Append the column titles at the beginning
     titles = [csv_encode('date')] + [csv_encode(field.name) for field in form.fields]
     yield writer.writerow(titles)
     for entry in form.entries:
         vals = [csv_encode(entry.created.isoformat())] + [csv_encode(field.value) for field in entry.fields]
         yield writer.writerow(vals)
예제 #2
0
        def generate():
            # Append the column titles at the beginning
            titles = [csv_encode(c[1]) for c in self._export_columns]
            titles[0] = codecs.BOM_UTF8.decode("utf8") + codecs.BOM_UTF8.decode() + titles[0]
            yield writer.writerow(titles)

            for row in data:
                vals = [csv_encode(self.get_export_value(row, c[0]))
                        for c in self._export_columns]
                yield writer.writerow(vals)
예제 #3
0
def generate_vals(writer, export_type, data):
    if export_type == 'general':
        titles = ['email_etudiant']
        titles += ['fra', 'styf', 'master_class', 'joi', 'ambassadeur']
        titles += ['name', 'first_name', 'year', 'specialty', 'school', 'tel']
        titles += ['registered_on', 'transports']
        titles += ['cv']
        yield writer.writerow(titles)
        for row in data:
            vals = []
            vals.append(row.get('id', ''))
            for t in titles[1:5]:
                vals.append(row['events'].get(t, {}).get('registered', False))
            vals.append(bool(row['events']['fra'].get('ambassador')))
            for t in titles[6:12]:
                vals.append(row.get('profile', {}).get(t, ''))
            vals.append(row.get('registered_on'))
            vals.append(row['events']['fra'].get('transports'))
            vals.append(row['profile'].get('resume_id'))
            vals = [csv_encode(v) for v in vals]
            yield writer.writerow(vals)
    else:
        titles = ['id_entreprise', 'valide']
    if export_type == 'equipement':
        titles += [
            'duration', 'equiped', 'banner', 'size', 'emplacement', 'pole'
        ]
        titles += [
            'chaise', 'table', 'banque_hotesse', 'tabouret', 'portemanteau',
            'chauffeuse', u'mange_debout', u'presentoir', u'ecran_32',
            u'ecran_42', u'poste_2', u'poste_3', u'poste_6', u'poste_9'
        ]
        yield writer.writerow(titles)
        for row in data:
            vals = []
            vals.append(row.get('id', ''))
            vals.append(row.get('equipement'))
            for t in titles[2:8]:
                if t in ['emplacement', 'banner']:
                    vals.append(row.get(t, ''))
                else:
                    vals.append(row.get(t, 0))
            for t in titles[8:13]:
                val = row['sections']['furnitures'].get(t, 0)
                if row['equiped']:
                    val += int(find_qty(t, str(row.get('size'))))
                vals.append(val)
            for t in titles[13:]:
                val = row['sections']['furnitures'].get(t, 0)
                vals.append(val)
            vals = [csv_encode(v) for v in vals]
            yield writer.writerow(vals)
    if export_type == 'restauration':
        titles += ['size', 'duration']
        titles += ['mercredi', 'jeudi']
        yield writer.writerow(titles)
        for row in data:
            vals = []
            vals.append(row.get('id', ''))
            vals.append(row.get('restauration'))
            vals.append(row.get('size', ''))
            vals.append(row.get('duration', ''))
            val_wed = row['sections']['catering']['wed'].get('seated', 0)
            val_thu = row['sections']['catering']['thu'].get('seated', 0)
            if row['duration'] in ['wed', 'both']:
                val_wed += nb_dishes(row.get('size'))
            if row['duration'] in ['thu', 'both']:
                val_thu += nb_dishes(row.get('size'))
            vals.append(val_wed)
            vals.append(val_thu)
            vals = [csv_encode(v) for v in vals]
            yield writer.writerow(vals)
    if export_type == 'transport':
        titles += [
            'departure_place', 'arrival_place', 'nb_persons', 'comment',
            'phone', 'departure_time'
        ]
        yield writer.writerow(titles)
        for row in data:
            for t in row['sections']['transports']:
                vals = []
                vals.append(row.get('id', ''))
                vals.append(row.get('transport'))
                for tt in titles[2:]:
                    vals.append(t.get(tt, ''))
                vals = [csv_encode(v) for v in vals]
                yield writer.writerow(vals)
    if export_type == 'badges':
        titles += ['entreprise']
        titles += ['name', 'function', 'days']
        yield writer.writerow(titles)
        for row in data:
            for t in row['sections']['persons']:
                vals = []
                vals.append(row.get('id', ''))
                vals.append(row.get('badges'))
                vals.append(row.get('name', ''))
                for title in titles[3:]:
                    vals.append(t.get(title, ''))
                vals = [csv_encode(v) for v in vals]
                yield writer.writerow(vals)
    if export_type == 'programme':
        titles += ['conference', 'networking', 'webtv']
        yield writer.writerow(titles)
        for row in data:
            vals = []
            vals.append(row.get('id', ''))
            vals.append(row.get('programme'))
            for t in titles[2:]:
                vals.append(row['sections']['events'].get(t, False))
            vals = [csv_encode(v) for v in vals]
            yield writer.writerow(vals)
    if export_type == 'secteurs':
        titles += ['duration', 'emplacement']
        titles += [
            u'name', u'salary', u'city', u'sector', u'revenue', u'country',
            u'enrollment'
        ]
        yield writer.writerow(titles)
        for row in data:
            vals = []
            vals.append(row.get('id', ''))
            vals.append(bool(row.get('info')))
            vals.append(row.get('duration', ''))
            vals.append(row.get('emplacement', ''))
            if row.get('info'):
                for t in titles[2:]:
                    vals.append(row['info'].get(t, ''))
            vals = [csv_encode(v) for v in vals]
            yield writer.writerow(vals)