当前位置: 首页>>代码示例>>Python>>正文


Python FMSUser.is_pro方法代码示例

本文整理汇总了Python中apps.fixmystreet.models.FMSUser.is_pro方法的典型用法代码示例。如果您正苦于以下问题:Python FMSUser.is_pro方法的具体用法?Python FMSUser.is_pro怎么用?Python FMSUser.is_pro使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.fixmystreet.models.FMSUser的用法示例。


在下文中一共展示了FMSUser.is_pro方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from apps.fixmystreet.models import FMSUser [as 别名]
# 或者: from apps.fixmystreet.models.FMSUser import is_pro [as 别名]
    def handle(self, *args, **options):
        from apps.fixmystreet.models import GroupMailConfig, OrganisationEntity, ReportEventLog, UserOrganisationMembership

        # Date of yesterday (or specific date)
        if options['date']:
            YESTERDAY = datetime.datetime.strptime(options['date'], "%d/%m/%Y").date()
        else:
            YESTERDAY = datetime.date.today() - datetime.timedelta(days=1)

        logger.info('DIGEST OF NOTIFICATIONS FOR ACTVITIES OF %s' % YESTERDAY)

        # All group mail configurations with at least 1 digest config
        group_mail_configs = GroupMailConfig.objects.filter(group__type=OrganisationEntity.DEPARTMENT).filter(Q(digest_closed=True) | Q(digest_created=True) | Q(digest_inprogress=True) | Q(digest_other=True))
        logger.info('group_mail_configs %s' % group_mail_configs)

        # All group having digest config
        groups = group_mail_configs.values_list('group', flat=True)
        logger.info('groups %s' % groups)

        # All events of yesterday related to groups
        events_yesterday = ReportEventLog.objects.filter(event_at__contains=YESTERDAY, report__responsible_department__in=groups)
        logger.info('events_yesterday %s' % events_yesterday)

        for mail_config in group_mail_configs:
            group = mail_config.group

            # Returns all activities of yesterday grouped by reports where and related to group
            activities_list = events_yesterday.filter(report__responsible_department=group)

            if not activities_list:
                continue

            # Send digest to responsibles according to mail config
            recipients = mail_config.get_manager_recipients()

            logger.info('Digest of %s %s' % (group, recipients))
            logger.info('   Number of activities: %s' % activities_list.count())

            for activity in activities_list:
                logger.info('   %s %s %s' % (activity.event_at, activity.report.id, activity))

            # If NOT option send, do not send email
            if not options['send']:
                continue

            for recipient in recipients:
                # Because recipients are email and can be a user or group email, have to mock a user
                user = FMSUser()
                user.email = recipient
                user.is_pro = lambda: True
                user.last_used_language = "fr"

                # Render and send the digest by mail
                send_digest(user, activity, activities_list, YESTERDAY)
开发者ID:,项目名称:,代码行数:56,代码来源:

示例2: FMSUserTest

# 需要导入模块: from apps.fixmystreet.models import FMSUser [as 别名]
# 或者: from apps.fixmystreet.models.FMSUser import is_pro [as 别名]
class FMSUserTest(FMSTestCase):
    def setUp(self):
        # Create a FMSUser
        self.fmsuser = FMSUser(
            telephone="0123456789",
            last_used_language="fr",
            username="aaa",
            first_name="aaa",
            last_name="aaa",
            email="[email protected]",
        )
        self.fmsuser.save()

    def testCreationOfFMSUser(self):
        """Create a user and check if the row in database has been created"""
        self.assertTrue(self.fmsuser.id > 0)

    def testFMSCitizenOrProRole(self):
        """Test the roles of the FMSUser created"""
        self.assertTrue(self.fmsuser.is_citizen())
        self.assertFalse(self.fmsuser.is_pro())
        self.fmsuser.agent = True
        self.assertFalse(self.fmsuser.is_citizen())
        self.assertTrue(self.fmsuser.is_pro())
        self.fmsuser.agent = False
        self.fmsuser.manager = True
        self.assertFalse(self.fmsuser.is_citizen())
        self.assertTrue(self.fmsuser.is_pro())
        self.fmsuser.manager = False
        self.fmsuser.leader = True
        self.assertFalse(self.fmsuser.is_citizen())
        self.assertTrue(self.fmsuser.is_pro())
        self.fmsuser.leader = False
        self.fmsuser.applicant = True
        self.assertFalse(self.fmsuser.is_citizen())
        self.assertTrue(self.fmsuser.is_pro())
        self.fmsuser.applicant = False
        self.fmsuser.contractor = True
        self.assertFalse(self.fmsuser.is_citizen())
        self.assertTrue(self.fmsuser.is_pro())
        self.fmsuser.contractor = False
        self.assertTrue(self.fmsuser.is_citizen())
        self.assertFalse(self.fmsuser.is_pro())

    def testFMSLanguage(self):
        """Test the user language"""
        self.assertEquals(self.fmsuser.last_used_language, "fr")

    def testFMSSpecificRoles(self):
        """Test the user roles boolean values"""
        self.assertFalse(self.fmsuser.agent)
        self.assertFalse(self.fmsuser.manager)
        self.assertFalse(self.fmsuser.leader)
        self.assertFalse(self.fmsuser.applicant)
        self.assertFalse(self.fmsuser.contractor)

    def test_double_citizen_case_insensitive(self):
        citizen_data = {"email": "[email protected]", "last_name": "user", "telephone": "123456789", "quality": 1}

        # Create first citizen
        citizen_form = CitizenForm(citizen_data)

        # Form has to be valid
        self.assertTrue(citizen_form.is_valid())
        citizen_form.save()

        # Create second citizen with a caps in email
        citizen_data["email"] = citizen_data["email"].upper()
        citizen_form = CitizenForm(citizen_data)

        # Form has to be valid
        self.assertTrue(citizen_form.is_valid())
        citizen_form.save()

        # And only one user with the same email case insensitive is created (it's the same citizen in both cases)
        self.assertEqual(1, FMSUser.objects.filter(username__iexact=citizen_data["email"]).count())

    def test_citizen_with_pro_email(self):
        manager = FMSUser(
            is_active=True,
            telephone="0123456789",
            last_used_language="fr",
            password="test",
            first_name="manager",
            last_name="manager",
            email="[email protected]",
            manager=True,
        )
        manager.save()

        citizen_data = {"email": manager.email, "last_name": "user", "telephone": "123456789", "quality": 1}

        # Create a citizen user
        citizen_form = CitizenForm(citizen_data)

        # Form has to be INVALID because the citizen use a pro email
        self.assertFalse(citizen_form.is_valid())
        self.assertTrue(citizen_form.errors)
开发者ID:arnemutab,项目名称:django-fixmystreet,代码行数:100,代码来源:test_users.py


注:本文中的apps.fixmystreet.models.FMSUser.is_pro方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。