Skip to content

Instantly share code, notes, and snippets.

@wilig
Created April 10, 2013 17:11
Show Gist options
  • Save wilig/5356533 to your computer and use it in GitHub Desktop.
Save wilig/5356533 to your computer and use it in GitHub Desktop.
New controllers look like this
@restrict(internal_access=True)
def index(request):
params = request.params
account = request.account
project, asset_group = _find_project_and_asset_group(request.db,
request.matchdict)
res = Asset.search_by_project(account, project, asset_group, params)
if params.get("with_meta", False) == "true":
return extjs.configure_asset_panel(account, project, res)
else:
return extjs.serialize_search(Asset, res)
@restrict()
def show(request):
try:
asset = Asset.find_by_id(request.account, request.matchdict['id'])
return dict(success=True, asset=[asset.to_dict()])
except NoResultFound:
not_found("Asset [%s] not found." % str(request.matchdict['asset_id']))
@restrict()
@unwrap_json('assets')
def update(request):
try:
asset = Asset.find_by_id(request.account, request.matchdict['id'])
asset.update(request.account, request.params)
return dict(success=True, assets=[asset.to_dict()])
except NoResultFound:
not_found("Asset [%s] not found." % str(request.matchdict['id']))
@restrict()
def delete(request):
try:
asset = Asset.find_by_id(request.account, request.matchdict['id'])
asset.delete(request.account)
return dict(success=True)
except NoResultFound:
not_found("Asset [%s] not found." % str(request.matchdict['id']))
@restrict()
@unwrap_json('assets')
def create(request):
db = request.db
project, asset_group = _find_project_and_asset_group(db, request.matchdict)
asset = Asset.create(request.account, project, asset_group, request.params)
return dict(success=True, assets=[asset.to_dict()])
@restrict(role=Roles.ADMIN)
def suppress(request):
pt_ids = request.params.get("publishing_target_ids", None)
try:
asset = Asset.find_by_id(request.account, request.matchdict['id'])
targets = asset.suppress(request.account, pt_ids)
return dict(success=True,
targets=[t.publishing_link_info() for t in targets],
num_suppressed=1)
except NoResultFound:
not_found("Asset [%s] not found." % str(request.matchdict['id']))
@restrict(role=Roles.ADMIN)
def publish(request):
pt_ids = request.params.get("publishing_target_ids", None)
try:
asset = Asset.find_by_id(request.account, request.matchdict['id'])
targets = asset.publish(request.account, pt_ids)
return dict(success=True,
targets=[t.publishing_link_info() for t in targets],
num_suppressed=1)
except NoResultFound:
not_found("Asset [%s] not found." % str(request.matchdict['id']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment