Ejemplo n.º 1
0
    def test_latest_rotation_no_start_or_end_date(self):
        """This test that if the weekdays and times are set for
        content rotation, that the content doesn't rotates with no dates set"""
        site = Site.objects.get(is_default_site=True)
        settings = SettingsProxy(site)
        site_settings = settings['core']['SiteSettings']
        site_settings.monday_rotation = True
        site_settings.tuesday_rotation = True
        site_settings.wednesday_rotation = True
        site_settings.thursday_rotation = True
        site_settings.friday_rotation = True
        site_settings.saturday_rotation = True
        site_settings.sunday_rotation = True
        site_settings.save()

        for i in range(5):
            self.footer = FooterPage(title='Footer Page %s',
                                     slug='footer-page-%s' % (i, ))
            self.footer_index.add_child(instance=self.footer)

        self.assertEquals(FooterPage.objects.live().count(), 5)
        self.assertEquals(self.main.latest_articles().count(), 0)

        self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=True)
        self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=False)
        self.assertEquals(self.main.latest_articles().count(), 10)
        first_article_old = self.main.latest_articles()[0].pk
        last_article_old = self.main.latest_articles()[9].pk
        rotate_content()
        self.assertEquals(first_article_old, self.main.latest_articles()[0].pk)
        self.assertEquals(last_article_old, self.main.latest_articles()[9].pk)
    def process_request(self, request):
        site = Site.objects.get(is_default_site=True)
        setting = SettingsProxy(site)
        persona_settings = setting['usermetadata']['PersonaeSettings']

        if not persona_settings.persona_required:
            return None

        exclude = [
            settings.MEDIA_URL, settings.STATIC_URL,
            reverse('molo.usermetadata:persona'),
            reverse('health'),
            reverse('versions'), '/admin/', 'django-admin/', '/import/',
            '/locale/'
        ]

        if hasattr(settings, 'PERSONA_IGNORE_PATH'):
            exclude += settings.PERSONA_IGNORE_PATH

        if any([p for p in exclude if request.path.startswith(p)]):
            return None

        if 'MOLO_PERSONA_SELECTION' not in request.session:
            url = '%s?next=%s' % (reverse('molo.usermetadata:persona'),
                                  request.path)
            return redirect(url)
    def setUp(self):
        self.mk_main()
        self.main = Main.objects.all().first()
        self.english = SiteLanguageRelation.objects.create(
            language_setting=Languages.for_site(self.main.get_site()),
            locale='en',
            is_active=True)

        self.index = PersonaIndexPage(title='Personae', slug="personae")
        self.main.add_child(instance=self.index)
        self.index.save_revision().publish()

        self.page = PersonaPage(title="child", slug="child")
        self.index.add_child(instance=self.page)
        self.page.save_revision().publish()

        self.client = Client()
        # Login
        self.user = self.login()

        site = Site.objects.get(is_default_site=True)
        setting = SettingsProxy(site)
        self.persona_settings = setting['usermetadata']['PersonaeSettings']
        self.persona_settings.persona_required = True
        self.persona_settings.save()

        self.site_settings = setting['core']['SiteSettings']
        self.site_settings.ga_tag_manager = 'GTM-xxxx'
        self.site_settings.save()
Ejemplo n.º 4
0
    def test_latest_rotation_on_multisite(self):
        """This test that if the date range, weekdays and times are set for
        content rotation, that the content rotates accordingly"""
        # sets the site settings
        site = self.main2.get_site()
        settings = SettingsProxy(site)
        site_settings = settings['core']['SiteSettings']

        site_settings.content_rotation_start_date = timezone.now()
        site_settings.content_rotation_end_date = timezone.now() + timedelta(
            days=1)
        time1 = str(timezone.now().time())[:8]
        time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8]
        site_settings.time = dumps([{
            'type': 'time',
            'value': time1
        }, {
            'type': 'time',
            'value': time2
        }])
        site_settings.monday_rotation = True
        site_settings.save()

        # creates articles and pages, some set to feature in latest, others not
        for i in range(5):
            self.footer = FooterPage(title='Footer Page %s',
                                     slug='footer-page-%s' % (i, ))
            self.footer_index.add_child(instance=self.footer)

        self.assertEqual(FooterPage.objects.live().count(), 5)
        self.assertEqual(self.main.latest_articles().count(), 0)

        self.mk_articles(self.yourmind_sub22,
                         count=10,
                         featured_in_latest_start_date=timezone.now())
        promote_articles()
        self.mk_articles(self.yourmind_sub22,
                         count=10,
                         featured_in_latest=False)
        self.assertEqual(self.main2.latest_articles().count(), 10)
        # gets the first and last articles of the list before it rotates
        first_article_old = self.main2.latest_articles()[0].pk
        last_article_old = self.main2.latest_articles()[9].pk

        rotate_content(day=0)

        # checks to see that the number of latest articles has not increased
        self.assertEqual(self.main2.latest_articles().count(), 10)
        # checks to see the the old first articles is not still the first one
        self.assertNotEqual(first_article_old,
                            self.main2.latest_articles()[0].pk)
        # checks to see the old first article has moved up 2 places
        self.assertEqual(first_article_old, self.main2.latest_articles()[2].pk)
        # checks to see the the old last article is not still last
        self.assertNotEqual(last_article_old,
                            self.main2.latest_articles()[8].pk)

        featured_from_main1 = self.main2.latest_articles().descendant_of(
            self.main).count()
        self.assertEqual(featured_from_main1, 0)
