Python django.contrib.messages.constants.WARNING Examples

The following are 24 code examples of django.contrib.messages.constants.WARNING(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.messages.constants , or try the search function .
Example #1
Source File: tests.py    From tom_base with GNU General Public License v3.0 6 votes vote down vote up
def test_add_selected_to_grouping(self):
        data = {
            'grouping': self.fake_grouping.id,
            'add': True,
            'isSelectAll': 'False',
            'selected-target': [self.fake_targets[0].id, self.fake_targets[1].id],
            'query_string': '',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)

        self.assertEqual(self.fake_grouping.targets.count(), 2)
        self.assertTrue(self.fake_targets[0] in self.fake_grouping.targets.all())
        self.assertTrue(self.fake_targets[1] in self.fake_grouping.targets.all())

        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('1 target(s) successfully added to group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn(('1 target(s) already in group \'{}\': {}'.format(
            self.fake_grouping.name, self.fake_targets[0].name), WARNING), messages) 
Example #2
Source File: tests.py    From tom_base with GNU General Public License v3.0 6 votes vote down vote up
def test_add_all_to_grouping_filtered_by_sidereal(self):
        data = {
            'grouping': self.fake_grouping.id,
            'add': True,
            'isSelectAll': 'True',
            'selected-target': [],
            'query_string': 'type=SIDEREAL&name=&key=&value=&targetlist__name=',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)
        self.assertEqual(self.fake_grouping.targets.count(), 3)
        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('2 target(s) successfully added to group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn((
            '1 target(s) already in group \'{}\': {}'.format(self.fake_grouping.name, self.fake_targets[0].name),
            WARNING), messages
        ) 
Example #3
Source File: tests.py    From tom_base with GNU General Public License v3.0 6 votes vote down vote up
def test_remove_all_from_grouping_filtered_by_sidereal(self):
        data = {
            'grouping': self.fake_grouping.id,
            'remove': True,
            'isSelectAll': 'True',
            'selected-target': [],
            'query_string': 'type=SIDEREAL&name=&key=&value=&targetlist__name=',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)
        self.assertEqual(self.fake_grouping.targets.count(), 0)
        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('1 target(s) successfully removed from group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn(('2 target(s) not in group \'{}\': {}'.format(
            self.fake_grouping.name, self.fake_targets[1].name + ', ' + self.fake_targets[2].name
        ), WARNING), messages) 
