示例#1
0
class CategoryListView(PicotableListView):
    model = Category
    columns = [
        Column("name",
               _(u"Name"),
               sort_field="translations__name",
               display="name",
               linked=True,
               filter_config=TextFilter(filter_field="translations__name",
                                        placeholder=_("Filter by name..."))),
        Column("status",
               _(u"Status"),
               filter_config=ChoicesFilter(choices=CategoryStatus.choices)),
        Column(
            "visibility",
            _(u"Visibility"),
            filter_config=ChoicesFilter(choices=CategoryVisibility.choices)),
        Column("parent", _(u"Parent"), sortable=False, display="parent"),
    ]

    def get_queryset(self):
        return Category.objects.all_except_deleted()

    def get_object_abstract(self, instance, item):
        return [{
            "text": "%s" % instance,
            "class": "header"
        }, {
            "title": _(u"Status"),
            "text": item["status"]
        }, {
            "title": _(u"Parent"),
            "text": item["parent"]
        } if instance.parent_id else None]
示例#2
0
class AttributeListView(PicotableListView):
    model = Attribute
    columns = [
        Column("identifier",
               _("Identifier"),
               filter_config=TextFilter(
                   filter_field="identifier",
                   placeholder=_("Filter by identifier..."))),
        Column("name",
               _("Name"),
               sort_field="translations__name",
               display="name",
               filter_config=TextFilter(filter_field="translations__name",
                                        placeholder=_("Filter by name..."))),
        Column("type",
               _("Type"),
               filter_config=ChoicesFilter(AttributeType.choices)),
        Column("visibility_mode",
               _("Visibility Mode"),
               filter_config=ChoicesFilter(AttributeVisibility.choices)),
        Column("searchable", _("Searchable")),
        Column("n_product_types", _("Used in # Product Types")),
    ]

    def get_queryset(self):
        return Attribute.objects.all().annotate(
            n_product_types=Count("product_types"))

    def get_object_abstract(self, instance, item):
        return [
            {
                "text": "%s" % instance,
                "class": "header"
            },
        ]
示例#3
0
def get_pico(rf, model=None, columns=None):
    model = model or get_user_model()
    columns = columns or [
        Column("id", "Id", filter_config=Filter(), display=instance_id),
        Column("username",
               "Username",
               sortable=False,
               filter_config=MultiFieldTextFilter(
                   filter_fields=("username", "email"), operator="iregex")),
        Column("email", "Email", sortable=False, filter_config=TextFilter()),
        Column("is_superuser",
               "Is Superuser",
               display="superuser_display",
               filter_config=ChoicesFilter(choices=false_and_true())),
        Column("is_active",
               "Is Active",
               filter_config=ChoicesFilter(
                   choices=false_and_true)),  # `choices` callable
        Column("date_joined", "Date Joined", filter_config=DateRangeFilter())
    ]

    return Picotable(request=rf.get("/"),
                     columns=columns,
                     queryset=model.objects.all(),
                     context=PicoContext())
示例#4
0
class OrderListView(PicotableListView):
    model = Order
    columns = [
        Column("identifier", _(u"Order"), linked=True, filter_config=TextFilter(operator="startswith")),
        Column("order_date", _(u"Order Date"), display="format_order_date", filter_config=DateRangeFilter()),
        Column(
            "customer", _(u"Customer"),
            filter_config=MultiFieldTextFilter(filter_fields=("customer__email", "customer__name"))
        ),
        Column("status", _(u"Status"), filter_config=ChoicesFilter(choices=OrderStatus.objects.all())),
        Column("payment_status", _(u"Payment Status"), filter_config=ChoicesFilter(choices=PaymentStatus.choices)),
        Column("shipping_status", _(u"Shipping Status"), filter_config=ChoicesFilter(choices=ShippingStatus.choices)),
        Column(
            "taxful_total_price", _(u"Total"),
            display="format_taxful_total_price", class_name="text-right",
            filter_config=RangeFilter(field_type="number")
        ),
    ]

    def get_queryset(self):
        return super(OrderListView, self).get_queryset().exclude(deleted=True)

    def format_order_date(self, instance, *args, **kwargs):
        return format_datetime(localtime(instance.order_date), locale=get_current_babel_locale())

    def format_taxful_total_price(self, instance, *args, **kwargs):
        return escape(format_home_currency(instance.taxful_total_price))

    def get_object_abstract(self, instance, item):
        return [
            {"text": "%s" % instance, "class": "header"},
            {"title": _(u"Total"), "text": item["taxful_total_price"]},
            {"title": _(u"Status"), "text": item["status"]}
        ]
