Ejemplo n.º 1
0
Archivo: page.py Proyecto: alkadis/vcv
    def create(cls,
               instance,
               title,
               text,
               creator,
               function=NORM,
               tags=None,
               wiki=False,
               formatting=False,
               sectionpage=False,
               allow_comment=True,
               allow_selection=True,
               always_show_original=True,
               abstract=None):
        from adhocracy.lib.text import title2alias
        from text import Text
        from tagging import Tagging
        if function not in Page.FUNCTIONS:
            raise AttributeError("Invalid page function type")
        label = title2alias(title)
        page = Page(instance, label, creator, function, formatting,
                    sectionpage, allow_comment, allow_selection,
                    always_show_original, abstract)
        meta.Session.add(page)
        meta.Session.flush()
        Text(page, Text.HEAD, creator, title, text, wiki)

        if tags is not None:
            page.taggings = Tagging.create_all(page, tags, creator)

        return page
Ejemplo n.º 2
0
    def create(cls, instance, title, text, creator, function=NORM, tags=None,
               wiki=False):
        from adhocracy.lib.text import title2alias
        from text import Text
        from tagging import Tagging
        if function not in Page.FUNCTIONS:
            raise AttributeError("Invalid page function type")
        label = title2alias(title)
        page = Page(instance, label, creator, function)
        meta.Session.add(page)
        meta.Session.flush()
        Text(page, Text.HEAD, creator, title, text, wiki)

        if tags is not None:
            page.taggings = Tagging.create_all(page, tags, creator)

        return page
Ejemplo n.º 3
0
    def create(cls, instance, title, text, creator, function=NORM, tags=None,
               wiki=False, formatting=False, sectionpage=False,
               allow_comment=True, allow_selection=True,
               always_show_original=True, abstract=None):
        from adhocracy.lib.text import title2alias
        from text import Text
        from tagging import Tagging
        if function not in Page.FUNCTIONS:
            raise AttributeError("Invalid page function type")
        label = title2alias(title)
        page = Page(instance, label, creator, function, formatting,
                    sectionpage, allow_comment, allow_selection,
                    always_show_original, abstract)
        meta.Session.add(page)
        meta.Session.flush()
        Text(page, Text.HEAD, creator, title, text, wiki)

        if tags is not None:
            page.taggings = Tagging.create_all(page, tags, creator)

        return page
Ejemplo n.º 4
0
    def create(cls,
               instance,
               title,
               text,
               creator,
               function=NORM,
               tags=None,
               wiki=False):
        from adhocracy.lib.text import title2alias
        from text import Text
        from tagging import Tagging
        if function not in Page.FUNCTIONS:
            raise AttributeError("Invalid page function type")
        label = title2alias(title)
        page = Page(instance, label, creator, function)
        meta.Session.add(page)
        meta.Session.flush()
        Text(page, Text.HEAD, creator, title, text, wiki)

        if tags is not None:
            page.taggings = Tagging.create_all(page, tags, creator)

        return page
Ejemplo n.º 5
0
    def _to_python(self, value, state):
        from adhocracy.model import Page
        from adhocracy.lib.text import title2alias
        value = super(ValidTitle, self)._to_python(value, state)

        if self.unused_label and not Page.unused_label(title2alias(value)):
            raise formencode.Invalid(
                _("An entry with this title already exists"), value, state)

        if not value or len(value) < 2:
            raise formencode.Invalid(_("No page name is given."), value, state)

        if value.lower() in FORBIDDEN_NAMES:
            raise formencode.Invalid(_("Invalid page name: %s") % value,
                                     value, state)

        try:
            int(value)
            raise formencode.Invalid(
                _("Variant name cannot be purely numeric: %s") % value,
                value, state)
        except:
            return value
