def archive(aid, fmt): try: archive = MessageArchive.select().where( MessageArchive.archive_id == aid).get() except MessageArchive.DoesNotExist: return 'Invalid or Expires Archive ID', 404 mime_type = None if fmt == 'json': mime_type == 'application/json' elif fmt == 'txt': mime_type = 'text/plain' elif fmt == 'csv': mime_type = 'text/csv' res = make_response(archive.encode(fmt)) res.headers['Content-Type'] = mime_type return res
def archive(aid, fmt): try: archive = MessageArchive.select().where( (MessageArchive.archive_id == aid) & (MessageArchive.expires_at > datetime.utcnow())).get() except MessageArchive.DoesNotExist: return 'Invalid or Expires Archive ID', 404 mime_type = None if fmt == 'json': mime_type = 'application/json' elif fmt == 'txt': mime_type = 'text/plain' elif fmt == 'csv': mime_type = 'text/csv' if fmt == 'html': return render_template('archive.html') res = make_response(archive.encode(fmt)) res.headers['Content-Type'] = mime_type return res