示例#5
0
def test_choice_filter_with_default(rf, admin_user, regular_user):
    columns = [
        Column("id", "Id", filter_config=Filter(), display=instance_id),
        Column("username",
               "Username",
               sortable=False,
               filter_config=MultiFieldTextFilter(filter_fields=("username",
                                                                 "email"),
                                                  operator="iregex")),
        Column("email", "Email", sortable=False, filter_config=TextFilter()),
        Column("is_superuser",
               "Is Superuser",
               display="superuser_display",
               filter_config=ChoicesFilter(choices=false_and_true())),
        Column("date_joined", "Date Joined", filter_config=DateRangeFilter())
    ]

    is_active = [
        Column("is_active",
               "Is Active",
               filter_config=ChoicesFilter(choices=false_and_true))
    ]
    is_active_with_default = [
        Column("is_active",
               "Is Active",
               filter_config=ChoicesFilter(choices=false_and_true,
                                           default=True))
    ]

    query = {"perPage": 100, "page": 1, "sort": "+id"}

    pico_no_defaults = get_pico(rf, columns=(columns + is_active))
    data = pico_no_defaults.get_data(query)
    user_data = data["items"][0]
    user = get_user_model().objects.get(id=user_data["id"])
    assert user.is_active

    pico_with_defaults = get_pico(rf,
                                  columns=(columns + is_active_with_default))
    data = pico_with_defaults.get_data(query)
    user_data = data["items"][0]
    user_with_defaults = get_user_model().objects.get(id=user_data["id"])
    assert user_with_defaults == user

    user.is_active = False
    user.save()

    data = pico_no_defaults.get_data(query)
    user_data = data["items"][0]
    new_user = get_user_model().objects.get(id=user_data["id"])
    assert new_user == user

    data = pico_with_defaults.get_data(query)
    user_data = data["items"][0]
    new_user_with_defaults = get_user_model().objects.get(id=user_data["id"])
    assert new_user_with_defaults != user_with_defaults
示例#6
0
class ContactListView(PicotableListView):
    model = Contact
    columns = [
        Column("name", _(u"Name"), linked=True, filter_config=TextFilter()),
        Column("type", _(u"Type"), display="get_type_display",
               sortable=False),  # TODO: Add a filter
        Column("email", _(u"Email"), filter_config=TextFilter()),
        Column("phone", _(u"Phone"), filter_config=TextFilter()),
        Column("is_active",
               _(u"Active"),
               filter_config=ChoicesFilter([(False, _("no")),
                                            (True, _("yes"))],
                                           default=True)),
        Column("n_orders",
               _(u"# Orders"),
               class_name="text-right",
               filter_config=RangeFilter(step=1)),
        Column("groups",
               _("Groups"),
               filter_config=ChoicesFilter(ContactGroup.objects.all(),
                                           "groups"))
    ]

    def get_queryset(self):
        groups = self.get_filter().get("groups")
        query = Q(groups__in=groups) if groups else Q()
        return super(ContactListView,
                     self).get_queryset().filter(query).annotate(
                         n_orders=Count("customer_orders"))

    def get_type_display(self, instance):
        if isinstance(instance, PersonContact):
            return _(u"Person")
        elif isinstance(instance, CompanyContact):
            return _(u"Company")
        else:
            return _(u"Contact")

    def get_object_abstract(self, instance, item):
        """
        :type instance: shoop.core.models.Contact
        """
        bits = filter(None, [
            item["type"],
            _("Active") if instance.is_active else _("Inactive"),
            _("Email: %s") % (instance.email or "\u2014"),
            _("Phone: %s") % (instance.phone or "\u2014"),
            _("%d orders") % instance.n_orders,
        ])
        return [{
            "text": instance.name or _("Contact"),
            "class": "header"
        }, {
            "text": ", ".join(bits)
        }]
