Example #1
0
    def add_role(self, name, description, activities=None):
        """
        Add a new role to the DB.

        @param name: Short, descriptive name of the role. Must be unique.
        @param description: Longer description of the role.
        @param activities: An activity dict defining the role's activities.
                           If parameter is omitted, then a default dict is used.
        """
        try:
            exists = self.find_role_by_name(name)
        except:
            exists = False

        if exists:
            raise DuplicateRole("{0} already exists as a role with id " "'{1}'".format(name, str(exists)))

        if activities is None:
            activities = get_activity_dict(False)

        now = datetime.datetime.now()
        pact = pickle(activities)
        role = Role(name, description, pact, now)
        mainDB.session.add(role)
        mainDB.session.commit()
        blob = pickle({"id": role.id})
        # XXX - Do we want to use the user ID of the person adding this role?
        self.eventLog.add("add_role", -1, True, blob, role.name)
        return role
Example #2
0
    def update_editor(self, u, e):
        """
        Given a user and an entry, update that entry's editors with that user.

        :param u: The user who edited the entry. Can be a user object, a uid,
                  or a string representing the username.
        :param e: The entry. Can be an entry id or an entry object.
        """
        now = datetime.datetime.now()
        entry = e
        if type(e) is IntType:
            entry = Entry.query.filter_by(id=e).first()

        users = UserDB().get_users(u)
        if len(users) > 0:
            user = users[0]
            editor = Editor.query.filter_by(entry_id=e.id).filter_by(
                user_id=user.id).first()
            if editor is None:
                editor = Editor(user, entry, now)
                mainDB.session.add(editor)
            else:
                editor.date = now

            mainDB.session.commit()
            pe = PEntry(entry)
            self.event_log.add('update_entry', user.id, False, pickle(
                pe), entry.title)
Example #3
0
    def update_temp_role_activities(self, role, acts):
        """
        Given a temportary role and updated activies for it, update it.

        Retuns updated role.
        """
        pact = pickle(acts)
        role.activities = pact
        return role
Example #4
0
    def update_entry(self, entry):
        """
        Given an entry object, update it.

        :param entry: The entry object to update.
        """
        mainDB.session.commit()
        pe = PEntry(entry)
        self.event_log.add('update_entry', entry.author.id, False, pickle(pe),
            repr(entry.title))
Example #5
0
    def add_entry_object(self, entry):
        """
        Given an entry object, add it to the system.

        :param entry: The entry object to add.
        """
        mainDB.session.add(entry)
        mainDB.session.commit()
        pe = PEntry(entry)
        self.event_log.add('add_entry', entry.author.id, False, pickle(pe),
            repr(entry.title))
Example #6
0
    def add(self, title, entry, author, group=None, weight=0, url=None,
            html=False, parent=None, static=False,
            postdate=datetime.datetime.now()):
        """
        Adds an entry to the system.

        Will not perform any checks, it will just add this entry. It's not
        this method's responsibility to check whether or not your entry is a
        duplicate. The one check it does do is to verify whether a URL is
        unique or not.

        :param title: The title of the post.
        :param entry: The entry of the post.
        :param author: The user object for the post's author
        :param group: The (optional) group this post will belong to. If None,
                      use the author's primary group
        :param url: The (optional) URL for this post.
        :param html: Flag detailing whether this post is in HTML or not
        :param parent: The (optional) parent for this post.
        :param static: (Optional) Whether or not the post is static.
        :param postdate: (Optional) The date of the post, current date default.

        :returns: New entry object just added
        """
        if group is None:
            group = author.primary_group

        e = Entry(title, author, group, postdate, entry, weight, url, html,
                parent, static)

        if type(url) is StringType:
            if self.find_by_URL(url):
                raise DuplicateURL(
                        'The URL "%s" was already found in the UrlDB!' % url)
            else:
                mainDB.session.add(e)
                mainDB.session.commit()
        else:
            mainDB.session.add(e)
            mainDB.session.commit()

        # FIXME
        # When a child is added, we need to also trigger page refreshes for
        # each member of the parent's children

        pe = PEntry(e)
        self.event_log.add('add_entry', author.id, False,
                pickle(pe), repr(e.title))
        return e
Example #7
0
    def delete(self, e):
        """
        Deletes an entry from the database.

        :param e: An entry to delete. Can be an integer for the entry id or an
                  entry object.
        """
        # FIXME
        # Should deal with parents and children so as not to leave orphans
        entry = e
        if type(e) is IntType:
            entry = Entry.query.filter_by(id=e).first()

        pe = PEntry(e)
        mainDB.session.delete(entry)
        mainDB.session.commit()
        self.event_log.add('del_entry', 0, False, pickle(pe), entry.title)
Example #8
0
 def create_temp_empty_role(self):
     """
     Returns a temporary, empty role object.
     """
     pact = pickle(get_activity_dict(False))
     return Role(None, None, pact, None)