コード例 #1
0
 def create(self,
            request,
            name,
            display_name,
            article,
            summary,
            user,
            tags=''):
     """
     Add a new page
     Raise PageFound if page exists
     """
     try:
         self.show_page(name)
         raise PageFound
     except PageNotFound:
         pass
     page = ArticlePage(name, display_name)
     page.user = user
     revision = ArticleRevision(article, summary, user)
     page.revisions.append(revision)
     default_renderer = s.show_setting("DEFAULTRENDERER")
     page.renderer = DBSession.query(ArticleRenderers).filter_by(
         name=default_renderer).one()
     page = self.add_addons(page, name, display_name, user)
     self.t.set_tags(page, tags)
     self.update_article_index(request, page, revision, user.name)
     DBSession.add(page)
コード例 #2
0
    def from_json(self, request, data):
        u = UserLib()
        data = json.loads(data)

        def convert_date(date):
            if isinstance(date, str):
                date = date.split(".")[0]
            date_format = "%Y-%m-%dT%H:%M:%S"
            try:
                return datetime.datetime.strptime(date, date_format)
            except TypeError:
                return datetime.datetime(1900, 1, 1)
            except ValueError:
                return datetime.datetime(1900, 1, 1)

        # Convert the dates back
        for k, dummy in enumerate(data):
            data[k]['created'] = convert_date(data[k]['created'])
            for k2, dummy in enumerate(data[k]['revisions']):
                data[k]['revisions'][k2]['created'] = \
                            convert_date(data[k]['revisions'][k2]['created'])
        # Delete all articles
        for page in DBSession.query(ArticlePage):
            DBSession.delete(page)
            self.s.delete_from_index(
                request.route_url("article_read", page_id=page.name))
        # Add articles back again
        for row in data:
            # Delete revisions and store in memory for later use
            revisions = row['revisions']
            del (row['revisions'])
            # Create page
            page = ArticlePage()
            for k, v in row.items():
                try:
                    setattr(page, k, v)
                except:
                    pass
            if not page.user_id:
                page.user_id = 1
            DBSession.add(page)
            page = self.show_page(row['name'])

            user = None
            # Add revisions
            for row2 in revisions:
                revision = ArticleRevision()
                for k, v in row2.items():
                    try:
                        setattr(revision, k, v)
                    except:
                        pass
                page.revisions.append(revision)
                user = u.show_by_id(revision.user_id)
                self.update_article_index(request, page, revision, user.name)
            if user:
                page = self.add_addons(page, row['name'], row['display_name'],
                                       user)
コード例 #3
0
 def add_category(self, name):
     """
     Add a forum category
     """
     try:
         self.get_category(name)
         raise CategoryFound
     except CategoryNotFound:
         pass
     DBSession.add(BBCategory(name))
コード例 #4
0
ファイル: commentlib.py プロジェクト: Rich43/pyracms_forum
 def get_comment(self, *args):
     args = dumps([int(z) if str(z).isnumeric() else z for z in args])
     hash_text = sha512(args.encode()).hexdigest()
     try:
         comment = DBSession.query(BBComment).filter_by(
             hash_text=hash_text).one()
     except NoResultFound:
         comment = BBComment()
         comment.hash_text = hash_text
         comment.thread = BBThread("Comment", args)
         DBSession.add(comment)
     return comment
コード例 #5
0
 def add_forum(self, name, description, category):
     """
     Add a forum
     """
     try:
         self.get_forum_by_name(name)
         raise ForumFound
     except ForumNotFound:
         pass
     forum_obj = BBForum(name, description, category)
     DBSession.add(forum_obj)
     DBSession.flush()
     return forum_obj
コード例 #6
0
    def add_vote(self, db_obj, user, like):
        """
        Add a vote to the database
        """

        vote = BBVotes(user, like)
        vote.post = db_obj
        try:
            DBSession.add(vote)
            transaction.commit()
        except IntegrityError:
            transaction.abort()
            raise AlreadyVoted
コード例 #7
0
 def add_vote(self, db_obj, user, like):
     """
     Add a vote to the database
     """
     
     vote = GameDepVotes(user, like)
     vote.game = db_obj
     try:
         DBSession.add(vote)
         transaction.commit()
     except IntegrityError:
         transaction.abort()
         raise AlreadyVoted
コード例 #8
0
 def update(self, request, page, article, summary, user, tags=''):
     """
     Update a page
     Raise PageNotFound if page does not exist
     """
     if not article:
         self.delete(page, user)
         return
     self.t.set_tags(page, tags)
     revision = ArticleRevision(article, summary, user)
     revision.page = page
     if not page.private:
         self.update_article_index(request, page, revision, user.name)
     DBSession.add(revision)
