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


Python FMSUser.is_pro方法代码示例

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


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

示例1: handle

# 需要导入模块: from django_fixmystreet.fixmystreet.models import FMSUser [as 别名]
# 或者: from django_fixmystreet.fixmystreet.models.FMSUser import is_pro [as 别名]
    def handle(self, *args, **options):
        from django_fixmystreet.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:IMIO,项目名称:django-fixmystreet,代码行数:56,代码来源:digest_notifications_pro.py

示例2: FMSUserTest

# 需要导入模块: from django_fixmystreet.fixmystreet.models import FMSUser [as 别名]
# 或者: from django_fixmystreet.fixmystreet.models.FMSUser import is_pro [as 别名]
class FMSUserTest(TestCase):

    fixtures = ["bootstrap", "list_items"]

    def setUp(self):
        self.user = User.objects.create_user('admin', '[email protected]', 'pwd')
        self.user.save()

        # these are from the fixtures file.
        self.category = ReportCategory.objects.all()[0]
        self.categoryclass = self.category.category_class

        self.commune = OrganisationEntity(name='test ward')
        #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)
开发者ID:ppo,项目名称:django-fixmystreet,代码行数:67,代码来源:users.py


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