magpie.ui.user.views¶
Attributes¶
Classes¶
Supported statuses of user-group relationships. |
|
Base methods for Magpie UI pages. |
|
Base methods for Magpie UI pages. |
Functions¶
|
Search in order for matched value of |
|
|
|
Decorator that encapsulates the operation in a try/except block, and redirects the response to the UI error page |
|
Use a pyramid sub-request to request Magpie API routes via the UI. This avoids max retries and closed connections |
|
Retrieves the 'JSON' body of a response using the property/callable according to the response's implementation. |
|
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when |
Module Contents¶
- magpie.ui.user.views.get_constant(constant_name: magpie.typedefs.Str, settings_container: magpie.typedefs.AnySettingsContainer | None = None, settings_name: magpie.typedefs.Str | None = None, default_value: magpie.typedefs.SettingValue | None = None, raise_not_set: bool = True, raise_missing: bool = True, print_missing: bool = False, empty_missing: bool = False) magpie.typedefs.SettingValue[source]¶
- Search in order for matched value of
constant_name: search in
MAGPIE_CONSTANTSsearch in settings if specified
search alternative setting names (see below)
search in
magpie.constantsdefinitionssearch in environment variables
Parameter
constant_nameis expected to have the formatMAGPIE_[VARIABLE_NAME]although any value can be passed to retrieve generic settings from all above-mentioned search locations.If
settings_nameis provided as alternative name, it is used as is to search for results ifconstant_namewas not found. Otherwise,magpie.[variable_name]is used for additional search when the formatMAGPIE_[VARIABLE_NAME]was used forconstant_name(i.e.:MAGPIE_ADMIN_USERwill also search formagpie.admin_userand so on for corresponding constants).- Parameters:
constant_name – key to search for a value
settings_container – WSGI application settings container (if not provided, uses found one in current thread)
settings_name – alternative name for settings if specified
default_value – default value to be returned if not found anywhere, and exception raises are disabled.
raise_not_set – raise an exception if the found key is
None, search until last case if others areNoneraise_missing – raise exception if key is not found anywhere
print_missing – print message if key is not found anywhere, return
Noneempty_missing – consider an empty value for an existing key as if it was missing (i.e.: as if not set).
- Returns:
found value or default_value
- Raises:
ValueError – if resulting value is invalid based on options (by default raise missing/empty/
Nonevalue)LookupError – if no appropriate value could be found from all search locations (according to options)
- Search in order for matched value of
- class magpie.ui.user.views.UserGroupStatus[source]¶
Bases:
magpie.utils.FlexibleNameEnumSupported statuses of user-group relationships.
- ALL = 'all'¶
- ACTIVE = 'active'¶
- PENDING = 'pending'¶
- class magpie.ui.user.views.BaseViews(request)[source]¶
Bases:
objectBase methods for Magpie UI pages.
- MAGPIE_FIXED_USERS_REFS = []¶
Special User that cannot have any relationship edited.
This includes both Group memberships and Permission references.
- MAGPIE_USER_PWD_LOCKED = []¶
Special User that could self-edit themselves, but is disabled since conflicting with other policies.
- MAGPIE_USER_PWD_DISABLED = []¶
Special User where password cannot be edited (managed by Magpie configuration settings).
- MAGPIE_ANONYMOUS_GROUP = None¶
Reference to
magpie.constants.MAGPIE_ANONYMOUS_GROUPfor convenience in UI pages.
- add_template_data(data: Dict[magpie.typedefs.Str, Any] | None = None) Dict[magpie.typedefs.Str, Any][source]¶
Adds required template data for the ‘heading’ mako template applied to every UI page.
- render(template: magpie.typedefs.Str, data: Dict[magpie.typedefs.Str, Any] | None = None) pyramid.response.Response[source]¶
Render the response with an explicit Mako template reference.
Views that are decorated by
pyramid.view.view_config()or registered bypyramid.config.Configurator.add_view()with arendererparameter do not require to call this function as it is auto-resolved with the submitteddata.
- magpie.ui.user.views.check_response(response: magpie.typedefs.AnyResponseType) magpie.typedefs.AnyResponseType[source]¶
- Returns:
response if the HTTP status code is successful.
- Raises:
HTTPError – (of appropriate type) if the response corresponds to an HTTP error code
- magpie.ui.user.views.handle_errors(func: Callable) Callable[source]¶
Decorator that encapsulates the operation in a try/except block, and redirects the response to the UI error page with API error contents.
In worst case scenario where the operation cannot figure out what to do with the exception response, raise the most basic
HTTPInternalServerErrorthat can be formulated from available details.See also
redirect_error()
- magpie.ui.user.views.request_api(request: pyramid.request.Request, path: magpie.typedefs.Str, method: magpie.typedefs.Str = 'GET', data: magpie.typedefs.JSON | magpie.typedefs.Str | None = None, headers: magpie.typedefs.HeadersType | None = None, cookies: magpie.typedefs.CookiesType | None = None) magpie.typedefs.AnyResponseType[source]¶
Use a pyramid sub-request to request Magpie API routes via the UI. This avoids max retries and closed connections when using 1 worker (eg: during tests).
Some information is retrieved from
requestto pass down to the sub-request (eg: cookies). If they are passed as argument, corresponding values will override the ones found inrequest.All sub-requests to the API are assumed to be
magpie.common.CONTENT_TYPE_JSONunless explicitly overridden withheaders. Headers are also looked for additionalSet-Cookieheader in case they need to be passed down tocookies.- Parameters:
request – incoming Magpie UI request that requires sub-request to Magpie API, to retrieve required details.
path – local Magpie API path (relative to root without URL).
method – HTTP method to send the API sub-request.
data – JSON dictionary or literal string content of the request body.
headers – override headers to employ for the API sub-request. Defaults to JSON Accept & Content-Type headers.
cookies – Override cookies to employ for the API sub-request. Defaults to current logged user. For empty cookies (no user), explicitly provide an empty dictionary.
- magpie.ui.user.views.get_json(request_or_response: magpie.typedefs.AnyRequestType | magpie.typedefs.AnyResponseType) magpie.typedefs.JSON[source]¶
Retrieves the ‘JSON’ body of a response using the property/callable according to the response’s implementation.
- magpie.ui.user.views.get_logger(name: magpie.typedefs.Str, level: int | None = None, force_stdout: bool = None, message_format: magpie.typedefs.Str | None = None, datetime_format: magpie.typedefs.Str | None = None) logging.Logger[source]¶
Immediately sets the logger level to avoid duplicate log outputs from the root logger and this logger when level is
logging.NOTSET.
- class magpie.ui.user.views.UserViews(request)[source]¶
Bases:
magpie.ui.utils.BaseViewsBase methods for Magpie UI pages.
- add_template_data(data=None)[source]¶
Adds required template data for the ‘heading’ mako template applied to every UI page.
- get_current_user_groups(user_group_status: magpie.models.UserGroupStatus = UserGroupStatus.ACTIVE) magpie.typedefs.List[str][source]¶
- join_discoverable_group(group_name)[source]¶
Registers the current user to the discoverable group.
- Raises:
HTTPBadRequest – if the operation is not valid.
- leave_discoverable_group(group_name: magpie.typedefs.Str) None[source]¶
Unregisters the current user from the discoverable group.
- Raises:
HTTPBadRequest – if the operation is not valid.
- edit_current_user()[source]¶
Edit the own fields of the current user profile (self-update information).
See also
magpie.ui.management.views.ManagementViews.edit_user()for corresponding operation by administrator