Example #4
Source File: api.py    From bioforum with MIT License 5 votes vote down vote up
def warning(request, message, extra_tags='', fail_silently=False):
    """Add a message with the ``WARNING`` level."""
    add_message(request, constants.WARNING, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
Example #5
Source File: background_messages.py    From feedsubs with MIT License 5 votes vote down vote up
def warning(user, message):
    """
    Adds a message with the ``WARNING`` level.

    :param user: User instance
    :param message: Message to show
    """
    message_user(user, message, constants.WARNING) 
Example #6
Source File: base_tags.py    From jorvik with GNU General Public License v3.0 5 votes vote down vote up
def level_to_bootstrap(message):
    map = {
        constants.DEBUG: 'alert-info',
        constants.INFO: 'alert-info',
        constants.SUCCESS: 'alert-success',
        constants.WARNING: 'alert-warning',
        constants.ERROR: 'alert-danger',
    }
    return map.get(message.level, 'alert-info') 
Example #7
Source File: messages.py    From avos with Apache License 2.0 5 votes vote down vote up
def warning(request, message, extra_tags='', fail_silently=False):
    """Adds a message with the ``WARNING`` level."""
    add_message(request, constants.WARNING, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
Example #8
Source File: utils.py    From esdc-ce with Apache License 2.0 5 votes vote down vote up
def warning(self, msg):
        self.add_message(constants.WARNING, msg) 
Example #9
Source File: base.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def add_level_messages(storage):
    """
    Add 6 messages from different levels (including a custom one) to a storage
    instance.
    """
    storage.add(constants.INFO, 'A generic info message')
    storage.add(29, 'Some custom level')
    storage.add(constants.DEBUG, 'A debugging message', extra_tags='extra-tag')
    storage.add(constants.WARNING, 'A warning')
    storage.add(constants.ERROR, 'An error')
    storage.add(constants.SUCCESS, 'This was a triumph.') 
Example #10
Source File: base.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def add_level_messages(storage):
    """
    Add 6 messages from different levels (including a custom one) to a storage
    instance.
    """
    storage.add(constants.INFO, 'A generic info message')
    storage.add(29, 'Some custom level')
    storage.add(constants.DEBUG, 'A debugging message', extra_tags='extra-tag')
    storage.add(constants.WARNING, 'A warning')
    storage.add(constants.ERROR, 'An error')
    storage.add(constants.SUCCESS, 'This was a triumph.') 
Example #11
Source File: messages.py    From Inboxen with GNU Affero General Public License v3.0 5 votes vote down vote up
def warning(user, message):
    """
    Adds a message with the ``WARNING`` level.

    :param user: User instance
    :param message: Message to show
    """
    message_user(user, message, constants.WARNING) 
Example #12
Source File: tests.py    From Inboxen with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_warning(self):
        messages.warning(self.user, "Hello")
        self.assertMessageOk(constants.WARNING) 
Example #13
Source File: extra_filters.py    From Kiwi with GNU General Public License v2.0 5 votes vote down vote up
def message_icon(msg):
    """
        Returns the string class name of a message icon
        which feeds directly into Patternfly.
    """
    icons = {
        messages.ERROR: 'error-circle-o',
        messages.WARNING: 'warning-triangle-o',
        messages.SUCCESS: 'ok',
        messages.INFO: 'info',
    }
    return 'pficon-' + icons[msg.level] 
Example #14
Source File: test_view.py    From edx-enterprise with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_post_link_and_enroll_no_notification(
            self,
            forms_client,
            views_client,
            track_enrollment,
    ):
        """
        Test bulk upload with linking and enrolling
        """
        views_instance = views_client.return_value
        views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course
        forms_instance = forms_client.return_value
        forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details
        self._login()
        user = UserFactory.create()
        unknown_email = FAKER.email()  # pylint: disable=no-member
        columns = [ManageLearnersForm.CsvColumns.EMAIL]
        data = [(user.email,), (unknown_email,)]
        course_id = "course-v1:EnterpriseX+Training+2017"
        course_mode = "professional"

        response = self._perform_request(columns, data, course=course_id, course_mode=course_mode, notify=False)

        views_instance.enroll_user_in_course.assert_called_once_with(
            user.username,
            course_id,
            course_mode
        )
        track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id)
        pending_user_message = (
            "The following learners do not have an account on Test platform. They have not been enrolled in {}. "
            "When these learners create an account, they will be enrolled automatically: {}"
        )
        self._assert_django_messages(response, set([
            (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)),
            (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)),
            (messages.WARNING, pending_user_message.format(course_id, unknown_email)),
        ]))
        assert PendingEnterpriseCustomerUser.objects.all()[0].pendingenrollment_set.all()[0].course_id == course_id
        num_messages = len(mail.outbox)
        assert num_messages == 0 
Example #15
Source File: test_view.py    From edx-enterprise with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_post_existing_pending_record_with_another_enterprise_customer(self):
        """
        Tests that a PendingEnterpriseCustomerUser already linked with an Enterprise cannot be linked with another
        Enterprise and a warning message is created in response
        """
        # precondition checks:
        self._login()
        email = FAKER.email()  # pylint: disable=no-member
        another_ent = EnterpriseCustomerFactory()
        PendingEnterpriseCustomerUserFactory(enterprise_customer=another_ent, user_email=email)
        # Confirm that only one instance exists before post request
        assert PendingEnterpriseCustomerUser.objects.filter(user_email=email).count() == 1

        response = self.client.post(
            self.view_url,
            data=self.add_required_data({ManageLearnersForm.Fields.EMAIL_OR_USERNAME: email})
        )
        pending_user_message = (
            "Pending user with email address {user_email} is already linked with another Enterprise {ec_name}, "
            "you will be able to add the learner once the user creates account or other enterprise "
            "deletes the pending user"
        )
        self._assert_django_messages(response, {
            (messages.WARNING, pending_user_message.format(ec_name=another_ent.name, user_email=email)),
        })
        self._test_post_existing_record_response(response)
        assert PendingEnterpriseCustomerUser.objects.filter(user_email=email).count() == 1 