示例#7
0
class ProductListView(PicotableListView):
    model = Product
    columns = [
        Column("sku", _(u"SKU"), display="sku", filter_config=TextFilter(placeholder=_("Filter by SKU..."))),
        Column("name", _(u"Name"), sort_field="translations__name", display="name", filter_config=TextFilter(
            filter_field="translations__name",
            placeholder=_("Filter by name...")
        )),
        Column("barcode", _(u"Barcode"), display="barcode", filter_config=TextFilter(_("Filter by barcode..."))),
        Column("type", _(u"Type")),
        Column("mode", _(u"Mode"), filter_config=ChoicesFilter(ProductMode.choices)),
        Column("category", _(u"Primary Category")),
    ]

    def get_queryset(self):
        filter = self.get_filter()
        shop_id = filter.get("shop")
        qs = Product.objects.all_except_deleted()
        q = Q()
        for mode in filter.get("modes", []):
            q = q | Q(mode=mode)
        qs = qs.filter(q)
        if shop_id:
            qs = qs.filter(shop_products__shop_id=int(shop_id))
        return qs

    def get_object_abstract(self, instance, item):
        return [
            {"text": "%s" % instance, "class": "header"},
            {"title": _(u"Barcode"), "text": item["barcode"]},
            {"title": _(u"SKU"), "text": item["sku"]},
            {"title": _(u"Type"), "text": item["type"]},
            {"title": _(u"Primary Category"), "text": item["category"]}
        ]
示例#8
0
文件: list.py 项目: sidaga/shoop
class ShopListView(PicotableListView):
    model = Shop
    columns = [
        Column("name", _(u"Name"), sort_field="translations__name", display="name", filter_config=TextFilter(
            filter_field="translations__name",
            placeholder=_("Filter by name...")
        )),
        Column("domain", _(u"Domain")),
        Column("identifier", _(u"Identifier")),
        Column("status", _(u"Status"), filter_config=ChoicesFilter(choices=ShopStatus.choices)),
    ]
示例#9
0
class CampaignListView(PicotableListView):
    columns = [
        Column("name",
               _(u"Title"),
               sort_field="name",
               display="name",
               linked=True,
               filter_config=TextFilter(operator="startswith")),
        Column("start_datetime", _("Starts")),
        Column("end_datetime", _("Ends")),
        Column("active",
               _("Active"),
               filter_config=ChoicesFilter(choices=[(0,
                                                     _("No")), (1,
                                                                _("Yes"))])),
    ]

    def start_datetime(self, instance, *args, **kwargs):
        if not instance.start_datetime:
            return ""
        return self._formatted_datetime(instance.start_datetime)

    def end_datetime(self, instance, *args, **kwargs):
        if not instance.end_datetime:
            return ""
        return self._formatted_datetime(instance.end_datetime)

    def _formatted_datetime(self, dt):
        return format_datetime(localtime(dt),
                               locale=get_current_babel_locale())

    def add_columns(self, column_id, columns, after=True):
        # TODO: Make better
        added = False
        for idx, column in enumerate(self.columns):
            if column.id == column_id:
                found_idx = idx + 1 if after else idx
                start = self.columns[:found_idx]
                end = self.columns[found_idx:]
                self.columns = start + columns + end
                added = True
                break

        if not added:
            self.columns += columns

    def get_object_abstract(self, instance, item):
        return [
            {
                "text": "%s" % (instance or _("CatalogCampaign")),
                "class": "header"
            },
        ]
示例#10
0
文件: list.py 项目: itsrashad/shoop
class _BaseMethodListView(PicotableListView):
    model = None  # Overridden below
    columns = [
        Column("name", _(u"Name"), sort_field="translations__name", filter_config=TextFilter(
            filter_field="name",
            placeholder=_("Filter by name...")
        )),
        Column("status", _(u"Status"), filter_config=ChoicesFilter(choices=MethodStatus.choices)),
    ]

    def get_object_abstract(self, instance, item):
        return [
            {"text": "%s" % instance, "class": "header"},
            {"title": _(u"Status"), "text": item["status"]}
        ]