def upgrade(migrate_engine):
    meta.bind = migrate_engine
    proposal_table = Table('proposal', meta,
        Column('id', Integer, ForeignKey('delegateable.id'), primary_key=True),
        Column('comment_id', Integer, ForeignKey('comment.id'), nullable=True),
        Column('adopt_poll_id', Integer, ForeignKey('poll.id'), nullable=True),
        Column('rate_poll_id', Integer, ForeignKey('poll.id'), nullable=True),
        Column('adopted', Boolean, default=False)
        )
    
    description = Column('description_id', Integer, nullable=True) # ForeignKey('page.id'), 
    if migrate_engine.url.drivername == "sqlite":
        description = Column('description_id', Integer, nullable=True)
    description.create(proposal_table)
    
    q1 = migrate_engine.execute(proposal_table.select())
    for (prop_id, comment_id, _, _, _, _) in q1:
        instance_id = None
        label = None
        ctime = None
        dtime = None
        q4 = migrate_engine.execute(delegateable_table.select(' delegateable.id = %d ' % prop_id))
        for (_, _label, _type, _ctime, _dtime, _, _, _instance_id) in q4:
            instance_id = _instance_id
            label = _label
            ctime = _ctime
            dtime = _dtime
        
        if comment_id is None: 
            continue
        
        q2 = migrate_engine.execute(comment_table.select(' comment.id = %d ' % comment_id))
        for (_, _, _, creator_id, topic_id, _, _, _, poll_id) in q2:
            migrate_engine.execute(vote_table.delete(vote_table.c.poll_id==poll_id))
            migrate_engine.execute(tally_table.delete(tally_table.c.poll_id==poll_id))
            migrate_engine.execute(poll_table.delete(poll_table.c.id==poll_id))
        
            
            q3 = delegateable_table.insert(values={'label': text.title2alias(label), 
                                          'type': u'page',
                                          'create_time': ctime,
                                          'delete_time': None,
                                          'creator_id': creator_id,
                                          'instance_id': instance_id})
            r = migrate_engine.execute(q3)
            page_id = r.last_inserted_ids()[-1]
            
            q5 = page_table.insert(values={'id': page_id, 
                                           'function': u'description'})
            r = migrate_engine.execute(q5)
            
            q10 = category_graph.insert(values={'parent_id': page_id, 
                                               'child_id': prop_id})
            r = migrate_engine.execute(q10)
            
            u4 = proposal_table.update(proposal_table.c.id==prop_id, values={
                'description_id': page_id,
                'comment_id': None
                })
            migrate_engine.execute(u4)
            
            q6 = migrate_engine.execute(revision_table.select(' revision.comment_id = %d ' % comment_id))
            last_id = None
            for (r_id, t_ctime, t_text, _, t_creator_id, _) in q6:
                q7 = text_table.insert(values={'title': label, 
                                              'text': t_text,
                                              'create_time': t_ctime,
                                              'delete_time': None,
                                              'user_id': t_creator_id,
                                              'page_id': page_id,
                                              'variant': u'HEAD',
                                              'parent_id': last_id})
                r = migrate_engine.execute(q7)
                last_id = r.last_inserted_ids()[-1]
                
            def move_comment(data):
                (c_id, c_ctime, c_dtime, c_user_id, c_topic_id, c_can, c_wiki, c_reply_id, c_poll_id) = data
                
                if c_reply_id == comment_id:
                    u1 = comment_table.update(comment_table.c.id==c_id, values={
                        'reply_id': None
                        })
                    migrate_engine.execute(u1)
                
                u2 = comment_table.update(comment_table.c.id==c_id, values={
                    'topic_id': page_id
                    })
                migrate_engine.execute(u2)
                
                u3 = poll_table.update(poll_table.c.id==c_poll_id, values={
                    'scope_id': page_id
                    })
                migrate_engine.execute(u3)
                migrate_engine.execute(tally_table.delete(tally_table.c.poll_id==c_poll_id))
                
                q8 = migrate_engine.execute(comment_table.select(' comment.reply_id = %d ' % c_id))
                for d in q8: 
                    move_comment(d)
                    
            q9 = migrate_engine.execute(comment_table.select(' comment.reply_id = %d ' % comment_id))
            for d in q9: 
                move_comment(d)
            
            migrate_engine.execute(revision_table.delete(revision_table.c.comment_id==comment_id))   
            migrate_engine.execute(comment_table.delete(comment_table.c.id==comment_id))   