コード例 #9
0
 def add_thread(self,
                title,
                description,
                body,
                user,
                forum=None,
                add_post=True):
     """
     Add a thread, optionally to a forum.
     """
     thread = BBThread(title, description)
     if forum:
         thread.forum = forum
     if add_post:
         self.add_post(thread, title, body, user)
     DBSession.add(thread)
     DBSession.flush()
     return thread
コード例 #10
0
 def create(self, name, display_name, description, tags, owner, request):
     """
     Add a new page
     Raise GameDepFound if page exists
     """
     if not self.exists(name, raise_if_found=True):
         page = GameDepPage(self.gamedep_type, name, display_name, owner)
         page.description = description
         self.t.set_tags(page, tags)
         s = SettingsLib()
         if s.has_setting("PYRACMS_FORUM"):
             from pyracms_forum.lib.boardlib import BoardLib
             page.thread_id = BoardLib().add_thread(name, display_name, "",
                                                    owner, add_post=False).id
         if s.has_setting("PYRACMS_GALLERY"):
             from pyracms_gallery.lib.gallerylib import GalleryLib
             g = GalleryLib()
             album = g.create_album(name, display_name, owner)
             page.album_id = album
         DBSession.add(page)
コード例 #11
0
 def create(self, name, display_name, description, tags, owner, request):
     """
     Add a new page
     Raise GameDepFound if page exists
     """
     if not self.exists(name, raise_if_found=True):
         page = GameDepPage(self.gamedep_type, name, display_name, owner)
         page.description = description
         self.t.set_tags(page, tags)
         s = SettingsLib()
         if s.has_setting("PYRACMS_FORUM"):
             from pyracms_forum.lib.boardlib import BoardLib
             page.thread_id = BoardLib().add_thread(name,
                                                    display_name,
                                                    "",
                                                    owner,
                                                    add_post=False).id
         if s.has_setting("PYRACMS_GALLERY"):
             from pyracms_gallery.lib.gallerylib import GalleryLib
             g = GalleryLib()
             album = g.create_album(name, display_name, owner)
             page.album_id = album
         DBSession.add(page)
コード例 #12
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        # Add Operating Systems
        DBSession.add(OperatingSystems("pi", "Platform Independent"))
        DBSession.add(OperatingSystems("win", "Windows"))
        DBSession.add(OperatingSystems("mac", "Mac OS X"))
        DBSession.add(OperatingSystems("lin", "Linux"))
        DBSession.add(OperatingSystems("sol", "Solaris"))
        DBSession.add(OperatingSystems("fbsd", "FreeBSD"))
        DBSession.add(OperatingSystems("nbsd", "NetBSD"))
        DBSession.add(OperatingSystems("obsd", "OpenBSD"))
        
        # Add Architectures
        DBSession.add(Architectures("pi", "Platform Independent"))
        DBSession.add(Architectures("i386", "32bit X86"))
        DBSession.add(Architectures("x86_64", "64bit X86"))
        DBSession.add(Architectures("arm", "ARM Little Endian"))
        DBSession.add(Architectures("armeb", "ARM Big Endian"))
        DBSession.add(Architectures("ppc", "32bit PowerPC"))
        DBSession.add(Architectures("ppc64", "64bit PowerPC"))
        DBSession.add(Architectures("sparc", "32bit SPARC"))
        DBSession.add(Architectures("sparc64", "64bit SPARC"))
    
        # Default Groups
        u = UserLib()
        u.create_group("gamedep", "Ability to Add, Edit and Delete" +
                       " games and dependencies.")
        
        # Default ACL
        acl = RootFactory()
        acl.__acl__.append((Allow, Everyone, 'gamedep_view'))
        acl.__acl__.append((Allow, Everyone, 'gamedep_list'))
        acl.__acl__.append((Allow, "group:admin", 'gamedep_mod'))
        acl.__acl__.append((Allow, "group:gamedep", "group:gamedep"))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_view'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_list'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_publish'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_edit'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_picture'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete_picture'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_source'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_binary'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_edit_binary'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete_binary'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_dependency'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete_dependency'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_edit_revision'))
        
        s = SettingsLib()
        s.update("DEFAULTGROUPS", s.show_setting("DEFAULTGROUPS") + 
                 "gamedep\n")
        s.create("INFO_PIC_ADDED", "Your picture (%s) has been added.")
        s.create("INFO_PIC_DELETED", "Your picture (%s) has been deleted.")
        s.create("INFO_BINARY_ADDED", "Your binary (%s) has been added.")
        s.create("INFO_BINARY_UPDATED", "Your binary (%s) has been updated.")
        s.create("INFO_BINARY_DELETED", "Your binary (%s) has been deleted.")
        s.create("INFO_SOURCE_UPLOADED", "The source code (%s) has been "
                                         "successfully uploaded.")
        s.create("INFO_DEPENDENCY_ADDED",
                 "Your dependency (%s) has been added.")
        s.create("INFO_DEPENDENCY_DELETED",
                 "Your dependency (%s) has been deleted.")
        s.create("INFO_REVISION_UPDATED", "A new version (%s) has been "
                                          "updated for %s.")
        s.create("INFO_REVISION_CREATED", "A new version (%s) has been "
                                          "created for %s.")
        s.create("ERROR_INVALID_BINARY_ID",
                 "Invalid Binary ID and/or Edit Type.")
        s.create("ERROR_NOT_UPLOADED_BINARY",
                 "You have not uploaded any binaries.")
        s.create("ERROR_NOT_UPLOADED_SOURCE_CODE",
                 "You have not uploaded any source code.")
        s.create("HYPERNUCLEUS_SERVER")

        m = MenuLib()
        group = m.show_group("main_menu")
        m.add_menu_item_route("Games", "gamedeplist", 3, group, Everyone,
                              {"type": GAME})
        m.add_menu_item_route("Dependencies", "gamedeplist", 4,
                              group, Everyone, {"type": DEP})