Example #16
Source File: api.py    From python2017 with MIT License 5 votes vote down vote up
def warning(request, message, extra_tags='', fail_silently=False):
    """
    Adds a message with the ``WARNING`` level.
    """
    add_message(request, constants.WARNING, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
Example #17
Source File: api.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def warning(request, message, extra_tags='', fail_silently=False):
    """
    Adds a message with the ``WARNING`` level.
    """
    add_message(request, constants.WARNING, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
Example #18
Source File: api.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def warning(request, message, extra_tags='', fail_silently=False):
    """Add a message with the ``WARNING`` level."""
    add_message(request, constants.WARNING, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
Example #19
Source File: tests.py    From tom_base with GNU General Public License v3.0 5 votes vote down vote up
def test_add_remove_from_grouping_empty_query_string(self):
        data = {
            'grouping': self.fake_grouping.id,
            'remove': True,
            'isSelectAll': 'True',
            'selected-target': [],
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)
        self.assertEqual(self.fake_grouping.targets.count(), 0)
        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('1 target(s) successfully removed from group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn(('2 target(s) not in group \'{}\': {}'.format(
            self.fake_grouping.name, self.fake_targets[1].name + ', ' + self.fake_targets[2].name
        ), WARNING), messages) 
Example #20
Source File: tests.py    From tom_base with GNU General Public License v3.0 5 votes vote down vote up
def test_remove_selected_from_grouping(self):
        data = {
            'grouping': self.fake_grouping.id,
            'remove': True,
            'isSelectAll': 'False',
            'selected-target': [self.fake_targets[0].id, self.fake_targets[1].id],
            'query_string': '',
        }
        response = self.client.post(reverse('targets:add-remove-grouping'), data=data)
        self.assertEqual(self.fake_grouping.targets.count(), 0)
        messages = [(m.message, m.level) for m in get_messages(response.wsgi_request)]
        self.assertIn(('1 target(s) successfully removed from group \'{}\'.'.format(self.fake_grouping.name),
                       SUCCESS), messages)
        self.assertIn(('1 target(s) not in group \'{}\': {}'.format(self.fake_grouping.name, self.fake_targets[1].name),
                       WARNING), messages) 
Example #21
Source File: api.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def warning(request, message, extra_tags='', fail_silently=False):
    """
    Adds a message with the ``WARNING`` level.
    """
    add_message(request, constants.WARNING, message, extra_tags=extra_tags,
                fail_silently=fail_silently) 
Example #22
Source File: test_view.py    From edx-enterprise with GNU Affero General Public License v3.0 4 votes vote down vote up
def test_post_link_and_enroll_no_course_details(
            self,
            forms_client,
            views_client,
            course_catalog_client,
            track_enrollment,
    ):
        """
        Test bulk upload with linking and enrolling
        """
        course_catalog_instance = course_catalog_client.return_value
        course_catalog_instance.get_course_run.return_value = {}
        views_instance = views_client.return_value
        views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course
        forms_instance = forms_client.return_value
        forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details

        self._login()
        user = UserFactory.create()
        unknown_email = FAKER.email()  # pylint: disable=no-member
        columns = [ManageLearnersForm.CsvColumns.EMAIL]
        data = [(user.email,), (unknown_email,)]
        course_id = "course-v1:EnterpriseX+Training+2017"
        course_mode = "professional"

        response = self._perform_request(columns, data, course=course_id, course_mode=course_mode)

        views_instance.enroll_user_in_course.assert_called_once_with(
            user.username,
            course_id,
            course_mode
        )
        track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id)
        pending_user_message = (
            "The following learners do not have an account on Test platform. "
            "They have not been enrolled in {}. When these learners create an "
            "account, they will be enrolled automatically: {}"
        )
        self._assert_django_messages(response, set([
            (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)),
            (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)),
            (messages.WARNING, pending_user_message.format(course_id, unknown_email)),
        ]))
        assert PendingEnterpriseCustomerUser.objects.all()[0].pendingenrollment_set.all()[0].course_id == course_id
        num_messages = len(mail.outbox)
        assert num_messages == 0 