Ejemplo n.º 7
0
def upgrade(migrate_engine):
    meta.bind = migrate_engine
    proposal_table = Table(
        'proposal', meta,
        Column('id', Integer, ForeignKey('delegateable.id'), primary_key=True),
        Column('comment_id', Integer, ForeignKey('comment.id'), nullable=True),
        Column('adopt_poll_id', Integer, ForeignKey('poll.id'), nullable=True),
        Column('rate_poll_id', Integer, ForeignKey('poll.id'), nullable=True),
        Column('adopted', Boolean, default=False))

    description = Column('description_id', Integer,
                         nullable=True)  # ForeignKey('page.id'),
    if migrate_engine.url.drivername == "sqlite":
        description = Column('description_id', Integer, nullable=True)
    description.create(proposal_table)

    q1 = migrate_engine.execute(proposal_table.select())
    for (prop_id, comment_id, _, _, _, _) in q1:
        instance_id = None
        label = None
        ctime = None
        dtime = None
        q4 = migrate_engine.execute(
            delegateable_table.select(' delegateable.id = %d ' % prop_id))
        for (_, _label, _type, _ctime, _dtime, _, _, _instance_id) in q4:
            instance_id = _instance_id
            label = _label
            ctime = _ctime
            dtime = _dtime

        if comment_id is None:
            continue

        q2 = migrate_engine.execute(
            comment_table.select(' comment.id = %d ' % comment_id))
        for (_, _, _, creator_id, topic_id, _, _, _, poll_id) in q2:
            migrate_engine.execute(
                vote_table.delete(vote_table.c.poll_id == poll_id))
            migrate_engine.execute(
                tally_table.delete(tally_table.c.poll_id == poll_id))
            migrate_engine.execute(
                poll_table.delete(poll_table.c.id == poll_id))

            q3 = delegateable_table.insert(
                values={
                    'label': text.title2alias(label),
                    'type': u'page',
                    'create_time': ctime,
                    'delete_time': None,
                    'creator_id': creator_id,
                    'instance_id': instance_id
                })
            r = migrate_engine.execute(q3)
            page_id = r.last_inserted_ids()[-1]

            q5 = page_table.insert(values={
                'id': page_id,
                'function': u'description'
            })
            r = migrate_engine.execute(q5)

            q10 = category_graph.insert(values={
                'parent_id': page_id,
                'child_id': prop_id
            })
            r = migrate_engine.execute(q10)

            u4 = proposal_table.update(proposal_table.c.id == prop_id,
                                       values={
                                           'description_id': page_id,
                                           'comment_id': None
                                       })
            migrate_engine.execute(u4)

            q6 = migrate_engine.execute(
                revision_table.select(' revision.comment_id = %d ' %
                                      comment_id))
            last_id = None
            for (r_id, t_ctime, t_text, _, t_creator_id, _) in q6:
                q7 = text_table.insert(
                    values={
                        'title': label,
                        'text': t_text,
                        'create_time': t_ctime,
                        'delete_time': None,
                        'user_id': t_creator_id,
                        'page_id': page_id,
                        'variant': u'HEAD',
                        'parent_id': last_id
                    })
                r = migrate_engine.execute(q7)
                last_id = r.last_inserted_ids()[-1]

            def move_comment(data):
                (c_id, c_ctime, c_dtime, c_user_id, c_topic_id, c_can, c_wiki,
                 c_reply_id, c_poll_id) = data

                if c_reply_id == comment_id:
                    u1 = comment_table.update(comment_table.c.id == c_id,
                                              values={'reply_id': None})
                    migrate_engine.execute(u1)

                u2 = comment_table.update(comment_table.c.id == c_id,
                                          values={'topic_id': page_id})
                migrate_engine.execute(u2)

                u3 = poll_table.update(poll_table.c.id == c_poll_id,
                                       values={'scope_id': page_id})
                migrate_engine.execute(u3)
                migrate_engine.execute(
                    tally_table.delete(tally_table.c.poll_id == c_poll_id))

                q8 = migrate_engine.execute(
                    comment_table.select(' comment.reply_id = %d ' % c_id))
                for d in q8:
                    move_comment(d)

            q9 = migrate_engine.execute(
                comment_table.select(' comment.reply_id = %d ' % comment_id))
            for d in q9:
                move_comment(d)

            migrate_engine.execute(
                revision_table.delete(
                    revision_table.c.comment_id == comment_id))
            migrate_engine.execute(
                comment_table.delete(comment_table.c.id == comment_id))