Пример #1
0
    def done(self, request, form_list):
        data = {}
        for form in form_list:
            data.update(form.cleaned_data)

        # Send alert

        alert = Alert(sent_by = data['sent_by'],
                      title = data['title'],
                      details = data['details'],
                      level = data['level'],
            )

        if data['send_to'] == 'all':
            alert_userlist(alert, User.objects.all())

        if data['send_to'] == 'group':
            alert_groups(alert, data['sent_to'])

        if data['send_to'] == 'user':
            alert.sent_to = data['sent_to']
            alert.save()

        
        # Display success message and redirect to changelist:
        return self._model_admin.response_add(request, alert)
Пример #2
0
    def test_alert_group(self):
        """
        Tests the ability of the system to alert a group of users
        """

        # Create groups
        group = Group.objects.create(name='test1')

        # Create a load of users
        for i in range(50):
            user = User.objects.create(username='******' % (i))
            if settings.NONREL:
                update_user_groups(user, [group])
            else:
                group.user_set.add(user)

        for i in range(50, 100):
            user = User.objects.create(username='******' % (i))

        alert = Alert(
            sent_by='Tester',
            title='Test title',
            details='No details',
            level='Notice',
        )

        alert_groups(alert, group)

        self.assertEquals(len(Alert.objects.all()), 50)
Пример #3
0
    def done(self, request, form_list):
        data = {}
        for form in form_list:
            data.update(form.cleaned_data)

        # Send alert

        alert = Alert(
            sent_by=data['sent_by'],
            title=data['title'],
            details=data['details'],
            level=data['level'],
        )

        if data['send_to'] == 'all':
            alert_userlist(alert, User.objects.all())

        if data['send_to'] == 'group':
            alert_groups(alert, data['sent_to'])

        if data['send_to'] == 'user':
            alert.sent_to = data['sent_to']
            alert.save()

        # Display success message and redirect to changelist:
        return self._model_admin.response_add(request, alert)
Пример #4
0
    def test_alert_group(self):
        """
        Tests the ability of the system to alert a group of users
        """

        # Create groups
        group = Group.objects.create(name = 'test1')

        # Create a load of users
        for i in range(50):
            user = User.objects.create(username = '******' %(i))
            if settings.NONREL:
                update_user_groups(user, [group])
            else:
                group.user_set.add(user)
                
        for i in range(50, 100):
            user = User.objects.create(username = '******' %(i))


        alert   =   Alert(
                        sent_by = 'Tester'
                    ,   title   = 'Test title'
                    ,   details = 'No details'
                    ,   level   = 'Notice',
                    )

        alert_groups(alert, group)
        self.assertEquals(len(Alert.objects.all()), 50)