Example #23
Source File: test_view.py    From edx-enterprise with GNU Affero General Public License v3.0 4 votes vote down vote up
def test_post_link_and_enroll(
            self,
            forms_client,
            views_client,
            course_catalog_client,
            track_enrollment,
    ):
        """
        Test bulk upload with linking and enrolling
        """
        discount_percentage = 20.0
        sales_force_id = 'dummy-sales_force_id'
        self.required_fields_with_default[ManageLearnersForm.Fields.DISCOUNT] = discount_percentage
        self.required_fields_with_default[ManageLearnersForm.Fields.SALES_FORCE_ID] = sales_force_id
        course_catalog_instance = course_catalog_client.return_value
        course_catalog_instance.get_course_run.return_value = {
            "name": "Enterprise Training",
            "start": "2017-01-01T12:00:00Z",
            "marketing_url": "http://localhost/course-v1:EnterpriseX+Training+2017"
        }
        views_instance = views_client.return_value
        views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course
        forms_instance = forms_client.return_value
        forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details
        self._login()
        user = UserFactory.create()
        unknown_email = FAKER.email()  # pylint: disable=no-member
        columns = [ManageLearnersForm.CsvColumns.EMAIL]
        data = [(user.email,), (unknown_email,)]
        course_id = "course-v1:EnterpriseX+Training+2017"
        course_mode = "professional"

        response = self._perform_request(columns, data, course=course_id, course_mode=course_mode)

        views_instance.enroll_user_in_course.assert_called_once_with(
            user.username,
            course_id,
            course_mode
        )
        track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id)
        pending_user_message = (
            "The following learners do not have an account on Test platform. "
            "They have not been enrolled in {}. When these learners create an "
            "account, they will be enrolled automatically: {}"
        )
        self._assert_django_messages(response, set([
            (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)),
            (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)),
            (messages.WARNING, pending_user_message.format(course_id, unknown_email)),
        ]))
        pending_enrollment = PendingEnterpriseCustomerUser.objects.all()[0].pendingenrollment_set.all()[0]
        assert pending_enrollment.course_id == course_id
        assert pending_enrollment.discount_percentage == discount_percentage
        assert pending_enrollment.sales_force_id == sales_force_id
        num_messages = len(mail.outbox)
        assert num_messages == 2 
Example #24
Source File: test_view.py    From edx-enterprise with GNU Affero General Public License v3.0 4 votes vote down vote up
def test_post_existing_and_duplicates(self):
        """
        Test that duplicates and existing links are handled correctly.

        1. Users already linked to an EnterpriseCustomer should cause a warning message, and an
            additional link won't be created, but otherwise will behave normally.
        2. Users that appear in a CSV twice will be ignored and a message will be created.
        3. Users that are attached to a different EnterpriseCustomer will be ignored, and
            a message will be created.
        """
        self._login()
        user = UserFactory(id=2)
        linked_user = UserFactory(id=3)
        user_linked_to_other_ec = UserFactory(id=4)
        EnterpriseCustomerUserFactory(user_id=user_linked_to_other_ec.id)
        EnterpriseCustomerUserFactory(user_id=linked_user.id, enterprise_customer=self.enterprise_customer)
        new_email = FAKER.email()  # pylint: disable=no-member

        assert EnterpriseCustomerUser.objects.count() == 2, "Precondition check: Two linked users"
        assert EnterpriseCustomerUser.objects.filter(user_id=linked_user.id).exists()
        assert EnterpriseCustomerUser.objects.filter(user_id=user_linked_to_other_ec.id).exists()
        assert not PendingEnterpriseCustomerUser.objects.exists(), "Precondition check: no pending user links"

        columns = [ManageLearnersForm.CsvColumns.EMAIL]
        data = [
            (linked_user.email,),  # a user that is already linked to this EC
            (new_email,),  # valid not previously seen email
            (user.email,),  # valid user email
            (user.email,),  # valid user email repeated
            (user_linked_to_other_ec.email,),  # valid user email linked to a different EC
        ]
        response = self._perform_request(columns, data)

        assert EnterpriseCustomerUser.objects.count() == 3, \
            "Two linked users remain, and one new link is created"
        assert EnterpriseCustomerUser.objects.filter(user_id=linked_user.id).exists()
        assert EnterpriseCustomerUser.objects.filter(user_id=user.id).exists()
        assert PendingEnterpriseCustomerUser.objects.count() == 1, "One pending linked users should be created"
        assert PendingEnterpriseCustomerUser.objects.filter(user_email=new_email).exists()
        self._assert_django_messages(response, set([
            (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)),
            (
                messages.WARNING,
                "The following learners were already associated with this "
                "Enterprise Customer: {}".format(linked_user.email)
            ),
            (messages.WARNING, "The following duplicate email addresses were not added: {}".format(user.email)),
            (
                messages.WARNING,
                "The following learners are already associated with another Enterprise Customer. "
                "These learners were not added to {}: {}".format(
                    self.enterprise_customer.name,
                    user_linked_to_other_ec.email
                )
            )
        ]))