当前位置: 首页>>代码示例>>Python>>正文


Python permissions.get_missing_permissions函数代码示例

本文整理汇总了Python中shuup.admin.utils.permissions.get_missing_permissions函数的典型用法代码示例。如果您正苦于以下问题:Python get_missing_permissions函数的具体用法?Python get_missing_permissions怎么用?Python get_missing_permissions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_missing_permissions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: 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
开发者ID:ruqaiya,项目名称:shuup,代码行数:26,代码来源:search.py

示例2: render

 def render(self, request):
     if not get_missing_permissions(request.user, self.required_permissions):
         yield '<li>'
         button = super(PostActionDropdownItem, self).render(request)
         for bit in button:
             yield bit
         yield '</li>'
开发者ID:gurch101,项目名称:shuup,代码行数:7,代码来源:toolbar.py

示例3: render

    def render(self, request):
        if not get_missing_permissions(request.user, self.required_permissions):
            if not self.items:
                return
            yield '<div class="btn-group" role="group">'

            if self.split_button:
                for bit in self.split_button.render(request):
                    yield bit

            yield '<button %s>' % flatatt_filter({
                "type": "button",
                "class": self.get_computed_class(),
                "data-toggle": "dropdown",
                "title": self.tooltip
            })

            if not self.split_button:
                yield self.render_label()
                yield " "

            yield '</button>'
            for bit in self.render_dropdown(request):
                yield bit
            yield '</div>'
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:toolbar.py

示例4: get_stock_adjustment_div

def get_stock_adjustment_div(request, supplier, product):
    """
    Get html string to adjust stock values

    Contains inputs for purchase_price_value and delta

    :param request: HTTP request
    :type request: django.http.HttpRequest
    :param supplier: shuup Supplier
    :type supplier: shuup.core.models.Supplier
    :param product: shuup Product
    :type product: shuup.core.models.Product
    :return: html div as a string
    :rtype: str
    """
    stock = StockCount.objects.get_or_create(product=product, supplier=supplier)[0]
    latest_adjustment = StockAdjustment.objects.filter(
        product=product, supplier=supplier, type=StockAdjustmentType.INVENTORY).last()
    purchase_price = (latest_adjustment.purchase_price.as_rounded().value if latest_adjustment else Decimal())
    context = {
        "product": product,
        "supplier": supplier,
        "delta_step": pow(0.1, product.sales_unit.decimals) if product.sales_unit.decimals else 0,
        "adjustment_form": StockAdjustmentForm(initial={"purchase_price": purchase_price, "delta": None}),
        "stock": stock,
        "stock_managed_form": StockManagedForm(initial={"stock_managed": not stock.stock_managed})
    }
    if "shuup.notify" in settings.INSTALLED_APPS:
        context["alert_limit_form"] = AlertLimitForm(initial={"alert_limit": stock.alert_limit or Decimal()})
        if not get_missing_permissions(request.user, ("notify.script.list",)):
            context["notify_url"] = reverse("shuup_admin:notify.script.list")
        else:
            context["notify_url"] = ""
    return render_to_string("shuup/simple_supplier/admin/add_stock_form.jinja", context=context, request=request)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:utils.py

示例5: get_stock_adjustment_div

def get_stock_adjustment_div(request, supplier, product):
    """
    Get html string to adjust stock values

    Contains inputs for purchase_price_value and delta

    :param request: HTTP request
    :type request: django.http.HttpRequest
    :param supplier: shuup Supplier
    :type supplier: shuup.core.models.Supplier
    :param product: shuup Product
    :type product: shuup.core.models.Product
    :return: html div as a string
    :rtype: str
    """
    latest_adjustment = StockAdjustment.objects.filter(
        product=product, supplier=supplier, type=StockAdjustmentType.INVENTORY
    ).last()
    purchase_price = latest_adjustment.purchase_price_value if latest_adjustment else Decimal("0.00")
    context = {
        "product": product,
        "supplier": supplier,
        "delta_step": pow(0.1, product.sales_unit.decimals),
        "adjustment_form": StockAdjustmentForm(initial={"purchase_price": purchase_price, "delta": None}),
    }
    if "shuup.notify" in settings.INSTALLED_APPS:
        from shuup.notify.models import Notification

        context["alert_limit_form"] = AlertLimitForm(initial={"alert_limit": 0})
        if not get_missing_permissions(request.user, get_default_model_permissions(Notification)):
            context["notify_url"] = reverse("shuup_admin:notify.script.list")
        else:
            context["notify_url"] = ""
    return render_to_string("shuup/simple_supplier/admin/add_stock_form.jinja", context=context, request=request)
