Changeset 579

Show
Ignore:
Timestamp:
10/19/06 08:59:57
Author:
chervol
Message:

merge Quinta customizations in blog

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • SimpleBlog/branches/plone-2.5/content/blog.py

    r578 r579  
    88import Products.SimpleBlog.Permissions 
    99from Products.CMFCore.utils import getToolByName 
     10 
     11import MetaWeblogAPI 
     12import BloggerAPI 
     13import MovableTypeAPI 
    1014 
    1115from Products.ATContentTypes.content.base import ATCTFolder 
     
    3842                                      description='Set the maximum number of BlogEntries to display.'),  
    3943                 default=20), 
     44    LinesField('categories',  
     45               widget=LinesWidget(label='Possible Categories',  
     46                                  label_msgid="label_categories", 
     47                                  description_msgid="help_categories", 
     48                                  i18n_domain="SimpleBlog", 
     49                                  description='Supply the list of possible categories that can be used in SimpleBlog Entries.')), 
    4050    BooleanField('warnForUnpublishedEntries',  
    4151             default=1,  
     
    4555                        description_msgid="help_warnForUnpublishedEntries", 
    4656                        description='When checked, a warning will be displayed on the blog\'s frontpage if there are entries that are not yet published.')), 
    47     BooleanField('allowCrossPosting',  
     57    BooleanField('allowCrossPosting', 
    4858             default=0,  
    49              widget=BooleanWidget(condition="python:0", # this line have to be removed in order to be visible/editable 
    50                         label='Allow cross-posting',  
     59             widget=BooleanWidget(condition="python:0", # hide the field 
     60                        label='Allow cross-posting', 
    5161                        i18n_domain="SimpleBlog", 
    5262                        label_msgid="label_allowCrossPosting", 
    5363                        description_msgid="help_allowCrossPosting", 
    5464                        description='When checked, this blog will include cross-post entries from other blogs.')), 
    55     LinesField('categories',  
    56                widget=LinesWidget(label='Possible Categories',  
    57                                   label_msgid="label_categories", 
    58                                   description_msgid="help_categories", 
    59                                   i18n_domain="SimpleBlog", 
    60                                   description='Supply the list of possible categories that can be used in SimpleBlog Entries.')), 
     65    LinesField('tags', 
     66               mutator = 'setTags', 
     67               widget=LinesWidget(label="Tags", 
     68                                  description='List of tags.'), 
     69               ), 
     70    BooleanField('tagsEnabled', 
     71                  accessor = 'isTagsEnabled', 
     72                  default = 1, 
     73                  schemata = 'interface', 
     74                  widget = BooleanWidget(label='Enable technorati tags', 
     75                                     label_msgid="label_enable_tags", 
     76                                     description_msgid="help_enable_tags",), 
     77              ), 
    6178    BooleanField('allowTrackback', 
    6279                  default = 1, 
     
    7693                                    description_msgid="help_adminEmail", 
    7794                                    i18n_domain="SimpleBlog", 
    78                                                    condition="python:0", # this line have to be removed in order to be visible/editable 
    79                                     description="Enter administrator's email for receaving notification about blog's activity"), 
     95                                    condition="python:0", # this line have to be removed in order to be visible/editable 
     96                                    description="Enter administrator's email for receiving notification about blog's activity"), 
    8097               ), 
    81  
     98    BooleanField('allowDelicious', 
     99                default = 1, 
     100                accessor = 'isDeliciousEnabled', 
     101                schemata = 'interface',  
     102                widget=BooleanWidget(label="Turn Delicious bookmarklet", 
     103                                    label_msgid="label_allow_delicious", 
     104                                    description_msgid="help_allow_delicious"), 
     105                ), 
     106    BooleanField('allowDigg', 
     107                default = 1, 
     108                accessor = 'isDiggEnabled', 
     109                schemata = 'interface', 
     110                widget=BooleanWidget(label="Turn Digg bookmarklet", 
     111                                    label_msgid="label_allow_digg", 
     112                                    description_msgid="help_allow_digg"), 
     113                ), 
     114    BooleanField('allowYahoo', 
     115                default = 1, 
     116                accessor = 'isYahooEnabled', 
     117                schemata = 'interface',  
     118                widget=BooleanWidget(label="Turn Yahoo bookmarklet", 
     119                                    label_msgid="label_allow_yahoo", 
     120                                    description_msgid="help_allow_yahoo"), 
     121                ), 
     122    BooleanField('allowGoogle', 
     123                default = 1, 
     124                accessor = 'isGoogleEnabled', 
     125                schemata = 'interface', 
     126                widget=BooleanWidget(label="Turn Google bookmarklet", 
     127                                    label_msgid="label_allow_google", 
     128                                    description_msgid="help_allow_google"), 
     129                ), 
     130    BooleanField('allowSpurl', 
     131                default = 1, 
     132                accessor = 'isSpurlEnabled', 
     133                schemata = 'interface',  
     134                widget=BooleanWidget(label="Turn Spurl bookmarklet", 
     135                                    label_msgid="label_allow_spurl", 
     136                                    description_msgid="help_allow_spurl"), 
     137                ), 
    82138        )) 
    83139 
     
    93149    schema = schema 
    94150    global_allow=1 
    95      
     151 
    96152    default_view = 'simpleblog_view_title_description' 
    97153    immediate_view = 'simpleblog_view_title_description' 
     
    101157    allowed_content_types=('BlogEntry', 'BlogFolder', 'Link', 'Image', 'File', 'Portlet') 
    102158 
     159    blogger = None 
     160    metaWeblog = None 
     161 
     162    def initializeArchetype(self, **kwargs): 
     163        BaseFolder.initializeArchetype(self, **kwargs) 
     164        RPCAuth = self.simpleblog_tool.findRPCAuth(self) 
     165 
     166        # Setup the MetaWeblog API 
     167        self.metaWeblog = MetaWeblogAPI.MetaWeblogAPI().__of__(self) 
     168        self.metaWeblog.setupRPCAuth(RPCAuth) 
     169 
     170        # Setup the Blogger API 
     171        self.blogger = BloggerAPI.BloggerAPI().__of__(self) 
     172        self.blogger.setupRPCAuth(RPCAuth) 
     173 
     174        # Setup the MovableTypeAPI API 
     175        self.mt = MovableTypeAPI.MovableTypeAPI().__of__(self) 
     176        self.mt.setupRPCAuth(RPCAuth)     
     177 
    103178    def canSetDefaultPage(self): 
    104179        return False 
    105  
    106180 
    107181    def manage_afterAdd(self, item, container): 
     
    114188        # get brains for items that are published within the context of this blog. 
    115189        entries = self.simpleblog_tool.searchForEntries(self, maxResults=0) 
    116          
     190 
    117191        # convert to objects 
    118192        objs = [e.getObject() for e in entries] 
    119193        return objs 
    120          
     194 
    121195    def listCategories(self): 
    122196        cats=self.getCategories() 
    123             
     197 
    124198        # add the global categories 
    125199        for c in self.simpleblog_tool.getGlobalCategories(): 
    126200            if not c in cats: 
    127                 cats.append(c)            
     201                cats.append(c) 
    128202        cats = list(cats) 
    129203        cats.sort() 
    130         return tuple(cats)                 
     204        return tuple(cats) 
    131205 
    132206    def getForeignEntries(self): 
     
    134208        return [f for f in self.getBRefs('AppearsIn') if self.portal_membership.checkPermission('View', f)] 
    135209 
    136          
    137210    def getEntries(self, category=None, maxResults=None, fromHere=0, filterState=1, sort=1, join=0, addCrossPostInfo=0, **kwargs): 
    138211        """ Return all the contained published entries, real objects, not the brains """ 
    139212        # see simpleblog_tool.searchForEntries for API description 
    140  
    141213        query=kwargs 
    142  
    143214        publishedState = self.simpleblog_tool.getPublishedState() 
    144          
    145215        if category!=None: 
    146216            query['EntryCategory']=category 
    147  
    148217        query['getAlwaysOnTop']=1 
    149          
    150218        if filterState: 
    151219            query['review_state']=publishedState             
    152      
    153220        # first the items that need to be listed on top 
    154221        localOnTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') 
    155222        localOnTop = [r.getObject() for r in localOnTop ] 
    156          
    157223        # then the other items 
    158224        query['getAlwaysOnTop']=0 
    159225        localNoTop = self.portal_catalog.searchResults(query, meta_type='BlogEntry', path={'query':self.simpleblog_tool.getObjectPath(self),'level':0}, sort_order='reverse', sort_on='effective') 
    160226        localNoTop= [r.getObject() for r in localNoTop]         
    161          
     227 
    162228        # foreign items 
    163229        if self.getAllowCrossPosting(): 
     
    169235        foreignOnTop = [e for e in foreignEntries if e.getAlwaysOnTop()] 
    170236        foreignNoTop = [e for e in foreignEntries if not e.getAlwaysOnTop()] 
    171          
    172237        # so, now we have: 
    173238        # total = localOnTop + foreignOnTop + localNoTop + foreignNoTop 
    174239        # and that needs to be sorted 
    175          
    176  
    177240        if addCrossPostInfo: 
    178241            # make each object a tuple (obj, <iscrosspost>) 
     
    181244            localOnTop = [(e,0) for e in localOnTop] 
    182245            localNoTop = [(e,0) for e in localNoTop] 
    183          
    184246        onTop = foreignOnTop + localOnTop 
    185247        onBottom = foreignNoTop + localNoTop 
    186          
    187248        if sort and foreignEntries: 
    188249            if addCrossPostInfo: 
     
    192253                onTop.sort((lambda x,y:cmp(y.effective(), x.effective()))) 
    193254                onBottom.sort((lambda x,y:cmp(y.effective(), x.effective()))) 
    194                        
    195255        if join: 
    196256            results = onTop+onBottom 
     
    200260                return results[:self.simpleblog_tool.getMaxItemsInPortlet()] 
    201261            else: 
    202                 return results[:maxResults]                
     262                return results[:maxResults] 
    203263        else: 
    204264            return (onTop, onBottom) 
    205          
     265 
    206266    def getAdminEmail(self): 
    207267        """ return blog admin email or root email """ 
     
    212272        return val 
    213273 
     274    def setTags(self, value, **kwargs): 
     275        """ Save tags in lower case """ 
     276        value = unique(value) 
     277        value.sort(lambda x, y: cmp(x,y)) 
     278        self.getField('tags').set(self, value, **kwargs) 
     279 
    214280registerType(Blog) 
    215281