def export(self, track_id, *args, **kw): user = handler.user.get_user_in_session(request) trac = DBSession.query(Track).filter(Track.id == track_id).first() if not checker.can_download(user, trac): flash("You haven't the right to export any tracks which is not yours") raise redirect('../') data = util.to_datagrid(track_grid, [trac]) tmpl_context.form = track_export kw['track_id'] = track_id return dict(page='tracks', model='Track', info=data, form_title='', value=kw)
def link(self, track_id, *args, **kw): user = handler.user.get_user_in_session(request) trac = DBSession.query(Track).filter(Track.id == track_id).first() if not checker.can_download(user, trac): flash("You haven't the right to download any tracks which is not yours", 'error') raise redirect('/tracks/') track = DBSession.query(Track).filter(Track.id == track_id).first() if track.status == constants.ERROR: flash("The track processing failed. You cannot download it.", 'error') raise redirect('/tracks/') response.content_type = 'application/x-sqlite3' response.headerlist.append(('Content-Disposition', 'attachment;filename=%s.sqlite' % track.name)) return open(track.path).read()
def dump(self, track_id, format, *args, **kw): user = handler.user.get_user_in_session(request) if not checker.can_download(user.id, track_id): flash("You haven't the right to export any tracks which is not yours", 'error') raise redirect('../') _track = DBSession.query(Track).filter(Track.id == track_id).first() if format == 'sqlite': response.content_type = 'application/x-sqlite3' return open(_track.path).read() else: tmp_file = tempfile.NamedTemporaryFile(delete=True) tmp_file.close() track.convert(_track.path, (tmp_file.name, format)) response.content_type = 'text/plain' return open(tmp_file.name).read()