开发者ID:shawnadelic,项目名称:shuup,代码行数:34,代码来源:utils.py

示例6: 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]
开发者ID:NamiStudio,项目名称:shuup,代码行数:31,代码来源:menu.py

示例7: 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]
开发者ID:gurch101,项目名称:shuup,代码行数:59,代码来源:menu.py

示例8: 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
开发者ID:gurch101,项目名称:shuup,代码行数:57,代码来源:home.py

示例9: 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)
     return context
开发者ID:NamiStudio,项目名称:shuup,代码行数:11,代码来源:dashboard.py

示例10: 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
开发者ID:ruqaiya,项目名称:shuup,代码行数:52,代码来源:home.py

示例11: 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
开发者ID:ruqaiya,项目名称:shuup,代码行数:16,代码来源:menu.py

示例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))

        # sort blocks by sort order and size, trying to make them fit better
        blocks.sort(key=lambda block: (block.sort_order, DashboardBlock.SIZES.index(block.size)))
        context["activity"] = get_activity(request=self.request)
        context["tour_key"] = "dashboard"
        context["tour_complete"] = is_tour_complete(get_shop(self.request), "dashboard", user=self.request.user)
        return context
开发者ID:ruqaiya,项目名称:shuup,代码行数:16,代码来源:dashboard.py

示例13: _get_unauth_reason

    def _get_unauth_reason(self, request):
        """
        Figure out if there's any reason not to allow the user access to this view via the given request.

        :type request: Request
        :param request: HttpRequest
        :rtype: str|None
        """

        if self.require_authentication:
            if not request.user.is_authenticated():
                return _("You must be logged in.")
            elif not getattr(request.user, 'is_staff', False):
                return _("You must be a staff member.")

        missing_permissions = get_missing_permissions(request.user, self.permissions)
        if missing_permissions:
            return _("You do not have the required permissions: %s") % ", ".join(missing_permissions)
开发者ID:gurch101,项目名称:shuup,代码行数:18,代码来源:urls.py

示例14: _get_unauth_reason

    def _get_unauth_reason(self, request):
        """
        Figure out if there's any reason not to allow the user access to this view via the given request.

        :type request: Request
        :param request: HttpRequest
        :rtype: str|None
        """
        if self.require_authentication:
            if not request.user.is_authenticated():
                return _("Sign in to continue")
            elif not getattr(request.user, 'is_staff', False):
                return _("You must be a staff member.")
            elif not get_shop(request):
                return _("There is no active shop available. Contact support for more details.")

        missing_permissions = get_missing_permissions(request.user, self.permissions)
        if missing_permissions:
            return _("You do not have the required permissions: %s") % ", ".join(missing_permissions)
开发者ID:ruqaiya,项目名称:shuup,代码行数:19,代码来源:urls.py

示例15: get_context_data

    def get_context_data(order, request=None):
        suppliers = Supplier.objects.filter(order_lines__order=order).distinct()
        create_permission = "order.create-shipment"
        delete_permission = "order.delete-shipment"
        missing_permissions = get_missing_permissions(request.user, [create_permission, delete_permission])
        create_urls = {}
        if create_permission not in missing_permissions:
            for supplier in suppliers:
                create_urls[supplier.pk] = reverse(
                    "shuup_admin:order.create-shipment", kwargs={"pk": order.pk, "supplier_pk": supplier.pk})

        delete_urls = {}
        if delete_permission not in missing_permissions:
            for shipment_id in order.shipments.all_except_deleted().values_list("id", flat=True):
                delete_urls[shipment_id] = reverse(
                    "shuup_admin:order.delete-shipment", kwargs={"pk": shipment_id})

        return {
            "suppliers": suppliers,
            "create_urls": create_urls,
            "delete_urls": delete_urls
        }
开发者ID:ruqaiya,项目名称:shuup,代码行数:22,代码来源:sections.py


注:本文中的shuup.admin.utils.permissions.get_missing_permissions函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。