예제 #1
0
 def get_context_data(self, **kwargs):
     shop = Shop.objects.first()
     context = super(ConsolidateSampleObjectsView,
                     self).get_context_data(**kwargs)
     context["has_installed_sample"] = sample_manager.has_installed_samples(
         shop)
     context["title"] = _("Sample Data")
     return context
예제 #2
0
    def form_valid(self, form):
        current_language = translation.get_language()
        default_language = getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE",
                                   None)

        # change the language to the PARLER_DEFAULT_LANGUAGE
        # so sample data will have data on fallback languages
        if default_language:
            translation.activate(default_language)

        shop = self.object
        form_data = form["sample"].cleaned_data
        business_segment = form_data["business_segment"]

        current_categories = sample_manager.get_installed_categories(shop)
        current_products = sample_manager.get_installed_products(shop)
        current_carousel = sample_manager.get_installed_carousel(shop)

        # only saves the business segment if there is no data installed
        # otherwise user can't change the segment
        if sample_manager.has_installed_samples(shop):
            business_segment = sample_manager.get_installed_business_segment(
                shop)
        else:
            sample_manager.save_business_segment(shop, business_segment)

        # user wants to install sample categories
        if form_data.get("categories", False) and not current_categories:
            categories = self._create_sample_categories(shop, business_segment)
            if categories:
                sample_manager.save_categories(shop, categories)

        # user wants to install sample products
        if form_data.get("products", False) and not current_products:
            products = self._create_sample_products(shop, business_segment)
            if products:
                sample_manager.save_products(shop, products)

        # user wants a carousel
        if form_data.get("carousel") and not current_carousel:
            carousel = self._create_sample_carousel(shop, business_segment)
            if carousel:
                sample_manager.save_carousel(shop, carousel.pk)

        # back to current language
        translation.activate(current_language)

        # user will no longer see this pane
        configuration.set(None, "sample_data_wizard_completed", True)

        # reindex the product catalog
        call_command("reindex_product_catalog")
예제 #3
0
def test_sample_data_manager():
    shop = get_default_shop()
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False

    BUSINESS_SEG = "default"
    PRODUCTS = [1, 2, 3]
    CATEGORIES = [4, 5, 6]
    CAROUSEL = 1

    manager.save_categories(shop, CATEGORIES)
    manager.save_products(shop, PRODUCTS)
    manager.save_carousel(shop, CAROUSEL)
    manager.save_business_segment(shop, BUSINESS_SEG)

    assert manager.get_installed_business_segment(shop) == BUSINESS_SEG
    assert manager.get_installed_products(shop) == PRODUCTS
    assert manager.get_installed_categories(shop) == CATEGORIES
    assert manager.get_installed_carousel(shop) == CAROUSEL
    assert manager.has_installed_samples(shop) is True

    new_shop = Shop.objects.create()
    assert manager.get_installed_business_segment(new_shop) is None
    assert manager.get_installed_products(new_shop) == []
    assert manager.get_installed_categories(new_shop) == []
    assert manager.get_installed_carousel(new_shop) is None
    assert manager.has_installed_samples(new_shop) is False

    manager.clear_installed_samples(shop)
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False
예제 #4
0
def test_sample_data_manager():
    shop = get_default_shop()
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False

    BUSINESS_SEG = "default"
    PRODUCTS = [1, 2, 3]
    CATEGORIES = [4, 5, 6]
    CAROUSEL = 1

    manager.save_categories(shop, CATEGORIES)
    manager.save_products(shop, PRODUCTS)
    manager.save_carousel(shop, CAROUSEL)
    manager.save_business_segment(shop, BUSINESS_SEG)

    assert manager.get_installed_business_segment(shop) == BUSINESS_SEG
    assert manager.get_installed_products(shop) == PRODUCTS
    assert manager.get_installed_categories(shop) == CATEGORIES
    assert manager.get_installed_carousel(shop) == CAROUSEL
    assert manager.has_installed_samples(shop) is True

    new_shop = Shop.objects.create()
    assert manager.get_installed_business_segment(new_shop) is None
    assert manager.get_installed_products(new_shop) == []
    assert manager.get_installed_categories(new_shop) == []
    assert manager.get_installed_carousel(new_shop) is None
    assert manager.has_installed_samples(new_shop) is False

    manager.clear_installed_samples(shop)
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False
예제 #5
0
파일: views.py 프로젝트: ruqaiya/shuup
    def form_valid(self, form):
        current_language = translation.get_language()
        default_language = getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None)

        # change the language to the PARLER_DEFAULT_LANGUAGE
        # so sample data will have data on fallback languages
        if default_language:
            translation.activate(default_language)

        shop = self.object
        form_data = form["sample"].cleaned_data
        business_segment = form_data["business_segment"]

        current_categories = sample_manager.get_installed_categories(shop)
        current_products = sample_manager.get_installed_products(shop)
        current_carousel = sample_manager.get_installed_carousel(shop)

        # only saves the business segment if there is no data installed
        # otherwise user can't change the segment
        if sample_manager.has_installed_samples(shop):
            business_segment = sample_manager.get_installed_business_segment(shop)
        else:
            sample_manager.save_business_segment(shop, business_segment)

        # user wants to install sample categories
        if form_data.get("categories", False) and not current_categories:
            categories = self._create_sample_categories(shop, business_segment)
            if categories:
                sample_manager.save_categories(shop, categories)

        # user wants to install sample products
        if form_data.get("products", False) and not current_products:
            products = self._create_sample_products(shop, business_segment)
            if products:
                sample_manager.save_products(shop, products)

        # user wants a carousel
        if form_data.get("carousel") and not current_carousel:
            carousel = self._create_sample_carousel(shop, business_segment)
            if carousel:
                sample_manager.save_carousel(shop, carousel.pk)

        # back to current language
        translation.activate(current_language)

        # user will no longer see this pane
        configuration.set(None, "sample_data_wizard_completed", True)
예제 #6
0
파일: __init__.py 프로젝트: ruqaiya/shuup
    def get_notifications(self, request):
        """ Injects a message to the user and also a notification """
        # multi-shop not supported
        if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            from shuup.admin.shop_provider import get_shop
            shop = get_shop(request)

            if sample_manager.has_installed_samples(shop):
                messages.warning(request, _('There is sample data installed. '
                                            'Access "Settings > Sample Data" for more information.'))

                yield Notification(
                    _("There is sample data installed. Click here to consolidate or delete them."),
                    title=_("Sample Data"),
                    kind="warning",
                    url="shuup_admin:sample_data"
                )
예제 #7
0
    def get_notifications(self, request):
        """ Injects a message to the user and also a notification """
        # multi-shop not supported
        if not ShuupSettings.get_setting("SHUUP_ENABLE_MULTIPLE_SHOPS"):
            from shuup.admin.shop_provider import get_shop
            shop = get_shop(request)

            if sample_manager.has_installed_samples(shop):
                messages.warning(
                    request,
                    _("There is a sample data installed. "
                      "Search `Sample Data` for more information."))

                yield Notification(_(
                    "There is a sample data installed. Click here to consolidate or delete them."
                ),
                                   title=_("Sample Data"),
                                   kind="warning",
                                   url="shuup_admin:sample_data")
예제 #8
0
파일: views.py 프로젝트: ruqaiya/shuup
 def get_context_data(self, **kwargs):
     shop = Shop.objects.first()
     context = super(ConsolidateSampleObjectsView, self).get_context_data(**kwargs)
     context["has_installed_sample"] = sample_manager.has_installed_samples(shop)
     context["title"] = _("Sample Data")
     return context