def test_is_allowed_homepage(self): """set is_allowed_homepage utility""" self.assertEqual( True, is_allowed_homepage(reverse("crm_view_entities_list"))) self.assertEqual(True, is_allowed_homepage(reverse("users_favorites_list"))) self.assertEqual(False, is_allowed_homepage(reverse("quick_search"))) self.assertEqual( True, is_allowed_homepage('http://testserver' + reverse("crm_view_entities_list")))
def user_homepage(request): """redirect to user homepage""" try: homepage = models.UserHomepage.objects.get(user=request.user) #Redirect to user homepage but make sure to avoid dead loop if is_allowed_homepage(homepage.url): return HttpResponseRedirect(homepage.url) except models.UserHomepage.DoesNotExist: pass return HttpResponseRedirect(reverse('crm_board_panel'))
def user_homepage(request): """redirect to user homepage""" try: homepage = models.UserHomepage.objects.get(user=request.user) #Redirect to user homepage but make sure to avoid dead loop if is_allowed_homepage(homepage.url): return HttpResponseRedirect(homepage.url) except models.UserHomepage.DoesNotExist: pass return HttpResponseRedirect(reverse('crm_board_panel'))
def crm(request): """add constant to context""" site_url = None if not settings.BALAFON_AS_HOMEPAGE: try: site_url = reverse('homepage') except NoReverseMatch: pass return { 'BALAFON_VERSION': VERSION, 'BALAFON_SITE_URL': site_url, 'BALAFON_ALLOW_SINGLE_CONTACT': crm_settings.ALLOW_SINGLE_CONTACT, 'BALAFON_NO_ENTITY_TYPE': crm_settings.NO_ENTITY_TYPE, 'BALAFON_ENTITY_TYPES': EntityType.objects.all(), 'BALAFON_MULTI_USER': getattr(settings, 'BALAFON_MULTI_USER', True), 'BALAFON_EMAIL_LOGIN': ('balafon.Profile.backends.EmailModelBackend' in settings.AUTHENTICATION_BACKENDS), 'BALAFON_STORE_INSTALLED': 'balafon.Store' in settings.INSTALLED_APPS, 'NOW': datetime.now(), 'is_allowed_homepage': is_allowed_homepage(request.path), 'addable_action_types': ActionType.objects.filter(set__isnull=False), }
def crm(request): """add constant to context""" site_url = None if not settings.BALAFON_AS_HOMEPAGE: try: site_url = reverse('homepage') except NoReverseMatch: pass return { 'BALAFON_VERSION': VERSION, 'BALAFON_SITE_URL': site_url, 'BALAFON_ALLOW_SINGLE_CONTACT': crm_settings.ALLOW_SINGLE_CONTACT, 'BALAFON_NO_ENTITY_TYPE': crm_settings.NO_ENTITY_TYPE, 'BALAFON_ENTITY_TYPES': EntityType.objects.all(), 'BALAFON_MULTI_USER': getattr(settings, 'BALAFON_MULTI_USER', True), 'BALAFON_EMAIL_LOGIN': ('balafon.Profile.backends.EmailModelBackend' in settings.AUTHENTICATION_BACKENDS), 'BALAFON_STORE_INSTALLED': 'balafon.Store' in settings.INSTALLED_APPS, 'NOW': datetime.now(), 'is_allowed_homepage': is_allowed_homepage(request.path), 'addable_action_types': ActionType.objects.filter(Q(set__isnull=False) | Q(is_default=True)), 'has_default_action': ActionType.objects.filter(is_default=True).count(), }
def clean_url(self): url = self.cleaned_data['url'] if not is_allowed_homepage(url): raise ValidationError(_(u"The url {0} is not allowed as homepage".format(url))) return url
def clean_url(self): url = self.cleaned_data['url'] if not is_allowed_homepage(url): raise ValidationError(_("The url {0} is not allowed as homepage".format(url))) return url
def test_is_allowed_homepage(self): """set is_allowed_homepage utility""" self.assertEqual(True, is_allowed_homepage(reverse("crm_view_entities_list"))) self.assertEqual(True, is_allowed_homepage(reverse("users_favorites_list"))) self.assertEqual(False, is_allowed_homepage(reverse("quick_search"))) self.assertEqual(True, is_allowed_homepage('http://testserver' + reverse("crm_view_entities_list")))