Ejemplo n.º 5
0
Archivo: tasks.py Proyecto: m1kola/molo
def rotate_content(day=None):
    """ this method gets the parameters that are needed for rotate_latest
    and rotate_featured_in_homepage methods, and calls them both"""
    # getting the content rotation settings from site settings
    main_lang = SiteLanguage.objects.filter(is_main_language=True).first()
    main = Main.objects.all().first()
    index = SectionIndexPage.objects.live().first()
    site = Site.objects.get(is_default_site=True)
    settings = SettingsProxy(site)
    site_settings = settings['core']['SiteSettings']
    if day is None:
        day = datetime.today().weekday()
    # creates a days of the week list

    # calls the two rotate methods with the necessary params
    if main and index:
        rotate_latest(main_lang, index, main, site_settings, day)
        rotate_featured_in_homepage(main_lang, day)
Ejemplo n.º 6
0
    def test_latest_rotation_no_valid_days(self):
        """This test that if the date range and times are set for
        content rotation, that it doesn't rotate without any weekdays set"""
        site = Site.objects.get(is_default_site=True)
        settings = SettingsProxy(site)
        site_settings = settings['core']['SiteSettings']
        site_settings.monday_rotation = True
        site_settings.content_rotation_start_date = timezone.now()
        site_settings.content_rotation_end_date = timezone.now() + timedelta(
            days=1)
        time1 = str(timezone.now().time())[:8]
        time2 = str((timezone.now() + timedelta(minutes=1)).time())[:8]
        site_settings.time = dumps([{
            'type': 'time',
            'value': time1
        }, {
            'type': 'time',
            'value': time2
        }])
        site_settings.save()

        for i in range(5):
            self.footer = FooterPage(title='Footer Page %s',
                                     slug='footer-page-%s' % (i, ))
            self.footer_index.add_child(instance=self.footer)

        self.assertEqual(FooterPage.objects.live().count(), 5)
        self.assertEqual(self.main.latest_articles().count(), 0)

        self.mk_articles(self.yourmind_sub,
                         count=10,
                         featured_in_latest_start_date=timezone.now())
        promote_articles()
        self.mk_articles(self.yourmind_sub, count=10, featured_in_latest=False)
        self.assertEqual(self.main.latest_articles().count(), 10)
        first_article_old = self.main.latest_articles()[0].pk
        last_article_old = self.main.latest_articles()[9].pk
        rotate_content(4)
        self.assertEqual(first_article_old, self.main.latest_articles()[0].pk)
        self.assertEqual(last_article_old, self.main.latest_articles()[9].pk)
Ejemplo n.º 7
0
    def setUp(self):
        self.mk_main()
        self.main = Main.objects.all().first()
        self.english = SiteLanguageRelation.objects.create(
            language_setting=Languages.for_site(self.main.get_site()),
            locale='en', is_active=True
        )
        self.french = SiteLanguageRelation.objects.create(
            language_setting=Languages.for_site(self.main.get_site()),
            locale='fr', is_active=True
        )

        self.index = PersonaIndexPage(title='Personae', slug="personae")
        self.main.add_child(instance=self.index)
        self.index.save_revision().publish()

        self.page = PersonaPage(title="child", slug="child")
        self.index.add_child(instance=self.page)
        self.page.save_revision().publish()
        self.page2 = PersonaPage(title="adult", slug="adult")
        self.index.add_child(instance=self.page2)
        self.page2.save_revision().publish()

        self.yourmind = self.mk_section(
            self.section_index, title='Your mind')
        self.yourmind_sub = self.mk_section(
            self.yourmind, title='Your mind subsection')

        self.client = Client()
        # Login
        self.user = self.login()

        site = Site.objects.get(is_default_site=True)
        setting = SettingsProxy(site)
        self.persona_settings = setting['usermetadata']['PersonaeSettings']
        self.persona_settings.persona_required = True
        self.persona_settings.save()