Add some JSON methods for pkgdb (and other interested apps)
This commit is contained in:
parent
53363cba7c
commit
dd54aedfb3
1 changed files with 42 additions and 1 deletions
|
@ -1,14 +1,55 @@
|
|||
import turbogears
|
||||
from turbogears import controllers, expose, identity
|
||||
|
||||
from fas.model import People
|
||||
from fas.model import Groups
|
||||
from fas.model import Log
|
||||
|
||||
from fas.auth import *
|
||||
|
||||
class JsonRequest(controllers.Controller):
|
||||
def __init__(self):
|
||||
"""Create a JsonRequest Controller."""
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
@expose("json")
|
||||
def index(self):
|
||||
"""Return a help message"""
|
||||
return dict(help='This is a json interface')
|
||||
return dict(help='This is a JSON interface.')
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
@expose("json")
|
||||
def person_by_id(self, id):
|
||||
try:
|
||||
person = People.by_id(id)
|
||||
return dict(success=True, person=person)
|
||||
except InvalidRequestError:
|
||||
return dict(success=False)
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
@expose("json")
|
||||
def person_by_username(self, username):
|
||||
try:
|
||||
person = People.by_username(username)
|
||||
return dict(success=True, person=person)
|
||||
except InvalidRequestError:
|
||||
return dict(success=False)
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
@expose("json")
|
||||
def group_by_id(self, id):
|
||||
try:
|
||||
group = Groups.by_id(id)
|
||||
return dict(success=True, group=group)
|
||||
except InvalidRequestError:
|
||||
return dict(success=False)
|
||||
|
||||
@identity.require(turbogears.identity.not_anonymous())
|
||||
@expose("json")
|
||||
def group_by_name(self, groupname):
|
||||
try:
|
||||
group = Groups.by_name(groupname)
|
||||
return dict(success=True, group=group)
|
||||
except InvalidRequestError:
|
||||
return dict(success=False)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue