コード例 #1
0
    def createMessage(self, req, name, message, button, 
                            mode, groups, start, end):
        """Create a new project message.

        :param string: name
        :param string: text (supports wiki formatting)
        :param string: button text
        :param string: mode ('Alert' or 'Full Screen')
        :param list: groups who can see the message (['groupA', 'groupB'])
        :param string: start date (ISO-8601 26-07-2014)
        :param string: end date (ISO-8601 30-07-2014)
        """

        try:
            ProjectMessage(self.env, name)
        except ResourceNotFound:
            self.log.debug("Name %s is unique - creating new project message.", name)
        else:
            return ("Unable to create a new project message. Please choose a "
                    "different name, %s is already in use." % (name))

        msg = ProjectMessage(self.env)
        msg['name'] = name
        msg['message'] = message
        msg['button'] = button
        msg['mode'] = mode
        msg['groups'] = groups
        msg['start'] = start
        msg['end'] = end
        msg['author'] = req.authname
        msg['created_at'] = to_utimestamp(datetime.now(pytz.utc))

        if not msg.validate():
            return "Could not create a new message. Some attributes are invalid."

        try:
            msg.insert()
        except DatabaseError:
            self.log.info("Database error when creating a new project message via XMLRPC.")
            return "Unable to create a new project message."
        else:
            self.log.info("Successfully created new project message via XMLRPC.")
            return "Successfully created new project message."
コード例 #2
0
    def _insert_message(self, name, message, button, mode, start, end, *args):
        """
        Inserts a new project message into the project_message table, 
        validating each argument passed prior to the transaction 
        being completed.

        This code is intended to be used only by IAdminCommandProvider.
        """

        try:
            ProjectMessage(self.env, name)
        except ResourceNotFound:
            self.log.debug("Name is unique - creating message.")
        else:
            raise AdminCommandError("There is already a project message "
                                    "with the name %s. Please choose "
                                    "a different name." % name)

        new_msg = ProjectMessage(self.env)
        new_msg['name'] = name
        new_msg['message'] = message
        new_msg['button'] = button
        new_msg['mode'] = mode
        new_msg['groups'] = [group for group in args]
        new_msg['start'] = start
        new_msg['end'] = end
        new_msg['author'] = "system" # anyone could lie about who they are
        new_msg['created_at'] = to_utimestamp(datetime.now(pytz.utc))

        if not new_msg.validate():
            raise AdminCommandError("Could not create a new message. Some "
                                    "attributes are invalid.")

        try:
            new_msg.insert()
        except:
            AdminCommandError("We were unable to save that "
                             "message. Please try again.")
        else:
            AdminCommandError("You created a new project message.")
            self.log.info("Created a new project message - %s", name)