changeset 11:69ecfe51d585

Dodałem prosty prototyp API
author Michał Rudowicz <michal.rudowicz@fl9.eu>
date Mon, 07 Mar 2011 11:04:11 +0100
parents 58a993029d9f
children 5b4688e1964c
files frontend/mfrontend/__init__.py frontend/mfrontend/views/api.py
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/frontend/mfrontend/__init__.py	Mon Mar 07 10:47:48 2011 +0100
+++ b/frontend/mfrontend/__init__.py	Mon Mar 07 11:04:11 2011 +0100
@@ -5,6 +5,7 @@
 from ConfigParser import SafeConfigParser, NoSectionError
 from mfrontend.views.frontend import frontend
 from mfrontend.views.jobcontrol import jobcontrol
+from mfrontend.views.api import api
 from mfrontend import db, utils
 
 
@@ -24,6 +25,7 @@
 app = flask.Flask(__name__)
 app.register_module(frontend)
 app.register_module(jobcontrol, url_prefix="/jobs")
+app.register_module(api, url_prefix="/api")
 app.config.from_object(__name__)
 app.config.from_envvar('MFRONTEND_SETTINGS', silent=True)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/frontend/mfrontend/views/api.py	Mon Mar 07 11:04:11 2011 +0100
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from flask import jsonify, Module
+from mfrontend import db, utils, exceptions, decorators
+api = Module(__name__)
+
+@api.route('/getjob/')
+@decorators.login_required
+def get_jobs():
+    return jsonify(jobs = db.get_jobs(None, None, None))
+
+@api.route('/getjob/<int:jobid>/')
+@decorators.login_required
+def get_job(jobid):
+    """ Zwraca w formacie JSON informacje o podanym zadaniu.
+        Uwaga: użytkownik musi być zalogowany, aby móc pobrać
+        informację o zadaniu.
+        @param  jobid   Identyfikator żądanego zadania.
+        @return         Informacje o zadaniu w formacie JSON.
+    """
+    pass #TODO!