コード例 #13
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        # Add Operating Systems
        DBSession.add(OperatingSystems("pi", "Platform Independent"))
        DBSession.add(OperatingSystems("win", "Windows"))
        DBSession.add(OperatingSystems("mac", "Mac OS X"))
        DBSession.add(OperatingSystems("lin", "Linux"))
        DBSession.add(OperatingSystems("sol", "Solaris"))
        DBSession.add(OperatingSystems("fbsd", "FreeBSD"))
        DBSession.add(OperatingSystems("nbsd", "NetBSD"))
        DBSession.add(OperatingSystems("obsd", "OpenBSD"))

        # Add Architectures
        DBSession.add(Architectures("pi", "Platform Independent"))
        DBSession.add(Architectures("i386", "32bit X86"))
        DBSession.add(Architectures("x86_64", "64bit X86"))
        DBSession.add(Architectures("arm", "ARM Little Endian"))
        DBSession.add(Architectures("armeb", "ARM Big Endian"))
        DBSession.add(Architectures("ppc", "32bit PowerPC"))
        DBSession.add(Architectures("ppc64", "64bit PowerPC"))
        DBSession.add(Architectures("sparc", "32bit SPARC"))
        DBSession.add(Architectures("sparc64", "64bit SPARC"))

        # Default Groups
        u = UserLib()
        u.create_group(
            "gamedep",
            "Ability to Add, Edit and Delete" + " games and dependencies.")

        # Default ACL
        acl = RootFactory()
        acl.__acl__.append((Allow, Everyone, 'gamedep_view'))
        acl.__acl__.append((Allow, Everyone, 'gamedep_list'))
        acl.__acl__.append((Allow, "group:admin", 'gamedep_mod'))
        acl.__acl__.append((Allow, "group:gamedep", "group:gamedep"))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_view'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_list'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_publish'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_edit'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_picture'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete_picture'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_source'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_binary'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_edit_binary'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_delete_binary'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_add_dependency'))
        acl.__acl__.append(
            (Allow, "group:gamedep", 'gamedep_delete_dependency'))
        acl.__acl__.append((Allow, "group:gamedep", 'gamedep_edit_revision'))

        s = SettingsLib()
        s.update("DEFAULTGROUPS",
                 s.show_setting("DEFAULTGROUPS") + "gamedep\n")
        s.create("INFO_PIC_ADDED", "Your picture (%s) has been added.")
        s.create("INFO_PIC_DELETED", "Your picture (%s) has been deleted.")
        s.create("INFO_BINARY_ADDED", "Your binary (%s) has been added.")
        s.create("INFO_BINARY_UPDATED", "Your binary (%s) has been updated.")
        s.create("INFO_BINARY_DELETED", "Your binary (%s) has been deleted.")
        s.create("INFO_SOURCE_UPLOADED", "The source code (%s) has been "
                 "successfully uploaded.")
        s.create("INFO_DEPENDENCY_ADDED",
                 "Your dependency (%s) has been added.")
        s.create("INFO_DEPENDENCY_DELETED",
                 "Your dependency (%s) has been deleted.")
        s.create("INFO_REVISION_UPDATED", "A new version (%s) has been "
                 "updated for %s.")
        s.create("INFO_REVISION_CREATED", "A new version (%s) has been "
                 "created for %s.")
        s.create("ERROR_INVALID_BINARY_ID",
                 "Invalid Binary ID and/or Edit Type.")
        s.create("ERROR_NOT_UPLOADED_BINARY",
                 "You have not uploaded any binaries.")
        s.create("ERROR_NOT_UPLOADED_SOURCE_CODE",
                 "You have not uploaded any source code.")
        s.create("HYPERNUCLEUS_SERVER")

        m = MenuLib()
        group = m.show_group("main_menu")
        m.add_menu_item_route("Games", "gamedeplist", 3, group, Everyone,
                              {"type": GAME})
        m.add_menu_item_route("Dependencies", "gamedeplist", 4, group,
                              Everyone, {"type": DEP})
