示例#1
0
    def register(self):
        """
        Registers the content items into the database. Registration only works for a 
        postgres user account.
        """
        pg_account = "postgres"

        if self._username == pg_account:
            for c in self.contentItems():
                if isinstance(c, Content):
                    cnt = Content()
                    qo = cnt.queryObject()
                    cn = qo.filter(Content.code == c.code).first()

                    #If content not found then add
                    if cn is None:
                        #Check if the 'postgres' role is defined, if not then create one
                        rl = Role()
                        rolequery = rl.queryObject()
                        role = rolequery.filter(
                            Role.name == pg_account).first()

                        if role is None:
                            rl.name = pg_account
                            rl.contents = [c]
                            rl.save()
                        else:
                            existingContents = role.contents
                            #Append new content to existing
                            existingContents.append(c)
                            role.contents = existingContents
                            role.update()
示例#2
0
    def register(self):
        """
        Registers the content items into the database. Registration only works for a 
        postgres user account.
        """
        PG_ACCOUNT = "postgres"

        if self._username == PG_ACCOUNT:
            for c in self.contentItems():
                if isinstance(c, Content):
                    cnt = Content()
                    qo = cnt.queryObject()

                    if c.code is None:
                        code = self.hash_code(unicode(c.name))
                        cn = c
                    else:
                        code = c.code

                    cn = qo.filter(Content.code == code).first()

                    #If content not found then add
                    if cn is None:
                        #Check if the 'postgres' role is defined, if not then create one
                        rl = Role()
                        rolequery = rl.queryObject()
                        role = rolequery.filter(
                            Role.name == PG_ACCOUNT).first()

                        if role is None:
                            rl.name = PG_ACCOUNT
                            rl.contents = [c]
                            rl.save()
                        else:
                            existingContents = role.contents
                            #Append new content to existing
                            if c.code is None:
                                c.code = code

                            if len([
                                    e_cont for e_cont in existingContents
                                    if e_cont.name == c.name
                            ]) == 0:
                                existingContents.append(c)
                                role.contents = existingContents
                                role.update()
        else:
            for c in self.contentItems():
                if isinstance(c, Content):
                    cnt = Content()
                    qo = cnt.queryObject()
                    cn = qo.filter(Content.name == c.name).first()
                    c.code = cn.code
示例#3
0
    def register(self):
        """
        Registers the content items into the database. Registration only works for a 
        postgres user account.
        """
        PG_ACCOUNT = "postgres"   
        
        if self._username == PG_ACCOUNT:
            for c in self.contentItems():
                if isinstance(c,Content):
                    cnt = Content()
                    qo = cnt.queryObject()

                    if c.code is None:
                        code = self.hash_code(unicode(c.name))
                        cn = c
                    else:
                        code = c.code

                    cn = qo.filter(Content.code == code).first()

                    #If content not found then add
                    if cn is None:
                        #Check if the 'postgres' role is defined, if not then create one
                        rl = Role()
                        rolequery = rl.queryObject()
                        role = rolequery.filter(Role.name == PG_ACCOUNT).first()
                        
                        if role is None:
                            rl.name = PG_ACCOUNT
                            rl.contents = [c]
                            rl.save()                     
                        else:
                            existingContents = role.contents
                            #Append new content to existing 
                            if c.code is None:
                                c.code = code 

                            if len([e_cont for e_cont in existingContents if e_cont.name ==  c.name])==0:
                                existingContents.append(c)
                                role.contents = existingContents
                                role.update()
        else:
            for c in self.contentItems():
                if isinstance(c,Content):
                    cnt = Content()
                    qo = cnt.queryObject()
                    cn = qo.filter(Content.name == c.name).first()
                    c.code = cn.code