def oparl_file_downloadUrl_data(params): file_data = db.get_file(deref={'values': ['file']}, search_params={'_id': ObjectId(params['file_id'])}) if len(file_data) == 0: # TODO: Rendere informativere 404 Seite abort(404) file_data = file_data[0] # 'file' property is not set (e.g. due to depublication) if 'file' not in file_data: if 'depublication' in file_data: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) handler = db.get_file_data(file_data['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = file_data['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = file_data['sha1Checksum'] response.headers['Last-modified'] = util.rfc1123date(file_data['file']['uploadDate']) response.headers['Expires'] = util.expires_date(hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age(hours=(24 * 30)) response.headers['Content-Disposition'] = 'attachment; filename=' + file_data['filename'] return response
def attachment_view(attachment_id, extension, savefile=False): """ Abruf/Download eines Attachments """ attachment_info = db.get_attachment(attachment_id) #pprint.pprint(attachment_info) if attachment_info is None: # TODO: Rendere informativere 404 Seite abort(404) # extension doesn't match file extension (avoiding arbitrary URLs) proper_extension = attachment_info['filename'].split('.')[-1] if proper_extension != extension: abort(404) # 'file' property is not set (e.g. due to depublication) if 'file' not in attachment_info: if 'depublication' in attachment_info: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) # handle conditional GET if 'If-Modified-Since' in request.headers: file_date = attachment_info['file']['uploadDate'].replace(tzinfo=None) request_date = util.parse_rfc1123date(request.headers['If-Modified-Since']) difference = file_date - request_date if difference < datetime.timedelta(0, 1): # 1 second return Response(status=304) #if 'if-none-match' in request.headers: # print "Conditional GET: If-None-Match" # TODO: handle ETag in request handler = db.get_file(attachment_info['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = attachment_info['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = attachment_info['sha1'] response.headers['Last-modified'] = util.rfc1123date( attachment_info['file']['uploadDate']) response.headers['Expires'] = util.expires_date( hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age( hours=(24 * 30)) # Save to file option if savefile == True: response.headers['Content-Disposition'] = 'attachment; filename=%s' % attachment_info['filename'] response.headers['X-Robots-Tag'] = 'noindex' # See https://support.google.com/webmasters/answer/139394 response.headers['Link'] = '<%sanhang/%s.%s>; rel="canonical"' % ( app.config['BASE_URL'], attachment_id, extension) return response
def suche_feed(): start_time = time.time() jsonp_callback = request.args.get('callback', None) q = request.args.get('q', '*:*') fq = request.args.get('fq', '') date_param = request.args.get('date', '') region = request.args.get('r', app.config['region_default']) # Suche wird durchgeführt query = db.query_paper(region=region, q=q, fq=fq, sort='publishedDate:desc', start=0, papers_per_page=50, facets=False) # Generate Root and Metainfos search_url = "%s/suche/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region, q, fq) feed_url = "%s/suche/feed/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region, q, fq) root = etree.Element("rss", version="2.0", nsmap={'atom': 'http://www.w3.org/2005/Atom'}) channel = etree.SubElement(root, "channel") etree.SubElement(channel, "title").text = 'Offenes Ratsinformationssystem: Paper-Feed' etree.SubElement(channel, "link").text = search_url etree.SubElement(channel, "language").text = 'de-de' description = u"Neue oder geänderte Dokumente mit dem Suchbegriff %s in %s" % (q, app.config['regions'][region]['name']) # TODO: Einschränkungen mit in die Description if fq: description += '' etree.SubElement(channel, "description").text = description etree.SubElement(channel, '{http://www.w3.org/2005/Atom}link', href=feed_url, rel="self", type="application/rss+xml") # Generate Result Items for paper in query['result']: item = etree.SubElement(channel, "item") paper_link = "%s/paper/%s" % (app.config['base_url'], paper['id']) description = 'Link: ' + paper_link + '</br>' if 'paperType' in paper: description = 'Art des Papers: ' + paper['paperType'] + '<br />' if 'publishedDate' in paper: description += u"Erstellt am: %s<br />" % dateutil.parser.parse(paper['publishedDate']).strftime('%d.%m.%Y') if 'lastModified' in paper: description += u"Zuletzt geändert am: %s<br />" % dateutil.parser.parse(paper['lastModified']).strftime('%d.%m.%Y') etree.SubElement(item, "pubDate").text = util.rfc1123date(paper['lastModified'] if 'lastModified' in paper else datetime.datetime.now()) etree.SubElement(item, "title").text = paper['name'] if 'name' in paper else 'Kein Titel' etree.SubElement(item, "description").text = description etree.SubElement(item, "link").text = paper_link etree.SubElement(item, "guid").text = paper_link response = make_response(etree.tostring(root, pretty_print=True), 200) response.mimetype = 'application/rss+xml' response.headers['Expires'] = util.expires_date(hours=24) response.headers['Cache-Control'] = util.cache_max_age(hours=24) return response
def attachment_download(attachment_id, extension): """ Download eines Attachments """ attachment_info = db.get_attachment(attachment_id) #pprint.pprint(attachment_info) if attachment_info is None: # TODO: Rendere informativere 404 Seite abort(404) # extension doesn't match file extension (avoiding arbitrary URLs) proper_extension = attachment_info['filename'].split('.')[-1] if proper_extension != extension: abort(404) # 'file' property is not set (e.g. due to depublication) if 'file' not in attachment_info: if 'depublication' in attachment_info: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) # handle conditional GET if 'If-Modified-Since' in request.headers: file_date = attachment_info['file']['uploadDate'].replace(tzinfo=None) request_date = util.parse_rfc1123date(request.headers['If-Modified-Since']) difference = file_date - request_date if difference < datetime.timedelta(0, 1): # 1 second return Response(status=304) #if 'if-none-match' in request.headers: # print "Conditional GET: If-None-Match" # TODO: handle ETag in request handler = db.get_file(attachment_info['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = attachment_info['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = attachment_info['sha1'] response.headers['Last-modified'] = util.rfc1123date( attachment_info['file']['uploadDate']) response.headers['Expires'] = util.expires_date( hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age( hours=(24 * 30)) return response
def attachment_download(attachment_id, extension): """ Download eines Attachments """ attachment_info = db.get_attachment(attachment_id) #pprint.pprint(attachment_info) if attachment_info is None: # TODO: Rendere informativere 404 Seite abort(404) # extension doesn't match file extension (avoiding arbitrary URLs) proper_extension = attachment_info['filename'].split('.')[-1] if proper_extension != extension: abort(404) # 'file' property is not set (e.g. due to depublication) if 'file' not in attachment_info: if 'depublication' in attachment_info: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) # handle conditional GET if 'If-Modified-Since' in request.headers: file_date = attachment_info['file']['uploadDate'].replace(tzinfo=None) request_date = util.parse_rfc1123date( request.headers['If-Modified-Since']) difference = file_date - request_date if difference < datetime.timedelta(0, 1): # 1 second return Response(status=304) #if 'if-none-match' in request.headers: # print "Conditional GET: If-None-Match" # TODO: handle ETag in request handler = db.get_file(attachment_info['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = attachment_info['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = attachment_info['sha1'] response.headers['Last-modified'] = util.rfc1123date( attachment_info['file']['uploadDate']) response.headers['Expires'] = util.expires_date(hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age(hours=(24 * 30)) return response
def oparl_file_accessUrl_data(params): file_data = db.get_file(deref={'values': ['file']}, search_params={'_id': ObjectId(params['file_id'])}) if len(file_data) == 0: # TODO: Rendere informativere 404 Seite abort(404) file_data = file_data[0] # extension doesn't match file extension (avoiding arbitrary URLs) #proper_extension = attachment_info['filename'].split('.')[-1] #if proper_extension != extension: # abort(404) # 'file' property is not set (e.g. due to depublication) if 'file' not in file_data: if 'depublication' in file_data: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) # handle conditional GET #if 'If-Modified-Since' in request.headers: # file_date = attachment_info['file']['uploadDate'].replace(tzinfo=None) # request_date = util.parse_rfc1123date(request.headers['If-Modified-Since']) # difference = file_date - request_date # if difference < datetime.timedelta(0, 1): # 1 second # return Response(status=304) #if 'if-none-match' in request.headers: # print "Conditional GET: If-None-Match" # TODO: handle ETag in request handler = db.get_file_data(file_data['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = file_data['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = file_data['sha1Checksum'] response.headers['Last-modified'] = util.rfc1123date(file_data['file']['uploadDate']) response.headers['Expires'] = util.expires_date(hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age(hours=(24 * 30)) return response
def suche_feed(): start_time = time.time() jsonp_callback = request.args.get('callback', None) q = request.args.get('q', '*:*') fq = request.args.get('fq', '') date_param = request.args.get('date', '') region = request.args.get('r', app.config['region_default']) # Suche wird durchgeführt query = db.query_paper(region=region, q=q, fq=fq, sort='publishedDate:desc', start=0, papers_per_page=50, facets=False) # Generate Root and Metainfos search_url = "%s/suche/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region, q, fq) feed_url = "%s/suche/feed/?r=%s&q=%s&fq=%s" % (app.config['base_url'], region, q, fq) root = etree.Element("rss", version="2.0", nsmap={'atom': 'http://www.w3.org/2005/Atom'}) channel = etree.SubElement(root, "channel") etree.SubElement( channel, "title").text = 'Offenes Ratsinformationssystem: Paper-Feed' etree.SubElement(channel, "link").text = search_url etree.SubElement(channel, "language").text = 'de-de' description = u"Neue oder geänderte Dokumente mit dem Suchbegriff %s in %s" % ( q, app.config['regions'][region]['name']) # TODO: Einschränkungen mit in die Description if fq: description += '' etree.SubElement(channel, "description").text = description etree.SubElement(channel, '{http://www.w3.org/2005/Atom}link', href=feed_url, rel="self", type="application/rss+xml") # Generate Result Items for paper in query['result']: item = etree.SubElement(channel, "item") paper_link = "%s/paper/%s" % (app.config['base_url'], paper['id']) description = 'Link: ' + paper_link + '</br>' if 'paperType' in paper: description = 'Art des Papers: ' + paper['paperType'] + '<br />' if 'publishedDate' in paper: description += u"Erstellt am: %s<br />" % dateutil.parser.parse( paper['publishedDate']).strftime('%d.%m.%Y') if 'modified' in paper: description += u"Zuletzt geändert am: %s<br />" % dateutil.parser.parse( paper['modified']).strftime('%d.%m.%Y') etree.SubElement(item, "pubDate").text = util.rfc1123date( paper['modified'] if 'modified' in paper else datetime.datetime.now()) etree.SubElement( item, "title").text = paper['name'] if 'name' in paper else 'Kein Titel' etree.SubElement(item, "description").text = description etree.SubElement(item, "link").text = paper_link etree.SubElement(item, "guid").text = paper_link response = make_response(etree.tostring(root, pretty_print=True), 200) response.mimetype = 'application/rss+xml' response.headers['Expires'] = util.expires_date(hours=24) response.headers['Cache-Control'] = util.cache_max_age(hours=24) return response