コード例 #14
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        # Add Groups
        u = UserLib()
        u.create_group(
            "article",
            "Ability to Add, Edit, Delete, " + "Revert and Protect Articles.")

        # Default ACL
        acl = RootFactory(session=DBSession)
        acl.__acl__.append((Allow, "group:admin", "switch_renderer"))
        acl.__acl__.append((Allow, "group:admin", "set_private"))
        acl.__acl__.append((Allow, "group:admin", "article_mod"))
        acl.__acl__.append((Allow, Authenticated, "article_list_revisions"))
        acl.__acl__.append((Allow, Everyone, "article_view"))
        acl.__acl__.append((Allow, Everyone, "article_list"))
        acl.__acl__.append((Allow, "group:article", "group:article"))
        acl.__acl__.append((Allow, "group:article", "article_view"))
        acl.__acl__.append((Allow, "group:article", "article_list"))
        acl.__acl__.append((Allow, "group:article", "article_create"))
        acl.__acl__.append((Allow, "group:article", "article_update"))
        acl.__acl__.append((Allow, "group:article", "article_delete"))
        acl.__acl__.append((Allow, "group:article", "article_revert"))

        # Add settings
        s = SettingsLib()
        s.create("PYRACMS_ARTICLE")
        s.update("DEFAULTGROUPS",
                 s.show_setting("DEFAULTGROUPS") + "article\n")

        # Add Menu Items
        m = MenuLib()
        group = m.show_group("main_menu")
        m.add_menu_item_route("Articles", "article_list", 2, group, Everyone)

        group = m.show_group("admin_area")
        m.add_menu_item_route("Backup Articles",
                              "userarea_admin_backup_articles", 8, group,
                              'backup')
        m.add_menu_item_route("Restore Articles",
                              "userarea_admin_restore_articles", 9, group,
                              'backup')

        group = MenuGroup("article_not_revision")
        m.add_menu_item_url("Comments", "/article/item/%(page_id)s?comments",
                            1, group, 'forum_view')
        m.add_menu_item_route("Gallery", "show_album", 2, group, 'show_album')
        m.add_menu_item_route("Edit", "article_update", 3, group,
                              'article_update')
        m.add_menu_item_route("Delete", "article_delete", 4, group,
                              'article_delete')
        m.add_menu_item_route("Switch Renderer [%(renderer)s]",
                              "article_switch_renderer", 5, group,
                              'switch_renderer')
        m.add_menu_item_route("Make %(private)s", "article_set_private", 6,
                              group, 'set_private')
        m.add_menu_item_route("%(hideshow)s Display Name",
                              "article_hide_display_name", 7, group,
                              'set_private')
        m.add_menu_item_url("Vote Up (%(up_count)s)",
                            "/vote/article/%(page_id)s/True", 8, group, 'vote')
        m.add_menu_item_url("Vote Down (%(down_count)s)",
                            "/vote/article/%(page_id)s/False", 9, group,
                            'vote')
        m.add_menu_item_route("List Revisions", "article_list_revisions", 10,
                              group, 'article_list_revisions')

        group = MenuGroup("article_revision")
        m.add_menu_item_route("List Revisions", "article_list_revisions", 1,
                              group, 'article_list_revisions')
        m.add_menu_item_route("Revert", "article_revert", 2, group,
                              "article_revert")

        # Add Renderers
        DBSession.add(ArticleRenderers("HTML"))
        DBSession.add(ArticleRenderers("BBCODE"))
        DBSession.add(ArticleRenderers("RESTRUCTUREDTEXT"))
        DBSession.add(ArticleRenderers("MARKDOWN"))