Changeset 542

Show
Ignore:
Timestamp:
08/15/07 01:55:04 (1 year ago)
Author:
brian
Message:

whatever you do, don't commit this

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pagoda/trunk/Pagoda/pagoda/models/node.py

    r541 r542  
    2424 
    2525class Node(Revision): 
     26    def __repr__(self): 
     27        cls = self.__class__ 
     28        cols = cls.c.keys() 
     29        return "%s(%s)" % ( 
     30            cls.__name__, 
     31            ", ".join(["%s=%r" % (col, getattr(self, col)) for col in cols]) 
     32        ) 
     33     
    2634    def query_latest_children(self): 
    2735        cls = self.__class__ 
     
    3745            parent_id=self.content_id 
    3846        ) 
    39      
    40     def __repr__(self): 
    41         cls = self.__class__ 
    42         cols = cls.c.keys() 
    43         return "%s(%s)" % ( 
    44             cls.__name__, 
    45             ", ".join(["%s=%r" % (col, getattr(self, col)) for col in cols]) 
     47 
     48    def delete_node(self, revision_status=workflow.PENDING): 
     49        return self.new_revision( 
     50            is_deleted=True, 
     51            revision_status=revision_status 
    4652        ) 
    4753 
    48 assign_mapper(session.context, Node, node_table, inherits=Revision.mapper) 
    49  
     54assign_mapper(session.context, Node, node_table, 
     55    inherits=Revision.mapper, 
     56    properties={ 
     57        'template': relation(Template) 
     58    } 
     59
  • pagoda/trunk/Pagoda/pagoda/models/revision.py

    r541 r542  
    2020    Column('revision_time', DateTime, nullable=False, default=now), 
    2121    Column('revision_comment', TEXT, nullable=False, default=""), 
    22     Column('revision_status', Integer, nullable=False, 
    23         default=workflow.PENDING 
    24     ), 
     22    Column('revision_status', Integer, nullable=False, default=workflow.DRAFT), 
    2523    Column('revision_release_time', DateTime, nullable=True), 
    2624    Column('revision_expire_time', DateTime, nullable=True) 
     
    161159assign_mapper(session.context, Revision, revision_table, 
    162160    inherits=Content.mapper, 
    163     properties=dict( 
    164         author=relation(User, lazy=True) 
    165     ) 
     161    polymorphic_on=revision_table.c.content_type, 
     162    properties={ 
     163        'author': relation(User, lazy=True) 
     164    } 
    166165) 
  • pagoda/trunk/Pagoda/pagoda/models/revision_mapper.py

    r541 r542  
    3535        """ 
    3636        Generate a `Select` that retrieves matching revisions from 
    37         `revisioned_table` correlated with `revision_table`. 
     37        `table` correlated with `self.revision_table`. 
    3838         
    3939        If `group_by` is a column name, column, or sequence of columns, it 
    40         will be added to the `Select` - this is necessary for the case of 
     40        will be added to the `Select` -- this is necessary for the case of 
    4141        localized tables where it is necessary to group by the locale. 
    4242         
     
    4444        `revision_table` joined in this `Select`, to prevent it from being 
    4545        confused with the correlated `revision_table`. By default the name 
    46         of `revisioned_table` is used and suffixed with '_revision'. 
     46        of `table` is used and suffixed with '_revision'. 
    4747         
    4848        """ 
     
    5050            join_alias = '%s_revision' % table.name 
    5151         
    52         revision_alias = self.revision_table.alias(join_alias) 
    53  
     52        revision_table = self.revision_table 
     53        revision_alias = revision_table.alias(join_alias) 
     54         
    5455        if group_by is not None: 
    5556            group_by = util.to_list(group_by) 
     
    6465            [max_revision_id], 
    6566            and_( 
    66                 table.c.revision_id <= self.revision_table.c.revision_id, 
     67                table.c.revision_id <= revision_table.c.revision_id, 
    6768                table.c.revision_id == revision_alias.c.revision_id, 
    68                 self.revision_table.c.content_id == revision_alias.c.content_id 
     69                revision_table.c.content_id == revision_alias.c.content_id 
    6970            ), 
    7071            from_obj=[table, revision_alias], 
     
    7374            correlate=False 
    7475        ) 
    75         revisions.correlate(self.revision_table) 
     76        revisions.correlate(revision_table) 
    7677        return revisions 
    77  
     78     
    7879    def add_table(self, table, id_label=None, locale_column=None, 
    7980                  join_alias=None): 
     
    8586 
    8687        subselect = self.revision_subselect(table, locale_column, join_alias) 
    87  
     88         
    8889        self.tables.add(table) 
    8990        self.id_labels[table] = id_label 
    9091        self.subselects[table] = subselect 
    91  
     92     
    9293    def get_selectable(self, alias): 
    9394        # XXX: Danger! Alert! Caution! Hey! 
    9495        # 
    9596        # The order of these tables is important! We want to ensure that the 
    96         # columns from `content_table` and `revision_table` are selected before 
    97         # others! Not only should their names have precedence, but SQLite's 
    98         # query planner actually returns different results if `revision_table` 
    99         # does not come first in the FROM clause. 
     97        # columns from `content_table` and `revision_table` are selected 
     98        # before others! Not only should their names have precedence, but 
     99        # SQLite's query planner actually returns different results if 
     100        # `revision_table` does not come first in the FROM clause. 
    100101        # 
    101102        select_tables = [self.content_table, self.revision_table] 
     
    105106        for select_table in select_tables: 
    106107            # It would be nice to use `select_columns.extend` here. 
    107             # However, `ColumnCollection.extend` and `ColumnCollection.add` allow 
    108             # later additions to overwrite (and change the order of) existing 
    109             # columns with the same name. We want existing columns to take 
    110             # precedence instead. 
     108            # However, `ColumnCollection.extend` and `ColumnCollection.add` 
     109            # allow later additions to overwrite (and change the order of) 
     110            # existing columns with the same name. We want existing columns 
     111            # to take precedence instead. 
    111112            for column in select_table.c: 
    112113                if not select_columns.has_key(column.name): 
     
    121122        revision_table = self.revision_table 
    122123         
    123         in_clauses = [table.c.revision_id.in_(self.subselects[table]) for 
    124                       table in self.tables] 
    125          
    126         id_clauses = [revision_table.c.revision_id == table.c.revision_id for 
    127                       table in self.tables] 
    128  
     124        in_clauses = [table.c.revision_id.in_(self.subselects[table]) 
     125                      for table in self.tables] 
     126         
     127        id_clauses = [revision_table.c.revision_id == table.c.revision_id 
     128                      for table in self.tables] 
     129         
    129130        selectable = select( 
    130131            select_columns, 
    131132            and_( 
    132                 content_table.c.content_id == revision_table.c.content_id, 
     133                # content_table.c.content_id == revision_table.c.content_id, 
     134                 
    133135                # Ensure that the `revision_id` from `revision_table` matches 
    134136                # the `revision_id` from one of the content tables, to prevent 
    135                 # a higher `revision_id` from matching this query but not being 
    136                 # used. 
    137                 or_(*id_clauses), 
     137                # a higher `revision_id` from matching this query but 
     138                # not being used. 
     139                 
     140                # or_(*id_clauses), 
    138141                *in_clauses 
    139142            ), 
     
    161164        """ 
    162165        revision_id, content_id, content_locale = args[0] 
    163         return query.get_by(revision_id=revision_id, content_id=content_id, 
    164                             content_locale=content_locale) 
     166        return query.get_by( 
     167            revision_id=revision_id, 
     168            content_id=content_id, 
     169            content_locale=content_locale 
     170        ) 
    165171     
    166172    def before_insert(self, mapper, connection, instance): 
     
    177183            instance.content_type = mapper.local_table.name 
    178184         
    179         # Order of `key_columns` is important due to dependencies! 
    180         key_columns = [ 
    181             mapper.c.content_id, 
    182             mapper.c.revision_id, 
    183             mapper.c.node_revision_id, 
    184             mapper.c.generic_revision_id, 
    185             mapper.c.localized_revision_id 
    186         ] 
    187          
    188185        insert_tables = util.OrderedSet() 
    189186         
    190         for col in key_columns
     187        for col in mapper.primary_key
    191188            if getattr(instance, col.name) is None: 
    192189                insert_table = get_column_table(col) 
     
    210207                    setattr(instance, column.name, value) 
    211208         
    212         if instance.node_revision_id is None: 
    213             instance.node_revision_id = instance.revision_id 
    214         if instance.generic_revision_id is None: 
    215             instance.generic_revision_id = instance.revision_id 
    216         if instance.localized_revision_id is None: 
    217             instance.localized_revision_id = instance.revision_id 
     209        # Set the labeled `revision_id` foreign keys on `instance`. 
     210        revision_id = get_original_column(mapper.c.revision_id) 
     211        for col in mapper.primary_key: 
     212            # Set instance values only if they are undefined. 
     213            if getattr(instance, col.name) is None: 
     214                # If `col` is a foreign key to `revision.revision_id`, set the 
     215                # corresponding instance value to `revision.revision_id`. 
     216                if col.foreign_key and follow_foreign_key(col) is revision_id: 
     217                    setattr(instance, col.name, instance.revision_id) 
    218218         
    219219        # Tell the session that this instance has already been persisted, 
     
    237237    else: 
    238238        extension = RevisionMapperExtension() 
    239         extensions.append(extension) # XXX: Testing! 
     239        extensions.append(extension) 
    240240    kwargs['extension'] = extensions 
    241241     
  • pagoda/trunk/Pagoda/pagoda/models/util.py

    r505 r542  
    22from datetime import datetime 
    33 
    4 __all__ = ['now', 'get_column_table', 'follow_foreign_key', 
    5            'get_instance_values'] 
     4__all__ = ['now', 'get_original_column', 'get_column_table', 
     5           'follow_foreign_key', 'get_instance_values'] 
    66 
    77now = datetime.utcnow 
    88 
     9def get_original_column(column): 
     10    return list(column.orig_set)[0] 
     11 
    912def get_column_table(column): 
    10     return list(column.orig_set)[0].table 
     13    return get_original_column(column).table 
    1114 
    1215def follow_foreign_key(column): 
  • pagoda/trunk/Pagoda/pagoda/plugins/controllers.py

    r541 r542  
    33from turbogears.database import metadata, session 
    44from turbogears.controllers import Controller 
    5 from pagoda import config 
     5from pagoda import config, workflow 
    66# Relative imports! 
    77import models 
     
    3636            transaction = models.session.create_transaction() 
    3737            try: 
    38                 deleted_content = self.content.new_revision(is_deleted=True) 
     38                deleted_content = self.content.new_revision( 
     39                    is_deleted=True, revision_status=workflow.PENDING 
     40                ) 
    3941                transaction.commit() 
    4042            except models.exceptions.SQLAlchemyError: 
  • pagoda/trunk/Pagoda/pagoda/plugins/page/models.py

    r534 r542  
    22from sqlalchemy.ext.assignmapper import assign_mapper 
    33from turbogears.database import metadata, session 
    4 from pagoda.models import node_table, Node, Revision 
     4from pagoda.models import node_table, Content, Revision, Node 
    55from pagoda.models.revision_mapper import * 
    66 
     
    2323page_selectable.add_table(node_table) 
    2424page_selectable.add_table(page_generic_table, 'generic_revision_id') 
    25 page_selectable.add_table(page_localized_table, 'localized_revision_id', 'content_locale') 
     25page_selectable.add_table( 
     26    page_localized_table, 'localized_revision_id', 'content_locale' 
     27
    2628 
    2729page_table = page_selectable.get_selectable('page') 
     
    3032    pass 
    3133 
    32 revision_mapper(session.context, Page, page_table) 
     34assign_mapper(session.context, Page, page_table, 
     35    inherits=Node.mapper, 
     36    select_table=page_table, 
     37    polymorphic_identity='page', 
     38    inherit_condition=or_( 
     39        page_table.c.revision_id == node_table.c.revision_id, 
     40        page_table.c.revision_id == page_generic_table.c.revision_id, 
     41        page_table.c.revision_id == page_localized_table.c.revision_id 
     42    ) 
     43
  • pagoda/trunk/Pagoda/pagoda/plugins/textcontainer/__init__.py

    r536 r542  
    1 # from pagoda.plugins.textcontainer.models import * 
    2 # from pagoda.plugins.textcontainer.controllers import * 
     1from pagoda.plugins.textcontainer.models import * 
     2from pagoda.plugins.textcontainer.controllers import * 
  • pagoda/trunk/Pagoda/pagoda/plugins/textcontainer/models.py

    r537 r542  
    1 # from sqlalchemy import * 
    2 # from sqlalchemy.ext.assignmapper import assign_mapper 
    3 # from turbogears.database import metadata, session 
    4 # from pagoda.models import Revision 
    5 # from pagoda.models.revision_mapper import * 
    6 #  
    7 # __all__ = ['textcontainer_generic_table', 'textcontainer_localized_table', 
    8 #            'textcontainer_table', 'TextContainer'] 
    9 #  
    10 # textcontainer_generic_table = Table('textcontainer_generic', metadata, 
    11 #     Column('revision_id', None, ForeignKey(Revision.c.revision_id), 
    12 #         primary_key=True 
    13 #     ), 
    14 #     Column('container_name', Unicode(75), nullable=False), 
    15 #     Column('editor_name', String(75), nullable=True) 
    16 # ) 
    17 #  
    18 # textcontainer_localized_table = Table('textcontainer_localized', metadata, 
    19 #     Column('revision_id', None, ForeignKey(Revision.c.revision_id), 
    20 #         primary_key=True 
    21 #     ), 
    22 #     Column('content_locale', String(8), nullable=False), 
    23 #     Column('text', Unicode, nullable=False, default="") 
    24 # ) 
    25 #  
    26 # # textcontainer_table = revisioned_table('textcontainer', 
    27 # #     textcontainer_generic_table, textcontainer_localized_table 
    28 # # ) 
    29 #  
    30 # class TextContainer(Revision): 
    31 #     pass 
    32 #  
    33 # # revision_mapper(session.context, TextContainer, textcontainer_table) 
     1from sqlalchemy import * 
     2from turbogears.database import metadata, session 
     3from pagoda.models import Revision 
     4from pagoda.models.revision_mapper import * 
     5 
     6__all__ = ['textcontainer_generic_table', 'textcontainer_localized_table', 
     7           'textcontainer_table', 'TextContainer'] 
     8 
     9textcontainer_generic_table = Table('textcontainer_generic', metadata, 
     10    Column('revision_id', None, ForeignKey(Revision.c.revision_id), 
     11        primary_key=True 
     12    ), 
     13    Column('container_name', Unicode(75), nullable=False), 
     14    Column('editor_name', String(75), nullable=True) 
     15
     16 
     17textcontainer_localized_table = Table('textcontainer_localized', metadata, 
     18    Column('revision_id', None, ForeignKey(Revision.c.revision_id), 
     19        primary_key=True 
     20    ), 
     21    Column('content_locale', String(8), nullable=False), 
     22    Column('text', Unicode, nullable=False, default="") 
     23
     24 
     25textcontainer_selectable = RevisionSelectable() 
     26textcontainer_selectable.add_table( 
     27    textcontainer_generic_table, 'generic_revision_id' 
     28
     29textcontainer_selectable.add_table( 
     30    textcontainer_localized_table, 'localized_revision_id', 'content_locale' 
     31
     32 
     33textcontainer_table = textcontainer_selectable.get_selectable('textcontainer') 
     34 
     35class TextContainer(Revision): 
     36    pass 
     37 
     38revision_mapper(session.context, TextContainer, textcontainer_table) 
  • pagoda/trunk/Pagoda/pagoda/workflow.py

    r455 r542  
    11""" 
    2 Defines the constants DRAFT, PENDING, APPROVED and DELETED, which are used in 
     2Defines the constants DRAFT, PENDING, and APPROVED, which are used in 
    33the `status` column of the `Revision` mapper to indicate the workflow state. 
    44 
     
    88PENDING = 1 # The content has been submitted for approval. 
    99APPROVED = 2 # The content has been approved for publication. 
    10 DELETED = 3 # The content has been approved for deletion. 
  • pagoda/trunk/TestProject/testproject/model.py

    r538 r542  
    22from sqlalchemy import * 
    33from turbogears.database import metadata, session 
    4 from sqlalchemy.ext.assignmapper import assign_mapper 
    54from turbogears import identity 
    65from pagoda.plugins.page import Page 
     
    3231    session.flush() 
    3332     
    34     home_page = Page(url=None, parent_id=None, content_locale='en_US', 
     33    home_page = Page( 
     34        url=None, parent_id=None, content_locale='en_US', 
    3535        title="Home", nav_show=True, revision_author_id=brian.user_id, 
    36         content_type='page', revision_status=workflow.APPROVED) 
     36        content_type='page', revision_status=workflow.APPROVED 
     37    ) 
    3738     
    3839    session.flush() 
     
    105106    # session.flush() 
    106107    #  
    107      
    108108    # pagoda_page_revised = Page( 
    109109    #     content_id=pagoda_page.content_id, 
     
    113113    #     title="Welcome! (Now typo free.)" 
    114114    # ) 
    115      
    116115    #  
    117116    # session.flush() 

Log in as guest/pagoda to create tickets