Changeset 1373


Ignore:
Timestamp:
02/14/07 15:49:32 (13 years ago)
Author:
jukka
Message:

Faster getStoryCandidates method with ability to only get resources that already have a story.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LeMillTool.py

    r1371 r1373  
    2323from AccessControl import ClassSecurityInfo 
    2424from Products.CMFCore.utils import getToolByName 
    25 from config import SEARCHABLE_TYPES, CONTENT_TYPES, COMMUNITY_TYPES, TOOLS_TYPES, ACTIVITY_TYPES, MATERIAL_TYPES 
     25from config import SEARCHABLE_TYPES, CONTENT_TYPES, COMMUNITY_TYPES, TOOLS_TYPES, ACTIVITY_TYPES, MATERIAL_TYPES, GOOD_STORIES_ONLY 
    2626from permissions import MANAGE_PORTAL 
    2727from itertools import chain 
     
    180180 
    181181    def getStoryCandidate(self, only_with_story=False): 
    182         """ Random pick for one content, method and tool """ 
     182        """ Random pick for one content, method and tool or story if only_with_story """ 
    183183        pc=getToolByName(self, 'portal_catalog') 
    184         rc=getToolByName(self, 'reference_catalog')         
    185         full_results=pc({'review_state':'public','getHasCoverImage':True}) 
    186         content=[x for x in full_results if x.meta_type in MATERIAL_TYPES] 
    187         method=[x for x in full_results if x.meta_type=='Activity'] 
    188         tool=[x for x in full_results if x.meta_type=='Tool'] 
    189         if content: 
    190             content=choice(content).getObject() 
    191         if method: 
    192             method=choice(method).getObject() 
    193         if tool: 
    194             tool=choice(tool).getObject() 
    195         if content and method and tool: 
    196             story=None 
    197             stories2=pc({'getRawRelatedContent':content.UID(), 'getRawRelatedMethods':method.UID(), 'getRawRelatedTools':tool.UID()}) 
    198             print stories2 
    199              
    200             relations_to_this_content=rc({'relationship':'relatesToContent', 'targetUID':content.UID()}) 
    201             stories=[x.sourceUID for x in relations_to_this_content] 
    202             good_stories=[] 
    203             for storc in stories: 
    204                 if rc({'sourceUID':storc, 'relationship':'relatesToMethods', 'targetUID':method.UID()}) and rc({'sourceUID':storc, 'relationship':'relatesToTools', 'targetUID':tool.UID()}): 
    205                     good_stories.append(storc) 
    206             if good_stories: 
    207                 story=choice(good_stories) 
    208                 story=self.uid_catalog(UID=story)[0].getObject() 
    209               
    210         else: 
    211             story=None 
     184        if GOOD_STORIES_ONLY or only_with_story: 
     185            stories=pc({'portal_type':'Story', 'review_state':'public'}) 
     186            story=choice(stories) 
     187            story=story.getObject() 
     188            content=story.getRelatedContent() 
     189            method=story.getRelatedActivities() 
     190            tool=story.getRelatedTools() 
     191            if content: 
     192                content=content[0] 
     193            if method: 
     194                method=method[0] 
     195            if tool: 
     196                tool=tool[0] 
     197        else:            
     198            full_results=pc({'review_state':'public','getHasCoverImage':True}) 
     199            content=[x for x in full_results if x.meta_type in MATERIAL_TYPES] 
     200            method=[x for x in full_results if x.meta_type=='Activity'] 
     201            tool=[x for x in full_results if x.meta_type=='Tool'] 
     202            if content: 
     203                content=choice(content).getObject() 
     204            if method: 
     205                method=choice(method).getObject() 
     206            if tool: 
     207                tool=choice(tool).getObject() 
     208            if content and method and tool: 
     209                stories=pc({'getRawRelatedContent':content.UID(), 'getRawRelatedActivities':method.UID(), 'getRawRelatedTools':tool.UID()}) 
     210                if stories: 
     211                    story=choice(stories) 
     212                    story=story.getObject()              
     213                else: 
     214                    story=None 
     215            else: 
     216                story=None 
    212217        candidate = {'chcontent':content, 'method':method, 'tool':tool, 'story':story} 
    213         print candidate 
    214218        return candidate 
    215219         
  • trunk/Story.py

    r1371 r1373  
    1717# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    1818 
    19 from SharedMetadata import target_group_schema, description, tags, coverImage 
     19from SharedMetadata import target_group_schema, description, tags, coverImage, deletionReason 
    2020from Resources import Resource 
    2121from Products.Archetypes.public import * 
     
    3030from config import * 
    3131 
    32 schema = BaseSchema + description + tags + target_group_schema + Schema(( 
     32schema = BaseSchema + description + tags + target_group_schema + deletionReason + Schema(( 
    3333    WYSIWYMField('bodyText', 
    3434        required=True, 
  • trunk/config.py

    r1362 r1373  
    304304FILTER_LINK_ORDER = ('Learning resource', 'Piece', 'LeMillReference') 
    305305 
     306# Front-page shows only resources that already have stories, no random combinations. 
     307GOOD_STORIES_ONLY = False 
  • trunk/skins/lemill/portlet_story_actions.pt

    r1371 r1373  
    1010                    can_moderate here/canIModerate;"> 
    1111<tal:visible condition="python:wf_state!='deleted'"> 
    12     <div class="tb-portlet" metal:use-macro="here/portlet_activity_actions/macros/image_div"/> 
     12 
     13 
     14    <div metal:use-macro="here/portlet_member/macros/memberportrait" /> 
    1315 
    1416    <tal:history condition="is_History"> 
Note: See TracChangeset for help on using the changeset viewer.