def get_shop_overview_block(request, currency, for_date=None): end = to_aware(for_date, time=time.max) if for_date else local_now() start_of_day = to_aware(end.date(), time=time.min) start_of_month = start_of_day.replace(day=1) start_of_year = start_of_day.replace(month=1, day=1) shop = request.shop if not currency: currency = shop.currency daily = get_order_overview_for_date_range(currency, start_of_day, end, shop=shop) mtd = get_order_overview_for_date_range(currency, start_of_month, end, shop=shop) ytd = get_order_overview_for_date_range(currency, start_of_year, end) totals = get_orders_by_currency(currency).complete().aggregate( num_orders=Count("id"), num_customers=Count("customer", distinct=True), sales=Sum("taxful_total_price_value") ) anon_orders = get_orders_by_currency(currency).complete().filter(customer__isnull=True, shop=shop).aggregate( num_orders=Count("id")) totals["num_customers"] += anon_orders["num_orders"] totals["sales"] = TaxfulPrice(totals["sales"] or 0, currency) block = DashboardContentBlock.by_rendering_template( "store_overview", request, "shuup/admin/sales_dashboard/_store_overview_dashboard_block.jinja", { "daily": daily, "mtd": mtd, "ytd": ytd, "totals": totals }) block.size = "medium" return block
def get_shop_overview_block(request, currency): today = date.today() start_of_month = date(today.year, today.month, 1) start_of_year = date(today.year, 1, 1) daily = get_order_overview_for_date_range(currency, today, today) mtd = get_order_overview_for_date_range(currency, start_of_month, today) ytd = get_order_overview_for_date_range(currency, start_of_year, today) totals = get_orders_by_currency(currency).complete().aggregate( num_orders=Count("id"), num_customers=Count("customer", distinct=True), sales=Sum("taxful_total_price_value") ) anon_orders = get_orders_by_currency(currency).complete().filter(customer__isnull=True).aggregate( num_orders=Count("id")) totals["num_customers"] += anon_orders["num_orders"] totals["sales"] = TaxfulPrice(totals["sales"] or 0, currency) block = DashboardContentBlock.by_rendering_template( "store_overview", request, "shuup/admin/sales_dashboard/_store_overview_dashboard_block.jinja", { "daily": daily, "mtd": mtd, "ytd": ytd, "totals": totals }) block.size = "small" return block
def _get_support_block(self, request): support_block = DashboardContentBlock.by_rendering_template( "support", request, "shuup/admin/support/_support_dashboard_block.jinja", {}) support_block.size = "medium" support_block.sort_order = 3 return [support_block]
def get_shop_overview_block(request, currency, for_date=None): end = to_aware(for_date, time=time.max) if for_date else local_now() start_of_day = to_aware(end.date(), time=time.min) start_of_month = start_of_day.replace(day=1) start_of_year = start_of_day.replace(month=1, day=1) daily = get_order_overview_for_date_range(currency, start_of_day, end) mtd = get_order_overview_for_date_range(currency, start_of_month, end) ytd = get_order_overview_for_date_range(currency, start_of_year, end) totals = get_orders_by_currency(currency).complete().aggregate( num_orders=Count("id"), num_customers=Count("customer", distinct=True), sales=Sum("taxful_total_price_value") ) anon_orders = get_orders_by_currency(currency).complete().filter(customer__isnull=True).aggregate( num_orders=Count("id")) totals["num_customers"] += anon_orders["num_orders"] totals["sales"] = TaxfulPrice(totals["sales"] or 0, currency) block = DashboardContentBlock.by_rendering_template( "store_overview", request, "shuup/admin/sales_dashboard/_store_overview_dashboard_block.jinja", { "daily": daily, "mtd": mtd, "ytd": ytd, "totals": totals }) block.size = "small" return block
def test_content_block_template(rf): TEMPLATES = get_templates_setting_for_specific_directories(settings.TEMPLATES, [TEMPLATES_DIR]) with override_settings(TEMPLATES=TEMPLATES): request = rf.get("/") dcb = DashboardContentBlock.by_rendering_template("foo", request, "module_template.jinja", { "name": "world" }) assert dcb.content == "Hello world"
def test_content_block_template(rf): TEMPLATES = get_templates_setting_for_specific_directories( settings.TEMPLATES, [TEMPLATES_DIR]) with override_settings(TEMPLATES=TEMPLATES): request = rf.get("/") dcb = DashboardContentBlock.by_rendering_template( "foo", request, "module_template.jinja", {"name": "world"}) assert dcb.content == "Hello world"
def _get_article_block(self, request): articles = self._get_resource(request, "articles") if articles.get("articles"): article_block = DashboardContentBlock.by_rendering_template( "articles", request, "shuup/admin/support/_articles_dashboard_block.jinja", articles) article_block.size = "small" return [article_block] return []
def _get_faq_block(self, request): faqs = self._get_resource(request, "faq") if faqs.get("faqs"): faq_block = DashboardContentBlock.by_rendering_template( "faq", request, "shuup/admin/support/_faq_dashboard_block.jinja", faqs) faq_block.size = "small" return [faq_block] return []
def get_recent_orders_block(request, currency=None): orders = get_orders_for_shop(request).valid().order_by("-order_date")[:5] block = DashboardContentBlock.by_rendering_template( "recent_orders", request, "shuup/admin/sales_dashboard/_recent_orders_dashboard_block.jinja", {"orders": orders}) block.size = "medium" return block
def get_recent_orders_block(request, currency): orders = get_orders_by_currency(currency).valid().order_by("-order_date")[:5] block = DashboardContentBlock.by_rendering_template( "recent_orders", request, "shuup/admin/sales_dashboard/_recent_orders_dashboard_block.jinja", { "orders": orders } ) block.size = "small" return block
def get_recent_orders_block(request, currency=None): orders = get_orders_for_shop(request).valid().order_by("-order_date")[:5] block = DashboardContentBlock.by_rendering_template( "recent_orders", request, "shuup/admin/sales_dashboard/_recent_orders_dashboard_block.jinja", { "orders": orders } ) block.size = "medium" block.sort_order = 2 return block
def get_dashboard_blocks(self, request): return [ DashboardContentBlock(id="test-0", content="Hello", size="invalid"), DashboardValueBlock(id="test-1", value="yes", title="hi"), DashboardNumberBlock(id="test-2", value=35, title="hello"), DashboardNumberBlock(id="test-3", value=35.3, title="hello"), DashboardMoneyBlock(id="test-4", value=35, title="hola", currency="USD"), ]
def get_dashboard_blocks(self, request): """ Return the latest 10 pending tasks """ contact = get_person_contact(request.user) tasks = (Task.objects.for_shop( get_shop(request)).assigned_to(contact).exclude( status__in=(TaskStatus.DELETED, TaskStatus.COMPLETED)).order_by("-priority"))[:10] if tasks.exists(): tasks_block = DashboardContentBlock.by_rendering_template( "articles", request, "shuup/admin/tasks/tasks_dashboard_block.jinja", context=dict(tasks=tasks)) tasks_block.size = "medium" yield tasks_block
def get_dashboard_blocks(self, request): """ Return the latest 10 pending tasks """ contact = get_person_contact(request.user) tasks = ( Task.objects.for_shop(get_shop(request)) .assigned_to(contact) .exclude(status__in=(TaskStatus.DELETED, TaskStatus.COMPLETED)) .order_by("-priority") )[:10] if tasks.exists(): tasks_block = DashboardContentBlock.by_rendering_template( "articles", request, "shuup/admin/tasks/tasks_dashboard_block.jinja", context=dict(tasks=tasks) ) tasks_block.size = "medium" yield tasks_block