示例#11
0
class ShopListView(PicotableListView):
    model = Shop
    columns = [
        Column("name",
               _(u"Name"),
               sort_field="translations__name",
               display="name",
               filter_config=TextFilter(filter_field="translations__name",
                                        placeholder=_("Filter by name..."))),
        Column("domain", _(u"Domain")),
        Column("identifier", _(u"Identifier")),
        Column("status",
               _(u"Status"),
               filter_config=ChoicesFilter(choices=ShopStatus.choices)),
    ]

    def get_toolbar(self):
        if settings.SHOOP_ENABLE_MULTIPLE_SHOPS:
            return super(ShopListView, self).get_toolbar()
        else:
            return Toolbar([])
示例#12
0
class UserListView(PicotableListView):
    model = settings.AUTH_USER_MODEL
    columns = [
        Column("username", _(u"Username"), filter_config=TextFilter()),
        Column("email", _(u"Email"), filter_config=TextFilter()),
        Column("first_name", _(u"First Name"), filter_config=TextFilter()),
        Column("last_name", _(u"Last Name"), filter_config=TextFilter()),
        Column(
            "is_active",
            _(u"Active"),
            filter_config=ChoicesFilter([(False, _("no")), (True, _("yes"))], default=True)
        ),
        Column("is_staff", _(u"Staff"), filter_config=true_or_false_filter),
        Column("is_superuser", _(u"Superuser"), filter_config=true_or_false_filter),
    ]

    def get_model(self):
        return get_user_model()

    def get_queryset(self):
        return self.get_model().objects.all()

    def get_context_data(self, **kwargs):
        context = super(UserListView, self).get_context_data(**kwargs)
        context["title"] = force_text(self.get_model()._meta.verbose_name_plural).title()
        return context

    def get_object_abstract(self, instance, item):
        bits = filter(None, [
            _("First Name: %s") % (getattr(instance, 'first_name', None) or "\u2014"),
            _("Last Name: %s") % (getattr(instance, 'last_name', None) or "\u2014"),
            _("Active") if instance.is_active else _(u"Inactive"),
            _("Email: %s") % (getattr(instance, 'email', None) or "\u2014"),
            _("Staff") if getattr(instance, 'is_staff', None) else None,
            _("Superuser") if getattr(instance, 'is_superuser', None) else None
        ])
        return [
            {"text": instance.get_username() or _("User"), "class": "header"},
            {"text": ", ".join(bits)}
        ]
示例#13
0
文件: list.py 项目: sidaga/shoop
class ProductListView(PicotableListView):
    model = Product
    columns = [
        Column("sku",
               _(u"SKU"),
               display="sku",
               filter_config=TextFilter(placeholder=_("Filter by SKU..."))),
        Column("name",
               _(u"Name"),
               sort_field="translations__name",
               display="name",
               filter_config=TextFilter(filter_field="translations__name",
                                        placeholder=_("Filter by name..."))),
        Column("type", _(u"Type")),
        Column("mode",
               _(u"Mode"),
               filter_config=ChoicesFilter(ProductMode.choices)),
        Column("category", _(u"Primary Category")),
    ]

    def get_queryset(self):
        return Product.objects.all_except_deleted()

    def get_object_abstract(self, instance, item):
        return [{
            "text": "%s" % instance,
            "class": "header"
        }, {
            "title": _(u"SKU"),
            "text": item["sku"]
        }, {
            "title": _(u"Type"),
            "text": item["type"]
        }, {
            "title": _(u"Primary Category"),
            "text": item["category"]
        }]
