def setUp(self): # create root page root_page = Page.objects.get(title="Root") # create homepage homepage = HomePage( title="Hello World", slug="hello-world", ) # add homepage to root page root_page.add_child(instance=homepage) # create book index page book_index = BookIndex( title="Book Index", page_description="Test", dev_standard_1_description="Test", dev_standard_2_description="Test", dev_standard_3_description="Test", ) # add book index to homepage homepage.add_child(instance=book_index) # create book (finally! needed for Errata reports) book = Book( cnx_id='d50f6e32-0fda-46ef-a362-9bd36ca7c97d', title='University Physics', salesforce_abbreviation='University Phys (Calc)', salesforce_name='University Physics', description="Test Book", ) book_index.add_child(instance=book)
def test_can_create_errata_list_page(self): root_page = Page.objects.get(title="Root") homepage = HomePage(title="Hello World", slug="hello-world", ) root_page.add_child(instance=homepage) errata_list_page = ErrataList(title="Errata List Template", correction_schedule="Some sample correction schedule text.") homepage.add_child(instance=errata_list_page) retrieved_page = Page.objects.get(id=errata_list_page.id) self.assertEqual(retrieved_page.title, "Errata List Template")
def get_context_data(self, **kwargs): kwargs = super(HomeView, self).get_context_data(**kwargs) home_page = HomePage.get_solo() home_slides = HomeSlide.objects.published().order_by('ordering')[:20] home_advantages = None # HomeAdvantage.objects.published().order_by('ordering')[:5] home_catalogs = HomeCatalog.objects.published().order_by('ordering') home_catalog_products = defaultdict(list) for product in HomeCatalogProduct.objects.published()\ .filter(product__status=StatusEnum.PUBLIC, catalog__status=StatusEnum.PUBLIC)\ .select_related('product').order_by('ordering').iterator(): home_catalog_products[product.catalog_id].append(product.product) home_catalog_manufacturers = defaultdict(list) for manufacturer in HomeCatalogManufacturer.objects.published()\ .filter(manufacturer__status=StatusEnum.PUBLIC, catalog__status=StatusEnum.PUBLIC)\ .select_related('manufacturer').order_by('ordering').iterator(): home_catalog_manufacturers[manufacturer.catalog_id].append( manufacturer.manufacturer) kwargs.update(home_advantages=home_advantages, home_catalogs=home_catalogs, home_catalog_manufacturers=home_catalog_manufacturers, home_catalog_products=home_catalog_products, home_page=home_page, home_slides=home_slides) return kwargs
def setUpTestData(cls): # create root page root_page = Page.objects.get(title="Root") # create homepage homepage = HomePage( title="Hello World", slug="hello-world", ) # add homepage to root page root_page.add_child(instance=homepage) # create book index page news_index = NewsIndex(title="News Index") # add book index to homepage homepage.add_child(instance=news_index) cls.news_index = Page.objects.get(id=news_index.id)
def test_can_create_homepage(self): root_page = Page.objects.get(title="Root") homepage = HomePage(title="Hello World", slug="hello-world", ) root_page.add_child(instance=homepage) retrieved_page = Page.objects.get(id=homepage.id) self.assertEqual(retrieved_page.title, "Hello World")
def import_page(name, path): with open(os.path.join(path, name, 'data'), 'rb') as f: data = pickle.load(f) def copy_data(target, data): copy_seo_data(target, data) translation.activate('en') target.content = html2text.html2text(data.text_en) translation.deactivate() translation.activate('fr') target.content = html2text.html2text(data.text_fr) translation.deactivate() if isinstance(data, models.HomePage): hp = HomePage.get_solo() copy_data(hp, data) push = HomePagePush() push.home_page = hp translation.activate('en') push.title = data.push_title_en push.content = html2text.html2text(data.push_content_en) translation.deactivate() translation.activate('fr') push.title = data.push_title_fr push.content = html2text.html2text(data.push_content_fr) translation.deactivate() push.save() hp.save() else: p = Page() p.slug = slugify(data.title_en.lower()) copy_data(p, data) translation.activate('en') p.title = data.title_en translation.deactivate() translation.activate('fr') p.title = data.title_fr translation.deactivate() if hasattr(data, 'background'): img = make_master_image( path, data.background, '{}-background'.format(data.title_en) ) p.background = img p.save()
def test_can_create_book_index(self): #create root page root_page = Page.objects.get(title="Root") #create homepage homepage = HomePage(title="Hello World", slug="hello-world", ) #add homepage to root page root_page.add_child(instance=homepage) #create book index page book_index = BookIndex(title="Book Index", page_description="Test", dev_standard_1_description="Test", dev_standard_2_description="Test", dev_standard_3_description="Test", ) #add book index to homepage homepage.add_child(instance=book_index) retrieved_page = Page.objects.get(id=book_index.id) self.assertEqual(retrieved_page.title, "Book Index")
def home(request): p = HomePage.get_solo() items = [] items.extend(Section.objects.all()) items.extend(Page.objects.all()) context = { 'page': p, 'background': DefaultBackground.get_solo().background, 'pushes': HomePagePush.objects.all(), 'items': items, } return render(request, 'pages/home.html', context)
def setUpTestData(cls): # create root page root_page = Page.objects.get(title="Root") # create homepage homepage = HomePage( title="Hello World", slug="hello-world", ) # add homepage to root page root_page.add_child(instance=homepage) # create book index page book_index = BookIndex( title="Book Index", page_description="Test", dev_standard_1_description="Test", dev_standard_2_description="Test", dev_standard_3_description="Test", ) # add book index to homepage homepage.add_child(instance=book_index) cls.book_index = Page.objects.get(id=book_index.id)
def setUp(self): # create root page root_page = Page.objects.get(title="Root") # create homepage homepage = HomePage( title="Hello World", slug="hello-world", ) # add homepage to root page root_page.add_child(instance=homepage) # create book index page book_index = BookIndex( title="Book Index", page_description="Test", dev_standard_1_description="Test", dev_standard_2_description="Test", dev_standard_3_description="Test", dev_standard_4_description="Test", ) # add book index to homepage homepage.add_child(instance=book_index) # create book (finally! needed for Errata reports) test_image = SimpleUploadedFile( name='openstax.png', content=open("admin_templates/static/images/openstax.png", 'rb').read()) test_doc = Document.objects.create(title='Test Doc', file=test_image) book = Book( cnx_id='d50f6e32-0fda-46ef-a362-9bd36ca7c97d', title='University Physics', salesforce_abbreviation='University Phys (Calc)', salesforce_name='University Physics', description="Test Book", cover=test_doc, title_image=test_doc, publish_date=datetime.date.today(), ) book_index.add_child(instance=book)
def setUpTestData(cls): # create root page root_page = Page.objects.get(title="Root") # create homepage homepage = HomePage(title="Hello World", slug="hello-world", ) # add homepage to root page root_page.add_child(instance=homepage) # create book index page book_index = BookIndex(title="Book Index", page_description="Test", dev_standard_1_description="Test", dev_standard_2_description="Test", dev_standard_3_description="Test", ) # add book index to homepage homepage.add_child(instance=book_index) test_image = SimpleUploadedFile(name='openstax.png', content=open("admin_templates/static/images/openstax.png", 'rb').read()) cls.test_doc = Document.objects.create(title='Test Doc', file=test_image) cls.book_index = Page.objects.get(id=book_index.id)