コード例 #1
0
ファイル: toolbar.py プロジェクト: vituocgia/wshop
    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 '<i class="fa fa-chevron-down"></i>'
            yield '</button>'
            for bit in self.render_dropdown(request):
                yield bit
            yield '</div>'
コード例 #2
0
ファイル: toolbar.py プロジェクト: vituocgia/wshop
 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>'
コード例 #3
0
ファイル: toolbar.py プロジェクト: vituocgia/wshop
 def render(self, request):
     if not get_missing_permissions(request.user,
                                    self.required_permissions):
         yield '<a %s>' % flatatt_filter({
             "href": self.url,
             "class": self.get_computed_class(),
             "title": self.tooltip
         })
         yield self.render_label()
         yield '</a>'
コード例 #4
0
ファイル: toolbar.py プロジェクト: vituocgia/wshop
 def render(self, request):
     if not get_missing_permissions(request.user,
                                    self.required_permissions):
         yield '<a %s>' % flatatt_filter(
             {
                 "href": "#",
                 "class": self.get_computed_class(),
                 "title": self.tooltip,
                 "onclick":
                 mark_safe(self.onclick) if self.onclick else None
             })
         yield self.render_label()
         yield '</a>'
コード例 #5
0
ファイル: dashboard.py プロジェクト: vituocgia/wshop
 def get_context_data(self, **kwargs):
     context = super(DashboardView, self).get_context_data(**kwargs)
     context["version"] = wshop.__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
コード例 #6
0
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
コード例 #7
0
ファイル: utils.py プロジェクト: vituocgia/wshop
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: wshop Supplier
    :type supplier: wshop.core.models.Supplier
    :param product: wshop Product
    :type product: wshop.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 "wshop.notify" in settings.INSTALLED_APPS:
        from wshop.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("wshop_admin:notify.script.list")
        else:
            context["notify_url"] = ""
    return render_to_string("wshop/simple_supplier/admin/add_stock_form.jinja",
                            context=context,
                            request=request)
コード例 #8
0
ファイル: urls.py プロジェクト: vituocgia/wshop
def get_model_url(object,
                  kind="detail",
                  user=None,
                  required_permissions=None,
                  shop=None):
    """
    Get a an admin object URL for the given object or object class by
    interrogating each admin module.

    If a user is provided, checks whether user has correct permissions
    before returning URL.

    Raises `NoModelUrl` if lookup fails

    :param object: Model or object class.
    :type object: class
    :param kind: URL kind. Currently "new", "list", "edit", "detail".
    :type kind: str
    :param user: Optional instance to check for permissions
    :type user: django.contrib.auth.models.User|None
    :param required_permissions: Optional iterable of permission strings
    :type required_permissions: Iterable[str]|None
    :param shop: The shop that owns the resource
    :type request: wshop.core.models.Shop|None
    :return: Resolved URL.
    :rtype: str
    """
    for module in get_modules():
        url = module.get_model_url(object, kind, shop)
        if not url:
            continue
        if user is None:
            return url
        else:
            permissions = ()
            if required_permissions is not None:
                permissions = required_permissions
            else:
                # TODO: Check permission type based on kind
                permissions = get_default_model_permissions(object)
            if not get_missing_permissions(user, permissions):
                return url
    raise NoModelUrl("Can't get object URL of kind %s: %r" %
                     (kind, force_text(object)))
コード例 #9
0
ファイル: urls.py プロジェクト: vituocgia/wshop
    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)
コード例 #10
0
ファイル: toolbar.py プロジェクト: vituocgia/wshop
 def render(self, request):
     if not get_missing_permissions(request.user,
                                    self.required_permissions):
         yield '<button %s>' % flatatt_filter({
             "form":
             self.form_id,  # This can be used to post another form
             "formaction":
             self.post_url,
             "name":
             self.name,
             "value":
             self.value,
             "type":
             "submit",
             "title":
             self.tooltip,
             "class":
             self.get_computed_class(),
             "onclick":
             ("return confirm(%s)" % json.dumps(force_text(self.confirm))
              if self.confirm else None)
         })
         yield self.render_label()
         yield '</button>'
コード例 #11
0
def get_menu_entry_categories(request):
    menu_categories = OrderedDict()
    menu_children = OrderedDict()

    # Update main menu from provides
    main_menu = extend_main_menu(MAIN_MENU)

    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
    ]
コード例 #12
0
ファイル: toolbar.py プロジェクト: vituocgia/wshop
 def render(self, request):
     if not get_missing_permissions(request.user,
                                    self.required_permissions):
         yield '<li class="dropdown-header">%s</li>' % self.text