示例#14
0
class StocksListView(PicotableListView):
    template_name = "shoop/simple_supplier/admin/base_picotable.jinja"
    model = Product
    columns = [
        Column("sku",
               _("SKU"),
               sort_field="product__sku",
               display="product__sku",
               linked=True,
               filter_config=TextFilter(filter_field="product__sku",
                                        placeholder=_("Filter by SKU..."))),
        Column("name",
               _("Name"),
               sort_field="product__translations__name",
               display="product__name",
               linked=True,
               filter_config=TextFilter(
                   filter_field="product__translations__name",
                   placeholder=_("Filter by name..."))),
        Column(
            "supplier",
            _("Supplier"),
            display="supplier",
            linked=False,
            filter_config=ChoicesFilter(
                Supplier.objects.filter(module_identifier="simple_supplier"))),
        Column("stock_information",
               _("Stock information"),
               display="get_stock_information",
               linked=False,
               sortable=False,
               raw=True),
        Column("adjust_stock",
               _("Adjust stock"),
               display="get_stock_adjustment_form",
               sortable=False,
               linked=False,
               raw=True)
    ]

    def get_object_abstract(self, instance, item):
        item.update({
            "_linked_in_mobile": False,
            "_url": self.get_object_url(instance.product)
        })
        return [
            {
                "text": item["name"],
                "class": "header"
            },
            {
                "title": "",
                "text": item["sku"]
            },
            {
                "title": "",
                "text": " ",
                "raw": item["stock_information"]
            },
            {
                "title": "",
                "text": " ",
                "raw": item["adjust_stock"]
            },
        ]

    def get_queryset(self):
        return StockCount.objects.filter(
            supplier__module_identifier="simple_supplier",
            product__stock_behavior=StockBehavior.STOCKED).order_by(
                "product__id")

    def get_context_data(self, **kwargs):
        context = super(PicotableListView, self).get_context_data(**kwargs)
        context["toolbar"] = None
        context["title"] = _("Stock management")
        return context

    def get_stock_information(self, instance):
        return get_stock_information_html(instance.supplier, instance.product)

    def get_stock_adjustment_form(self, instance):
        return get_stock_adjustment_div(self.request, instance.supplier,
                                        instance.product)
示例#15
0
文件: _list.py 项目: teserak/shoop
class CartListView(PicotableListView):
    model = StoredBasket
    columns = [
        Column("created_on",
               _(u"Created on"),
               display="format_created_date",
               filter_config=DateRangeFilter()),
        Column("updated_on",
               _(u"Last updated on"),
               display="format_updated_date",
               filter_config=DateRangeFilter()),
        Column("finished",
               _("Abandoned"),
               display="format_abandoned_status",
               filter_config=ChoicesFilter([(False, _("yes")),
                                            (True, _("no"))])),
        Column("shop",
               _("Shop"),
               filter_config=ChoicesFilter(choices=Shop.objects.all())),
        Column("product_count",
               _("Product count"),
               filter_config=RangeFilter()),
        Column("customer",
               _(u"Customer"),
               filter_config=MultiFieldTextFilter(
                   filter_fields=("customer__email", "customer__name"))),
        Column("orderer",
               _(u"Orderer"),
               filter_config=MultiFieldTextFilter(
                   filter_fields=("orderer__email", "orderer__name"))),
        Column("taxful_total_price",
               _(u"Total"),
               sort_field="taxful_total_price_value",
               display="format_taxful_total_price",
               class_name="text-right",
               filter_config=RangeFilter(
                   field_type="number",
                   filter_field="taxful_total_price_value")),
    ]

    def get_queryset(self):
        """
        Ignore potentially active carts, displaying only those not updated for at least 2 hours.
        """
        cutoff = now() - datetime.timedelta(hours=2)
        filters = {"updated_on__lt": cutoff, "product_count__gte": 0}
        return super(CartListView, self).get_queryset().filter(**filters)

    def format_abandoned_status(self, instance, *args, **kwargs):
        return "yes" if not instance.finished else "no"

    def format_created_date(self, instance, *args, **kwargs):
        return get_locally_formatted_datetime(instance.created_on)

    def format_updated_date(self, instance, *args, **kwargs):
        return get_locally_formatted_datetime(instance.updated_on)

    def format_taxful_total_price(self, instance, *args, **kwargs):
        return escape(format_money(instance.taxful_total_price))

    def get_context_data(self, **kwargs):
        context = super(CartListView, self).get_context_data(**kwargs)
        context["title"] = _("Carts")
        return context

    def get_object_abstract(self, instance, item):
        return [
            {
                "text": "%s" % instance,
                "class": "header"
            },
            {
                "title": _(u"Created on"),
                "text": item["created_on"]
            },
            {
                "title": _(u"Last updated on"),
                "text": item["updated_on"]
            },
            {
                "title": _(u"Ordered"),
                "text": item["finished"]
            },
            {
                "title": _(u"Total"),
                "text": item["taxful_total_price"]
            },
        ]