本文整理汇总了Python中shuup.admin.module_registry.get_modules函数的典型用法代码示例。如果您正苦于以下问题:Python get_modules函数的具体用法?Python get_modules怎么用?Python get_modules使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_modules函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dashboard_blocks
def test_dashboard_blocks(rf):
request = rf.get("/")
with replace_modules([ATestModule]):
block_ids = set()
for block in chain(*(m.get_dashboard_blocks(request) for m in get_modules())):
block_ids.add(block.id)
assert block_ids >= set(["test-0", "test-1", "test-2", "test-3", "test-4"])
示例2: get_menu_entry_categories
def get_menu_entry_categories(request):
menu_categories = OrderedDict()
menu_category_icons = {}
for identifier, category_name, icon in MENU_CATEGORIES:
menu_categories[identifier] = _MenuCategory(category_name, icon)
menu_category_icons[identifier] = icon
modules = list(get_modules())
for module in modules:
menu_category_icons.update(
(force_text(key), force_text(value))
for (key, value) in module.get_menu_category_icons().items()
if key not in menu_category_icons
)
for module in modules:
if get_missing_permissions(request.user, module.get_required_permissions()):
continue
for entry in (module.get_menu_entries(request=request) or ()):
category_identifier = entry.category
category = menu_categories.get(category_identifier) if category_identifier else None
if not category:
category_identifier = force_text(category_identifier or module.name)
category = menu_categories.get(category_identifier)
if not category:
menu_categories[category_identifier] = category = _MenuCategory(
name=category_identifier,
icon=menu_category_icons.get(category_identifier, "fa fa-circle")
)
category.entries.append(entry)
return [c for identifier, c in six.iteritems(menu_categories) if len(c.entries) > 0]
示例3: get_search_results
def get_search_results(request, query):
fuzzer = FuzzyMatcher(query)
normal_results = []
menu_entry_results = []
for module in get_modules():
if get_missing_permissions(request.user, module.get_required_permissions()):
continue
normal_results.extend(module.get_search_results(request, query) or ())
for menu_entry in module.get_menu_entries(request) or ():
texts = (menu_entry.get_search_query_texts() or ())
if any(fuzzer.test(text) for text in texts):
menu_entry_results.append(SearchResult(
text=menu_entry.text,
url=menu_entry.url,
icon=menu_entry.icon,
category=menu_entry.category,
relevance=90,
is_action=True
))
results = sorted(
chain(normal_results, menu_entry_results),
key=lambda r: r.relevance,
reverse=True
)
return results
示例4: test_permission_group_form_updates_members
def test_permission_group_form_updates_members(regular_user):
with replace_modules([ARestrictedTestModule]):
modules = [m for m in get_modules()]
test_module = modules[0]
module_permissions = test_module.get_required_permissions()
assert module_permissions
group = get_default_permission_group()
PermissionGroupForm(instance=group, prefix=None)
assert not group.permissions.all()
assert not group.user_set.all()
data = {
"name": "New Name",
"members": [force_text(regular_user.pk)],
}
for permission in ARestrictedTestModule().get_required_permissions():
data["perm:%s" % permission] = permission
form = PermissionGroupForm(instance=group, prefix=None, data=data)
form.save()
assert group.name == "New Name"
assert set(module_permissions) == get_permissions_from_group(group)
assert regular_user in group.user_set.all()
form = PermissionGroupForm(instance=group, prefix=None, data={"name": "Name"})
form.save()
assert not group.permissions.all()
assert not group.user_set.all()
示例5: get_menu_entry_categories
def get_menu_entry_categories(request):
menu_categories = OrderedDict()
menu_children = OrderedDict()
menu_category_icons = {}
for menu_item in MAIN_MENU:
identifier = menu_item["identifier"]
icon = menu_item["icon"]
menu_categories[identifier] = _MenuCategory(
identifier=identifier,
name=menu_item["title"],
icon=icon,
)
for child in menu_item["children"]:
child_identifier = "%s:%s" % (identifier, child["identifier"])
child_category = _MenuCategory(child["identifier"], child["title"], None)
menu_children[child_identifier] = child_category
menu_categories[identifier].children.append(child_category)
menu_category_icons[identifier] = icon
modules = list(get_modules())
for module in modules:
menu_category_icons.update(
(force_text(key), force_text(value))
for (key, value) in module.get_menu_category_icons().items()
if key not in menu_category_icons
)
all_categories = set()
for module in modules:
if get_missing_permissions(request.user, module.get_required_permissions()):
continue
for entry in (module.get_menu_entries(request=request) or ()):
category_identifier = entry.category
subcategory = entry.subcategory
entry_identifier = "%s:%s" % (category_identifier, subcategory) if subcategory else category_identifier
menu_items = menu_children if subcategory else menu_categories
category = menu_items.get(entry_identifier)
if not category:
category_identifier = force_text(category_identifier or module.name)
category = menu_items.get(category_identifier)
if not category:
menu_items[category_identifier] = category = _MenuCategory(
identifier=category_identifier,
name=category_identifier,
icon=menu_category_icons.get(category_identifier, "fa fa-circle")
)
category.entries.append(entry)
if subcategory:
parent = menu_categories.get(category_identifier)
all_categories.add(parent)
else:
all_categories.add(category)
return [c for menu_identifier, c in six.iteritems(menu_categories) if c in all_categories]
示例6: get_context_data
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
context["blocks"] = blocks = []
context["tour_key"] = "home"
context["tour_complete"] = is_tour_complete("home")
wizard_complete = setup_wizard_complete()
wizard_url = reverse("shuup_admin:wizard")
wizard_actions = []
if not wizard_complete:
wizard_actions.append({
"text": _("Complete wizard"),
"url": wizard_url
})
else:
wizard_steps = load_setup_wizard_panes(
shop=Shop.objects.first(), request=self.request, visible_only=False)
for step in wizard_steps:
wizard_actions.append({
"text": step.title,
"url": "%s?pane_id=%s" % (wizard_url, step.identifier),
"no_redirect": True
})
blocks.append(
SimpleHelpBlock(
_("Complete the setup wizard"),
actions=wizard_actions,
icon_url="shuup_admin/img/configure.png",
priority=-1,
done=wizard_complete
)
)
for module in get_modules():
if not get_missing_permissions(self.request.user, module.get_required_permissions()):
blocks.extend(module.get_help_blocks(request=self.request, kind="setup"))
blocks.sort(key=lambda b: b.priority)
blocks.append(
SimpleHelpBlock(
priority=1000,
text=_("Publish your store"),
description=_("Let customers browse your store and make purchases"),
css_class="green",
actions=[{
"method": "POST",
"text": _("Publish shop"),
"url": reverse("shuup_admin:shop.enable", kwargs={"pk": self.request.shop.pk}),
"data": {
"enable": True,
"redirect": reverse("shuup_admin:dashboard")
}
}],
icon_url="shuup_admin/img/publish.png"
)
)
return context
示例7: test_valid_permissions_for_all_modules
def test_valid_permissions_for_all_modules():
"""
If a module requires permissions, make sure all url and module-
level permissions are valid.
"""
for module in get_modules():
url_permissions = set(get_permissions_from_urls(module.get_urls()))
module_permissions = set(module.get_required_permissions())
for permission in (url_permissions | module_permissions):
assert get_permission_object_from_string(permission)
示例8: get_context_data
def get_context_data(self, **kwargs):
context = super(DashboardView, self).get_context_data(**kwargs)
context["version"] = shuup.__version__
context["notifications"] = notifications = []
context["blocks"] = blocks = []
for module in get_modules():
notifications.extend(module.get_notifications(request=self.request))
blocks.extend(module.get_dashboard_blocks(request=self.request))
context["activity"] = get_activity(request=self.request)
return context
示例9: _get_enabled_modules
def _get_enabled_modules(self, permissions):
if not self.instance.pk:
return []
permissions = set(permissions)
modules = []
for module in get_modules():
# Ignore modules that haven't configured a name
if module.name != "_Base_" and set(module.get_required_permissions()).issubset(permissions):
modules.append(force_text(module.name))
return modules
示例10: setup_blocks_complete
def setup_blocks_complete(request):
"""
Check if any incomplete setup blocks remain.
:return: whether all setup blocks are complete
:rtype: Boolean
"""
for module in get_modules():
if len([block for block in module.get_help_blocks(request=request, kind="setup") if not block.done]) > 0:
return False
return True
示例11: get_context_data
def get_context_data(self, **kwargs):
context = super(HomeView, self).get_context_data(**kwargs)
shop = get_shop(self.request)
context["blocks"] = blocks = []
context["tour_key"] = "home"
context["tour_complete"] = is_tour_complete(shop, "home", user=self.request.user)
wizard_complete = setup_wizard_complete(self.request)
wizard_url = reverse("shuup_admin:wizard")
wizard_actions = []
if not wizard_complete:
wizard_actions.append({
"text": _("Complete wizard"),
"url": wizard_url
})
else:
wizard_steps = load_setup_wizard_panes(shop=shop, request=self.request, visible_only=False)
for step in wizard_steps:
wizard_actions.append({
"text": step.title,
"url": "%s?pane_id=%s" % (wizard_url, step.identifier),
"no_redirect": True
})
if wizard_actions:
blocks.append(
SimpleHelpBlock(
_("Complete the setup wizard"),
actions=wizard_actions,
icon_url="shuup_admin/img/configure.png",
priority=-1,
done=wizard_complete
)
)
for module in get_modules():
if not get_missing_permissions(self.request.user, module.get_required_permissions()):
blocks.extend(module.get_help_blocks(request=self.request, kind="setup"))
blocks.sort(key=lambda b: b.priority)
if not blocks:
blocks.append(
SimpleHelpBlock(
_("All set. Nothing to be configured"),
actions=[],
icon_url="shuup_admin/img/configure.png",
priority=-1,
done=True
)
)
return context
示例12: get_context_data
def get_context_data(self, **kwargs):
context = super(DashboardView, self).get_context_data(**kwargs)
context["version"] = shuup.__version__
context["notifications"] = notifications = []
context["blocks"] = blocks = []
for module in get_modules():
if not get_missing_permissions(self.request.user, module.get_required_permissions()):
notifications.extend(module.get_notifications(request=self.request))
blocks.extend(module.get_dashboard_blocks(request=self.request))
context["activity"] = get_activity(request=self.request)
context["tour_key"] = "dashboard"
context["tour_complete"] = is_tour_complete("dashboard")
return context
示例13: test_valid_permissions_for_all_modules
def test_valid_permissions_for_all_modules():
"""
If a module requires permissions, make sure all url and module-
level permissions are valid.
Modules that add permissions using migrations must be checked
manually since their permissions will not be in the test database.
"""
for module in get_modules():
url_permissions = set(get_permissions_from_urls(module.get_urls()))
module_permissions = set(module.get_required_permissions())
for permission in (url_permissions | module_permissions):
# Only requirement for permissions are that they
# are list of strings
assert isinstance(permission, six.string_types)
示例14: get_quicklinks
def get_quicklinks(request):
quicklinks = OrderedDict()
for block in QUICKLINK_ORDER:
quicklinks[block] = []
for module in get_modules():
if get_missing_permissions(request.user, module.get_required_permissions()):
continue
for help_block in module.get_help_blocks(request, kind="quicklink"):
quicklinks[help_block.category].append(help_block)
links = quicklinks.copy()
for block, data in six.iteritems(links):
if not quicklinks[block]:
quicklinks.pop(block)
return quicklinks
示例15: test_valid_permissions_for_all_modules
def test_valid_permissions_for_all_modules():
"""
If a module requires permissions, make sure all url and module-
level permissions are valid.
Modules that add permissions using migrations must be checked
manually since their permissions will not be in the test database.
"""
for module in get_modules():
url_permissions = set(get_permissions_from_urls(module.get_urls()))
module_permissions = set(module.get_required_permissions())
for permission in (url_permissions | module_permissions):
if module.__class__ in migrated_permissions:
assert permission in migrated_permissions[module.__class__]
else:
assert get_permission_object_from_string(permission)