def notify_role(role, subject, html): if role.email is None: log.error("Role does not have E-Mail: %r", role) return sender = '%s <%s>' % (get_app_title(), get_config('MAIL_FROM')) subject = '[%s] %s' % (get_app_title(), subject) msg = Message(subject=subject, sender=sender, recipients=[role.email]) msg.html = html mail.send(msg)
def metadata(): enable_cache(server_side=False) schemata = {} for schema_id, schema in resolver.store.items(): if not schema_id.endswith('#'): schema_id = schema_id + '#' schemata[schema_id] = { 'id': schema_id, 'title': schema.get('title'), 'faIcon': schema.get('faIcon'), 'plural': schema.get('plural', schema.get('title')), 'description': schema.get('description'), 'inline': schema.get('inline', False) } return jsonify({ 'status': 'ok', 'app': { 'title': get_app_title(), 'url': get_app_url(), 'samples': get_config('SAMPLE_SEARCHES') }, 'fields': Metadata.facets(), 'categories': Collection.CATEGORIES, 'countries': COUNTRY_NAMES, 'languages': LANGUAGE_NAMES, 'schemata': schemata })
def reconcile_index(): domain = get_app_url().strip('/') api_key = request.auth_role.api_key if authz.logged_in() else None preview_uri = entity_link('{{id}}') + '&preview=true&api_key=%s' % api_key meta = { 'name': get_app_title(), 'identifierSpace': 'http://rdf.freebase.com/ns/type.object.id', 'schemaSpace': 'http://rdf.freebase.com/ns/type.object.id', 'view': {'url': entity_link('{{id}}')}, 'preview': { 'url': preview_uri, 'width': 600, 'height': 300 }, 'suggest': { 'entity': { 'service_url': domain, 'service_path': url_for('reconcile_api.suggest_entity', api_key=api_key) }, 'type': { 'service_url': domain, 'service_path': url_for('reconcile_api.suggest_type') }, 'property': { 'service_url': domain, 'service_path': url_for('reconcile_api.suggest_property') } }, 'defaultTypes': [{ 'id': DEFAULT_TYPE, 'name': 'Persons and Companies' }] } return jsonify(meta)
def check_role_alerts(role): alerts = Alert.by_role(role).all() if not len(alerts): return log.info('Alerting %r, %d alerts...', role, len(alerts)) for alert in alerts: results = alert_query(alert) if results['total'] == 0: continue log.info('Found: %d new results for: %r', results['total'], alert.label) alert.update() try: subject = '%s (%s new results)' % (alert.label, results['total']) html = render_template('alert.html', alert=alert, results=results, role=role, qs=make_document_query(alert), app_title=get_app_title(), app_url=get_app_url()) notify_role(role, subject, html) except Exception as ex: log.exception(ex) db.session.commit()