noc.lib.app.application

Module Contents

class noc.lib.app.application.FormErrorsContext(form)

Bases: object

Catch ValueError exception and populate form’s _errors fields

__enter__(self)
__exit__(self, exc_type, exc_val, exc_tb)
class noc.lib.app.application.ApplicationBase

Bases: type

Application metaclass. Registers application class to site

classmethod __new__(mcs, name, bases, attrs)
class noc.lib.app.application.Application(site)

Bases: six.with_metaclass()

Basic application class.

Application combined by set of methods, decorated with @view. Each method accepts requests and returns reply

title = APPLICATION TITLE
icon = icon_application
glyph = file
extra_permissions = []
implied_permissions
diverged_permissions
Form
config
app_alias
TZ
js_app_class
base_url

Application’s base URL

mrt_config
classmethod add_to_class(cls, name, value)
set_app(self, app)
classmethod add_view(cls, name, func, url, access, url_name=None, menu=None, method=None, validate=None, api=False)
get_launch_info(self, request)

Return desktop launch information

classmethod get_app_id(cls)

Returns application id

reverse(self, url, *args, **kwargs)

Reverse URL name to URL

message_user(self, request, message)

Send a message to user

get_template_path(self, template)

Return path to named template

static get_object_or_404(*args, **kwargs)

Shortcut to get_object_or_404

get_environment(self)

Returns jinja2 environment :return:

render(self, request, template, dict=None, **kwargs)

Render template within context

render_template(self, template, dict=None, **kwargs)

Render template to string

static render_response(data, content_type='text/plain')

Render arbitrary Content-Type response

static render_plain_text(text, content_type='text/plain')

Render plain/text response

static render_json(obj, status=200)

Create serialized JSON-encoded response

render_success(self, request, subject=None, text=None)

Render “success” page

render_failure(self, request, subject=None, text=None)

Render “failure” page

render_wait(self, request, subject=None, text=None, url=None, timeout=5, progress=None)

Render wait page

render_static(self, request, path, document_root=None)
response_redirect(self, url, *args, **kwargs)

Redirect to URL

response_redirect_to_referrer(self, request, back_url=None)

Redirect to referrer page

response_redirect_to_object(self, object)

Redirect to object: {{base.url}}/{{object.id}}/

response_forbidden(self, text=None)

Render Forbidden response

response_not_found(self, text=None)

Render Not Found response

response_bad_request(self, text=None)

Render 400 Bad Request :param text: :return:

response_accepted(self, location=None)

Render 202 Accepted :param location: :return:

close_popup(self, request)

Render javascript closing popup window

html_escape(self, s)

Escape HTML

debug(self, message)
error(self, message)
cursor(self)

Returns db cursor

execute(self, sql, args=[])

Execute SQL query

lookup(self, request, func)

AJAX lookup wrapper @todo: Remove

lookup_json(self, request, func, id_field='id', name_field='name')

Ajax lookup wrapper, returns JSON list of hashes

iter_views(self)

Iterator returning application views

get_permissions(self)

Return a set of permissions, used by application

user_access_list(self, user)

Return a list of user access entries

group_access_list(self, group)

Return a list of group access entries

user_access_change_url(self, user)

Return an URL to change user access

group_access_change_url(self, group)

Return an URL to change group access

customize_form(self, form, table, search=False)

Add custom fields to django form class

apply_custom_fields(self, o, v, table)

Apply custom fields to form :param o: Object :param v: values dict :param table: table :return:

apply_custom_initial(self, o, v, table)
Parameters:
  • o – Object
  • v – Initial data
  • table – table
Returns:

form_errors(self, form)
with self.form_errors(form):
object.save()
Parameters:form
Returns:
to_json(self, v)

Convert custom types to json string :param v: :return:

api_launch_info(self, request)