def test_layout_api(): l = Layout(FauxTheme, "test") l.begin_column({"md": 8}) px0y0 = l.add_plugin("text", {"text": "yes"}) l.begin_column({"md": 4}) px1y0 = l.add_plugin("text", {"text": "no"}) assert len(l) == 1 assert len(l.rows[0]) == 2 assert not l.delete_cell(x=0, y=1) # nonexistent row assert l.get_cell(0, 0) == px0y0 assert l.get_cell(1, 0) == px1y0 assert not l.get_cell(2, 0) assert not l.get_cell(0, 1) l.begin_row() assert len(l) == 2 assert len(l.rows[1]) == 0 l.begin_column() assert len(l.rows[1]) == 1 assert l.delete_cell(x=0, y=1) # existent cell assert not l.delete_cell(x=0, y=1) # cell existent no more assert l.delete_row(1) # existent row assert len(l) == 1 assert not l.delete_row(1) # nonexistent row l.insert_row(0).add_cell() # insert a cellful row in first place assert len(l) == 2 and list(map(len, l.rows)) == [1, 2] l.insert_row(1) # insert an empty row in second place assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2] assert not l.insert_row(-1) # that's silly!
def _handle_xtheme_save(self): svc_pk = config.get(self.shop, CONTENT_FOOTER_KEY) svc = SavedViewConfig.objects.filter(pk=svc_pk).first() theme = get_current_theme(self.shop) if not svc and theme: context = {"shop": self.shop} rendered_content = template_loader.render_to_string(content_data.FOOTER_TEMPLATE, context).strip() layout = Layout(theme, "footer-bottom") # adds the footer template layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(SnippetsPlugin.identifier, {"in_place": rendered_content}) svc = SavedViewConfig( theme_identifier=theme.identifier, shop=self.shop, view_name=XTHEME_GLOBAL_VIEW_NAME, status=SavedViewConfigStatus.CURRENT_DRAFT ) svc.set_layout_data(layout.placeholder_name, layout) svc.save() svc.publish() config.set(self.shop, CONTENT_FOOTER_KEY, svc.pk)
def test_layout_api(): l = Layout(FauxTheme, "test") l.begin_column({"md": 8}) px0y0 = l.add_plugin("text", {"text": "yes"}) l.begin_column({"md": 4}) px1y0 = l.add_plugin("text", {"text": "no"}) assert len(l) == 1 assert len(l.rows[0]) == 2 assert not l.delete_cell(x=0, y=1) # nonexistent row assert l.get_cell(0, 0) == px0y0 assert l.get_cell(1, 0) == px1y0 assert not l.get_cell(2, 0) assert not l.get_cell(0, 1) l.begin_row() assert len(l) == 2 assert len(l.rows[1]) == 0 l.begin_column() assert len(l.rows[1]) == 1 assert l.delete_cell(x=0, y=1) # existent cell assert not l.delete_cell(x=0, y=1) # cell existent no more assert l.delete_row(1) # existent row assert len(l) == 1 assert not l.delete_row(1) # nonexistent row l.insert_row(0).add_cell() # insert a cellful row in first place assert len(l) == 2 and list(map(len, l.rows)) == [1, 2] l.insert_row(1) # insert an empty row in second place assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2] assert not l.insert_row(-1) # that's silly!
def test_layout_api(): l = Layout(FauxTheme, "test") l.begin_column({"md": 8}) px0y0 = l.add_plugin("text", {"text": "yes"}) l.begin_column({"md": 4}) px1y0 = l.add_plugin("text", {"text": "no"}) assert len(l) == 1 assert len(l.rows[0]) == 2 assert not l.delete_cell(x=0, y=1) # nonexistent row assert l.get_cell(0, 0) == px0y0 assert l.get_cell(1, 0) == px1y0 assert not l.get_cell(2, 0) assert not l.get_cell(0, 1) l.begin_row() assert len(l) == 2 assert len(l.rows[1]) == 0 l.begin_column() assert len(l.rows[1]) == 1 assert l.delete_cell(x=0, y=1) # existent cell assert not l.delete_cell(x=0, y=1) # cell existent no more assert l.delete_row(1) # existent row assert len(l) == 1 assert not l.delete_row(1) # nonexistent row l.insert_row(0).add_cell() # insert a cellful row in first place assert len(l) == 2 and list(map(len, l.rows)) == [1, 2] l.insert_row(1) # insert an empty row in second place assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2] assert not l.insert_row(-1) # that's silly! assert l.move_row_to_index(0, 1) assert len(l) == 3 and list(map(len, l.rows)) == [0, 1, 2] assert l.move_row_to_index(2, 0) assert len(l) == 3 and list(map(len, l.rows)) == [2, 0, 1] assert not l.move_row_to_index(1, 100) assert len(l) == 3 and list(map(len, l.rows)) == [2, 0, 1] assert not l.move_row_to_index(1, -1) assert len(l) == 3 and list(map(len, l.rows)) == [2, 0, 1] cell = l.get_cell(0, 0) # top left to bottom right assert l.move_cell_to_position(0, 0, 1, 2) assert l.get_cell(1, 2) == cell assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2] cell = l.get_cell(0, 0) # top left to middle assert l.move_cell_to_position(0, 0, 0, 1) assert l.get_cell(0, 0) == cell assert len(l) == 2 and list(map(len, l.rows)) == [1, 2] # invalid cell assert not l.move_cell_to_position(0, 100, 0, 1) # move to invalid cell assert not l.move_cell_to_position(0, 0, 100, 1)
def test_layout_api(): l = Layout(FauxTheme, "test") l.begin_column({"md": 8}) px0y0 = l.add_plugin("text", {"text": "yes"}) l.begin_column({"md": 4}) px1y0 = l.add_plugin("text", {"text": "no"}) assert len(l) == 1 assert len(l.rows[0]) == 2 assert not l.delete_cell(x=0, y=1) # nonexistent row assert l.get_cell(0, 0) == px0y0 assert l.get_cell(1, 0) == px1y0 assert not l.get_cell(2, 0) assert not l.get_cell(0, 1) l.begin_row() assert len(l) == 2 assert len(l.rows[1]) == 0 l.begin_column() assert len(l.rows[1]) == 1 assert l.delete_cell(x=0, y=1) # existent cell assert not l.delete_cell(x=0, y=1) # cell existent no more assert l.delete_row(1) # existent row assert len(l) == 1 assert not l.delete_row(1) # nonexistent row l.insert_row(0).add_cell() # insert a cellful row in first place assert len(l) == 2 and list(map(len, l.rows)) == [1, 2] l.insert_row(1) # insert an empty row in second place assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2] assert not l.insert_row(-1) # that's silly! assert l.move_row_to_index(0, 1) assert len(l) == 3 and list(map(len, l.rows)) == [0, 1, 2] assert l.move_row_to_index(2, 0) assert len(l) == 3 and list(map(len, l.rows)) == [2, 0, 1] assert not l.move_row_to_index(1, 100) assert len(l) == 3 and list(map(len, l.rows)) == [2, 0, 1] assert not l.move_row_to_index(1, -1) assert len(l) == 3 and list(map(len, l.rows)) == [2, 0, 1] cell = l.get_cell(0, 0) # top left to bottom right assert l.move_cell_to_position(0, 0, 1, 2) assert l.get_cell(1, 2) == cell assert len(l) == 3 and list(map(len, l.rows)) == [1, 0, 2] cell = l.get_cell(0, 0) # top left to middle assert l.move_cell_to_position(0, 0, 0, 1) assert l.get_cell(0, 0) == cell assert len(l) == 2 and list(map(len, l.rows)) == [1, 2] # invalid cell assert not l.move_cell_to_position(0, 100, 0, 1) # move to invalid cell assert not l.move_cell_to_position(0, 0, 100, 1)
def _create_sample_carousel(cls, shop, business_segment): """ Create the sample carousel for the given business_segment and also injects it to the default theme currently being used in front """ if business_segment not in BUSINESS_SEGMENTS: return None carousel_data = BUSINESS_SEGMENTS[business_segment]["carousel"] carousel = create_sample_carousel(carousel_data, business_segment, shop) # injects the carousel plugin with in the front_content placeholder # this will only works if the theme have this placeholder, we expect so if 'shuup.xtheme' in settings.INSTALLED_APPS: from shuup.front.apps.carousel.plugins import CarouselPlugin from shuup.xtheme.plugins.products import ProductHighlightPlugin from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus from shuup.xtheme.layout import Layout from shuup.xtheme._theme import get_current_theme theme = get_current_theme(shop) if theme: layout = Layout(theme, "front_content") # adds the carousel layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk}) # adds some products layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(ProductHighlightPlugin.identifier, {}) svc = SavedViewConfig( theme_identifier=theme.identifier, shop=shop, view_name="IndexView", status=SavedViewConfigStatus.CURRENT_DRAFT) svc.set_layout_data(layout.placeholder_name, layout) svc.save() svc.publish() return carousel
def _create_sample_carousel(cls, shop, business_segment): """ Create the sample carousel for the given business_segment and also injects it to the default theme currently being used in front """ if business_segment not in BUSINESS_SEGMENTS: return None carousel_data = BUSINESS_SEGMENTS[business_segment]["carousel"] carousel = create_sample_carousel(carousel_data, business_segment, shop) # injects the carousel plugin with in the front_content placeholder # this will only works if the theme have this placeholder, we expect so if 'shuup.xtheme' in settings.INSTALLED_APPS: from shuup.front.apps.carousel.plugins import CarouselPlugin from shuup.xtheme.plugins.products import ProductHighlightPlugin from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus from shuup.xtheme.layout import Layout from shuup.xtheme._theme import get_current_theme theme = get_current_theme(shop) if theme: layout = Layout(theme, "front_content") # adds the carousel layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk}) # adds some products layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(ProductHighlightPlugin.identifier, {}) svc = SavedViewConfig( theme_identifier=theme.identifier, shop=shop, view_name="IndexView", status=SavedViewConfigStatus.CURRENT_DRAFT ) svc.set_layout_data(layout.placeholder_name, layout) svc.save() svc.publish() return carousel
def test_carousel_custom_colors(rf): from shuup.front.apps.carousel.plugins import CarouselPlugin from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus from shuup.xtheme.layout import Layout from shuup.xtheme._theme import get_current_theme from django.core.urlresolvers import reverse shop = get_default_shop() shop.maintenance_mode = False shop.save() carousel = Carousel.objects.create(name="test") carousel.shops.add(shop) test_image = Image.objects.create(original_filename="slide.jpg") test_slide = Slide.objects.create( carousel=carousel, name="test", available_from=(datetime.now() - timedelta(days=1)), image=test_image, target=LinkTargetType.CURRENT ) theme = get_current_theme(shop) # adds the carousel to the front page layout = Layout(theme, "front_content") layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk}) svc = SavedViewConfig( theme_identifier=theme.identifier, shop=shop, view_name="IndexView", status=SavedViewConfigStatus.CURRENT_DRAFT ) svc.set_layout_data(layout.placeholder_name, layout) svc.save() svc.publish() client = Client() # no customized color response = client.get(reverse("shuup:index")) content = response.content.decode("utf-8") assert "owl-carousel" in content assert ".owl-nav .owl-prev" not in content assert ".owl-nav .owl-next" not in content assert ".owl-dot:nth-child(" not in content # put colors in arrows carousel.arrows_color = "#ffaabb" carousel.save() response = client.get(reverse("shuup:index")) content = response.content.decode("utf-8") assert ".owl-nav .owl-prev" in content assert ".owl-nav .owl-next" in content assert "color: #ffaabb !important;" in content # put custom color in dots test_slide.inactive_dot_color = "#a1b2c3" test_slide.active_dot_color = "#d4e4f6" test_slide.save() response = client.get(reverse("shuup:index")) content = response.content.decode("utf-8") assert ".owl-dot:nth-child(1)" in content assert "border-color: #a1b2c3 !important" in content assert "background-color: #d4e4f6 !important;" in content
def test_carousel_custom_colors(rf): from shuup.front.apps.carousel.plugins import CarouselPlugin from shuup.utils.django_compat import reverse from shuup.xtheme._theme import get_current_theme from shuup.xtheme.layout import Layout from shuup.xtheme.models import SavedViewConfig, SavedViewConfigStatus shop = get_default_shop() shop.maintenance_mode = False shop.save() carousel = Carousel.objects.create(name="test") carousel.shops.add(shop) test_image = Image.objects.create(original_filename="slide.jpg") test_slide = Slide.objects.create( carousel=carousel, name="test", available_from=(datetime.now() - timedelta(days=1)), image=test_image, target=LinkTargetType.CURRENT, ) theme = get_current_theme(shop) # adds the carousel to the front page layout = Layout(theme, "front_content") layout.begin_row() layout.begin_column({"md": 12}) layout.add_plugin(CarouselPlugin.identifier, {"carousel": carousel.pk}) svc = SavedViewConfig( theme_identifier=theme.identifier, shop=shop, view_name="IndexView", status=SavedViewConfigStatus.CURRENT_DRAFT ) svc.set_layout_data(layout.placeholder_name, layout) svc.save() svc.publish() client = Client() # no customized color response = client.get(reverse("shuup:index")) content = response.content.decode("utf-8") assert "owl-carousel" in content assert ".owl-nav .owl-prev" not in content assert ".owl-nav .owl-next" not in content assert ".owl-dot:nth-child(" not in content # put colors in arrows carousel.arrows_color = "#ffaabb" carousel.save() response = client.get(reverse("shuup:index")) content = response.content.decode("utf-8") assert ".owl-nav .owl-prev" in content assert ".owl-nav .owl-next" in content assert "color: #ffaabb !important;" in content # put custom color in dots test_slide.inactive_dot_color = "#a1b2c3" test_slide.active_dot_color = "#d4e4f6" test_slide.save() response = client.get(reverse("shuup:index")) content = response.content.decode("utf-8") assert ".owl-dot:nth-child(1)" in content assert "border-color: #a1b2c3 !important" in content assert "background-color: #d4e4f6 !important;" in content