Esempio n. 1
0
    def test_find_active(self):
        user = self.create_user()
        # No messages yet.
        self.assertEqual(Message.find_active(self.store).count(), 0)

        # One global message
        msg = Message(store=self.store, created_by=user, content='global')
        messages = set(Message.find_active(self.store))
        self.assertEqual(messages, set([msg]))
Esempio n. 2
0
    def _try_register_messages(cls):
        if cls._messages_registered:
            return

        from stoqlib.domain.message import Message
        with api.new_store() as store:
            user = api.get_current_user(store)
            branch = api.get_current_branch(store)
            # We cannot setup correctly if the user or branch are not setup yet.
            if not user or not branch:
                return

            messages = Message.find_active(store, branch, user)
            for msg in messages:

                @register
                class Foo(ResourceStatus):
                    name = msg.id
                    label = _('Message')
                    status = ResourceStatus.STATUS_WARNING
                    reason = msg.content

                    def refresh(self):
                        pass

        cls._messages_registered = True
Esempio n. 3
0
File: status.py Progetto: stoq/stoq
    def _try_register_messages(cls):
        if cls._messages_registered:
            return

        from stoqlib.domain.message import Message
        with api.new_store() as store:
            # We cannot setup correctly if the user or branch are not setup yet.
            if not api.get_current_user(store) or not api.get_current_branch(store):
                return

            messages = Message.find_active(store)
            for msg in messages:
                @register
                class Foo(ResourceStatus):
                    name = msg.id
                    label = _('Message')
                    status = ResourceStatus.STATUS_WARNING
                    reason = msg.content

                    def refresh(self):
                        pass
        cls._messages_registered = True
Esempio n. 4
0
 def create_model(self, store):
     return Message(store=store, created_by=api.get_current_user(store))