]>
git.siccegge.de Git - fachschaftentool.git/blob - application.py
2 # -*- coding: utf-8 -*-
9 from flask
import Flask
, session
, redirect
, url_for
, escape
, request
, render_template
, g
, make_response
13 DATABASE
= os
.path
.join(os
.path
.dirname(__file__
), '..', 'data', 'fachschaften.sqlite')
14 #DATABASE = os.path.join(os.path.dirname(__file__), 'fachschaften.sqlite')
17 db
= sqlite3
.connect(DATABASE
)
18 db
.row_factory
= sqlite3
.Row
25 fachschaften
= cursor
.execute("SELECT * from fachschaft")
26 return render_template('index.html', fachschaften
=fachschaften
)
28 @app.route('/show/<int:id>/')
32 fachschaft
= cursor
.execute("SELECT * from fachschaft WHERE rowid = ?", [id]).fetchone()
33 studiengang
= cursor
.execute("SELECT * from studiengang WHERE fachschaft = ?", [fachschaft
['rowid']]).fetchall()
34 return render_template('show.html', fachschaft
=fachschaft
, studiengaenge
=studiengang
)
38 return render_template('add.html')
40 @app.route('/addp/', methods
=['POST'])
46 cursor
.execute("INSERT INTO fachschaft "
47 "(langname, kurzname, land, stadt, studenten, "
48 "organ, vertreten, organisation, fachschaftler, homepage) "
49 "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
56 data
['vertretenestudis'],
57 data
['organisationsform'],
60 rowid
= cursor
.lastrowid
61 for i
in range(0, 10):
62 if data
['studiengang%d' % i
] != '':
63 cursor
.execute("INSERT INTO studiengang "
64 "(fachschaft, name, anf_dieses, anf_vorjahr) "
65 "VALUES (?, ?, ?, ?)",
67 data
['studiengang%d' % i
],
68 data
['anfaenger%d' % i
],
69 data
['vorjahr%d' % i
]])
71 return redirect(url_for('show', id = rowid
))
73 @app.route('/download/')
78 data
= StringIO
.StringIO()
79 tar
= tarfile
.TarFile(mode
='w', fileobj
=data
)
80 for fachschaft
in cursor
.execute("SELECT * from fachschaft").fetchall():
81 studiengaenge
= cursor
.execute("SELECT * from studiengang WHERE fachschaft = ?", [fachschaft
['rowid']]).fetchall()
82 fdata
= render_template('fachschaft.tex',
83 fachschaft
= fachschaft
,
84 studiengaenge
= studiengaenge
)
85 fdata
= fdata
.encode('utf-8')
86 filename
= '%s_%s.tex' % (fachschaft
['kurzname'].strip().lower().replace(' ', '_').replace('/','_').replace(u
'ä', 'ae').replace(u
'ü', 'ue').replace(u
'ö', 'oe'),
88 info
= tarfile
.TarInfo(name
='fachschaften/%s' % filename
)
89 info
.size
= len(fdata
)
90 tar
.addfile(info
, StringIO
.StringIO(fdata
))
91 universities
.append(filename
)
94 fdata
= ('\n'.join(['\input{fachschaften/%s}' % (u
) for u
in universities
])).encode('utf-8')
95 info
= tarfile
.TarInfo(name
='liste.tex')
96 info
.size
= len(fdata
)
97 tar
.addfile(info
, StringIO
.StringIO(fdata
))
100 fdata
= file(os
.path
.join(os
.path
.dirname(__file__
), 'templates', 'master.tex')).read()
101 info
= tarfile
.TarInfo(name
='master.tex')
102 info
.size
= len(fdata
)
103 tar
.addfile(info
, StringIO
.StringIO(fdata
))
106 fdata
= file(os
.path
.join(os
.path
.dirname(__file__
), 'templates', 'kiflogo.pdf')).read()
107 info
= tarfile
.TarInfo(name
='kiflogo.pdf')
108 info
.size
= len(fdata
)
109 tar
.addfile(info
, StringIO
.StringIO(fdata
))
112 for elem
in os
.listdir(os
.path
.join(os
.path
.dirname(__file__
), 'templates', 'beamertheme')):
113 fdata
= file(os
.path
.join(os
.path
.dirname(__file__
), 'templates', 'beamertheme', elem
)).read()
114 info
= tarfile
.TarInfo(name
=elem
)
115 info
.size
= len(fdata
)
116 tar
.addfile(info
, StringIO
.StringIO(fdata
))
120 responseobj
=make_response(data
.getvalue())
121 responseobj
.mimetype
="application/x-tar"
124 if __name__
== '__main__':