def get(key, node=None, default=None): """ Retrieve data :param key: :param node: the node_key or the dot notation key to retrieve sub data get('myapp', 'this.is.a.nested.dict.data') get('my_other_data') :param default: :return: dict_dot dict object """ d = AppData.get_by_key(key) if d: data = utils.dict_dot(d) return data.get(node, default) if node else data return {}
def test_dict_dot(): d = { "name": "Mardix", "location": { "street": "My Address", "city": "Charlotte", "state": "NC" }, "family": { "wife": { "name": "Rara" }, "kids": [{ "name": "Son#1", "toys": ["cars", "paper", "planes"] }, { "name": "Son#2" }] } } dd = utils.dict_dot(d) assert dd.get("name") == "Mardix" assert dd["name"] == "Mardix" dd["name"] = "Jones" assert dd.get("name") == "Jones" assert dd.get("location.city") == "Charlotte" assert dd.get("location.zip_code") is None assert dd.get("location.area_code", 704) == 704 assert isinstance(dd.get("family"), dict) assert dd.get("family.wife.name") == "Rara" assert dd.get("family.kids.0.name") == "Son#1" assert isinstance(dd.get("family.kids.0.toys"), list) assert dd.get("family.kids.0.toys.2") == "planes" assert dd.get("family.kids.1.name") == "Son#2"
import logging from . import signals, exceptions, oauth import flask_login from flask import current_app from mocha.exceptions import AppError import mocha.cli from mocha import (_, utc_now, config, abort, send_mail, url_for, views, models, utils, request, redirect, flash, session, init_app, decorators as h_deco) import models as auth_models from flask_login import current_user __version__ = "1.0.0" __options__ = utils.dict_dot({}) # USER ROLES ROLES_SUPERADMIN = ["SUPERADMIN"] ROLES_ADMIN = ROLES_SUPERADMIN + ["ADMIN"] ROLES_MANAGER = ROLES_ADMIN + ["MANAGER"] ROLES_CONTRIBUTOR = ROLES_MANAGER + ["EDITOR", "CONTRIBUTOR"] ROLES_MODERATOR = ROLES_CONTRIBUTOR + ["MODERATOR"] ACTIONS = { "USERNAME": "******", "PASSWORD": "******", "EMAIL": "EMAIL", "STATUS": "STATUS", "PROFILE_IMAGE": "PROFILE_IMAGE", "UPDATE": "UPDATE"