]> git.siccegge.de Git - teilnehmertool.git/blobdiff - teilnehmertool.py
topdf.sh
[teilnehmertool.git] / teilnehmertool.py
index a1530c6a8e1433e6b676e1d432c74a3915ac0880..bda2774fca2b67cbb68fb005d20a52dccc73e286 100755 (executable)
@@ -9,12 +9,34 @@ import string
 import jinja2
 import os
 import os.path
+import re
+import sys
 
 conn = None
 
 
 env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates', encoding='utf-8'))
 
+
+## jinja2 TeX espaping from http://flask.pocoo.org/snippets/55/
+LATEX_SUBS = [
+    (re.compile(r'\\'), r'\\textbackslash'),
+    (re.compile(r'([{}_#%&$])'), r'\\\1'),
+    (re.compile(r'~'), r'\~{}'),
+    (re.compile(r'\^'), r'\^{}'),
+    (re.compile(r'"'), r"''"),
+    (re.compile(r'\.\.\.+'), r'\\ldots'),
+]
+
+def escape_tex(value):
+    newval = value
+    for pattern, replacement in LATEX_SUBS:
+        newval = pattern.sub(replacement, newval)
+    return newval
+
+env.filters['escape_tex'] = escape_tex
+
+
 def import_teilnehmer(input):
     ids = set([ i[0] for i in conn.execute('SELECT id FROM teilnehmer').fetchall() ])
 
@@ -25,8 +47,8 @@ def import_teilnehmer(input):
                 continue
             if not int(row[0]) in ids:
                 print "Importing %s" % (row, )
-                conn.execute("INSERT INTO teilnehmer VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
-                             row + [0, 0, 0])
+                conn.execute("INSERT INTO teilnehmer VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+                             row[:-2] + ['Kein T-Shirt', 'Kein Pulli'] + row[-2:] + [0, 0, 0, "", "false"])
 
     conn.commit()
 
@@ -129,18 +151,63 @@ def create_remind(outdir='output'):
                                                                                       preis, id])
     conn.commit()
 
+
 def create_nametag(outdir='output'):
     template = env.get_template('nametag.svg')
 
-    for vorname, nachname, namensschild, hochschule in \
-        conn.execute("SELECT vorname, nachname, namensschild, hochschule FROM teilnehmer"):
+    for teiln_id, vorname, nachname, namensschild, hochschule, dochned in \
+        conn.execute("SELECT id, vorname, nachname, namensschild, hochschule, dochned FROM teilnehmer"):
+
+        if dochned != "false":
+            print >> sys.stderr, "not generating %s %s (id %s), because abgemeldet" % (vorname, nachname, teiln_id)
+            continue
 
-        with open(os.path.join(outdir, "%s.svg" % namensschild), 'w') as f:
+        with open(os.path.join(outdir, "%s.svg" % teiln_id), 'w') as f:
             f.write(template.render(name=u"%s %s" % (vorname.decode('utf-8'),
                                                      nachname.decode('utf-8')),
                                     nick=namensschild.decode('utf-8'),
                                     uni1=hochschule.decode('utf-8')).encode('utf-8'))
 
+
+def create_teilnehmer_list(outdir = 'output'):
+    template = env.get_template('teilnehmerliste.tex')
+
+    teilnehmer = []
+    for vor, nach, nick, hochschule, betrag, bezahlt, shirtsize, zippersize, dochned, comment in \
+        conn.execute("SELECT vorname, nachname, namensschild, hochschule, betrag, bezahlt, tshirt, zipper, dochned, orga_comment FROM teilnehmer ORDER BY UPPER(nachname) ASC"):
+
+        vor = vor.decode('utf8')
+        nach = nach.decode('utf8')
+        nick = nick.decode('utf8')
+        hochschule = hochschule.decode('utf8')
+        ## betrag ist schon int
+        ## bezahlt ist schon int
+        shirtsize = shirtsize.decode('utf8')
+        if re.match("kein", shirtsize, flags=re.IGNORECASE):
+            shirtsize = ""
+
+        zippersize = zippersize.decode('utf8')
+        if re.match("kein", zippersize, flags=re.IGNORECASE):
+            zippersize = ""
+
+        ## string to bool..
+        if dochned == "false":
+            will_attend = True
+        else:
+            will_attend = False
+        comment = comment.decode('utf8')
+
+        teilnehmer.append({'vorname': vor, 'nachname': nach,
+            'hochschule': hochschule, 'nick': nick, 'betrag': betrag, 'bezahlt':
+            bezahlt, 'shirtsize': shirtsize, 'zippersize': zippersize,
+            'will_attend': will_attend, 'comment': comment})
+
+
+    with open(os.path.join(outdir, "teilnehmerliste.tex"), 'w') as out:
+        out.write(template.render(teilnehmer=teilnehmer).encode('utf-8'))
+
+
+
 def create_bmbf_list(outdir = 'output'):
     template = env.get_template('bmbf-unterschriftenliste.tex')
 
@@ -148,7 +215,7 @@ def create_bmbf_list(outdir = 'output'):
     teilnehmer = []
     i = 1
     for vor, nach, hochschule in \
-        conn.execute("SELECT vorname, nachname, hochschule FROM teilnehmer ORDER BY nachname DESC"):
+        conn.execute("SELECT vorname, nachname, hochschule FROM teilnehmer ORDER BY UPPER(nachname) ASC"):
 
         vor = vor.decode('utf8')
         nach = nach.decode('utf8')
@@ -179,6 +246,8 @@ def main():
                        help='Generiere Zahlungsaufforderungserinnerung')
     group.add_argument('--bmbf', action='store_true',
                        help='Generiere BMBF-Unterschriftenliste')
+    group.add_argument('--liste', action='store_true',
+                       help='Generiere Teilnehmerübersichtsliste')
 
     # Argumente
     parser.add_argument('--db', default='teilnehmer.sqlite',
@@ -196,7 +265,7 @@ def main():
     conn.row_factory = sqlite3.Row
     conn.execute('pragma encoding = "UTF-8";')
 
-    if args.nametag or args.email or args.pay or args.remind or args.bmbf:
+    if args.nametag or args.email or args.pay or args.remind or args.bmbf or args.liste:
         assert(args.output)
         if not os.path.exists(args.output):
             os.mkdir(args.output)
@@ -211,6 +280,8 @@ def main():
             create_remind(args.output)
         elif args.bmbf:
             create_bmbf_list(args.output)
+        elif args.liste:
+            create_teilnehmer_list(args.output)
 
     elif args.importcsv:
         assert(args.input)