mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-13 07:29:39 +00:00
Add REST API handlers
This commit is contained in:
parent
cdb9608f31
commit
7b764447ac
@ -2,6 +2,8 @@ from indico.core import signals
|
||||
from indico.core.plugins import IndicoPlugin, IndicoPluginBlueprint
|
||||
from MaKaC.webinterface.pages.conferences import WPConfModifScheduleGraphic
|
||||
|
||||
from .controllers import RHDataImport, RHGetImporters
|
||||
|
||||
|
||||
class ImporterPlugin(IndicoPlugin):
|
||||
"""Importer plugin
|
||||
@ -15,9 +17,10 @@ class ImporterPlugin(IndicoPlugin):
|
||||
self.inject_js('importer_js', WPConfModifScheduleGraphic)
|
||||
self.inject_css('importer_css', WPConfModifScheduleGraphic)
|
||||
self.connect(signals.timetable_buttons, self.get_timetable_buttons)
|
||||
self.importers = {}
|
||||
|
||||
def get_blueprints(self):
|
||||
return IndicoPluginBlueprint('importer', __name__)
|
||||
return blueprint
|
||||
|
||||
def get_timetable_buttons(self, *args, **kwargs):
|
||||
yield ('Importer', 'createImporterDialog')
|
||||
@ -25,3 +28,8 @@ class ImporterPlugin(IndicoPlugin):
|
||||
def register_assets(self):
|
||||
self.register_js_bundle('importer_js', 'js/importer.js')
|
||||
self.register_css_bundle('importer_css', 'css/importer.css')
|
||||
|
||||
|
||||
blueprint = IndicoPluginBlueprint('importer', __name__)
|
||||
blueprint.add_url_rule('/import/<importer_name>', 'import', RHDataImport, methods=('GET', 'POST'))
|
||||
blueprint.add_url_rule('/importers', 'importers', RHGetImporters, methods=('GET', 'POST'))
|
||||
|
||||
29
importer/indico_importer/controllers.py
Normal file
29
importer/indico_importer/controllers.py
Normal file
@ -0,0 +1,29 @@
|
||||
from flask import jsonify
|
||||
from flask_pluginengine import current_plugin
|
||||
|
||||
from MaKaC.webinterface.rh.base import RHProtected
|
||||
|
||||
|
||||
class RHDataImport(RHProtected):
|
||||
"""
|
||||
Fetches data from the specified importer plugin.
|
||||
Arguments:
|
||||
importer - name of an importer plugin being used
|
||||
query - string used in importer's search phrase
|
||||
size - number of returned queries
|
||||
"""
|
||||
def process(self, params):
|
||||
importer = current_plugin.importers.get(params['importer_name'])
|
||||
if not importer:
|
||||
return 'No such importer available'
|
||||
query = params.get('query')
|
||||
size = params.get('size', 10)
|
||||
return importer.import_data(query, size)
|
||||
|
||||
|
||||
class RHGetImporters(RHProtected):
|
||||
def process(self, params):
|
||||
importers = {}
|
||||
for importer in current_plugin.importers.itervalues():
|
||||
importers[importer.id] = importer.name
|
||||
return jsonify(importers)
|
||||
Loading…
x
Reference in New Issue
Block a user