Changeset 2998

Show
Ignore:
Timestamp:
01/15/10 17:25:30 (2 years ago)
Author:
jukka
Message:

Fixed #1958, made References to be proper materials and also changed branching to be an ability that materials don't have unless explicitly added.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CommonMixIn.py

    r2975 r2998  
    3131from types import MethodType as instancemethod 
    3232import time, re, traceback, transaction 
    33  
    3433 
    3534# For sortable_title -method 
     
    110109    def isDiscussable(self): 
    111110        """ We are not, but can be overrided by more complex resources """ 
     111        return False 
     112 
     113    def isBranchable(self): 
    112114        return False 
    113115 
  • trunk/LeMillReference.py

    r2979 r2998  
    2424from config import PROJECTNAME, MODIFY_CONTENT, VIEW 
    2525from Material import Material 
    26 from Schemata import material_schema, description 
     26from Schemata import material_schema, description,  author_schema, group_sharing 
    2727 
    2828 
     
    120120 
    121121 
    122 schema = material_schema + description + lemillreference_schema 
     122schema = material_schema + description + author_schema + group_sharing + lemillreference_schema 
    123123 
    124124schema = schema.copy() 
  • trunk/LeMillTool.py

    r2997 r2998  
    16631663        pc=getToolByName(self, 'portal_catalog') 
    16641664        if portal_type=='content': 
    1665             portal_type=list(MATERIAL_TYPES)+['LeMillReference','LeMillPrintResource'] 
     1665            portal_type=list(MATERIAL_TYPES)+['LeMillPrintResource'] 
    16661666        return pc(portal_type=portal_type, getState="public") 
    16671667 
  • trunk/LearningResource.py

    r2949 r2998  
    140140        else: 
    141141            member_id = lutool.getAuthenticatedId() 
    142         if getattr(self, 'editingMode', '')=='other_users_can_edit_a_copy' and not (self.amIOwner() or self.canIModerate()): 
    143             return False             
     142        if self.isBranchable(): 
     143            if not self.branchableEditingCheck(): 
     144                return False 
    144145        if not getattr(self, 'getGroupEditing', False): 
    145146            return True 
  • trunk/LessonPlan.py

    r2949 r2998  
    2626from Material import Material 
    2727from permissions import MODIFY_CONTENT 
     28from Branchable import Branchable 
    2829 
    2930lessonplan_schema = Schema(( 
     
    113114 
    114115 
    115 class LessonPlan(Material): 
     116class LessonPlan(Branchable, Material): 
    116117    """Lesson plan""" 
    117118    schema = schema 
  • trunk/Material.py

    r2975 r2998  
    6565        return text 
    6666 
    67     ############ Workflow methods ################################# 
    68  
    69     def canDeleteOnCancel(self): 
    70         """ Materials can have newly created branches that may look like good objects but they aren't """ 
    71         history=self.getHistory() 
    72         if not history: 
    73             return True 
    74         summary=history[0].get('_summary','') 
    75         if summary.startswith('Copy of '):  # this is a newly created branch 
    76             return True   
    77         return LearningResource.canDeleteOnCancel(self) 
    78  
    79     security.declarePrivate('manage_beforeDelete') 
    80     def manage_beforeDelete(self, item, container): 
    81         """ When deleting, remove branch-related references. """         
    82         if self.Schema().has_key('branch_of'): 
    83             branch_parent= self.getBranch_of() 
    84             storeRefs = getattr(item, '_v_cp_refs', None) 
    85             if branch_parent and not storeRefs: 
    86                 branch_parent.removeFromBranches(self.UID()) 
    87         LearningResource.manage_beforeDelete(self, item, container) 
    88  
    89     ############ Branching ######################################## 
    90  
    91  
    92  
    93     security.declareProtected(ADD_CONTENT_PERMISSION,'createBranch') 
    94     def createBranch(self, REQUEST): 
    95         """ Create a branch for object """ 
    96         if self.state=='deleted' or self.state=='private': 
    97             return 
    98         lutool=getToolByName(self, 'lemill_usertool') 
    99         lt=getToolByName(self, 'lemill_tool') 
    100         parent = aq_parent(aq_inner(self)) 
    101         new = parent.lemill_invokeFactory(parent, self.meta_type, id=self.meta_type.lower()+str(id(self)), do_create=True) 
    102         base_obj=self 
    103  
    104         for field in base_obj.schema.values(): 
    105             # list all fields here that shouldn't be copyied to new object 
    106             if not getattr(field, 'copied_in_branching', True) or field.getName()=='id': 
    107                 continue 
    108             old_accessor = field.getEditAccessor(base_obj) 
    109             new_mutator = field.getMutator(new) 
    110             if not old_accessor: 
    111                 continue 
    112             val = old_accessor() 
    113             copied_val = None 
    114             try: 
    115                 copied_val = copy.copy(val) 
    116             except TypeError: 
    117                 copied_val = copy.copy(val.aq_base) 
    118             new_mutator(copied_val) 
    119  
    120         # Setting parent and needed values 
    121         baseuid=base_obj.UID() 
    122         base_obj.addToBranches(new.UID()) 
    123         new.setBranch_of(baseuid) 
    124         author=lutool.getAuthenticatedId() 
    125         new.setCreators([author]+list(base_obj.Creators())) 
    126         new.storeInHistory({}, summary='Copy of %s created' % base_obj.title_or_id()) 
    127         new.setHistory(new.getHistory()+base_obj.getHistory()+new.getHistory()) 
    128         lt.addPortalMessage('You are editing a copy of the original learning resource.') 
    129         return REQUEST.RESPONSE.redirect('%s/base_edit' % new.absolute_url())         
    130  
    131  
    132     security.declareProtected(ModerateContent,'removeBranches') 
    133     def removeBranches(self): 
    134         """ Manage command to remove broken branches """ 
    135         self.setBranches([]) 
    136  
    137     def addToBranches(self, UID): 
    138         """ Makes sure that object UID is in branches """ 
    139         branch_list = self.getRawBranches() 
    140         if UID not in branch_list: 
    141             branch_list.append(UID) 
    142             self.setBranches(branch_list) 
    143  
    144     def removeFromBranches(self, UID): 
    145         """ remove """ 
    146         branch_list = self.getRawBranches() 
    147         if UID in branch_list: 
    148             branch_list.remove(UID) 
    149             self.setBranches(branch_list) 
    150  
    151     def allowOnlyBranch(self): 
    152         """ only checks if this is 'locked' resource, doesn't check if the author is one that is asking """ 
    153         return getattr(self, 'editingMode','')=='other_users_can_edit_a_copy'             
    154  
    155     def allowSettingOfEditingPermissions(self): 
    156         """ Only authors and moderators can hide drafts or prevent editing """ 
    157         # if translation, don't show editing_settings fields 
    158         return (self.amIOwner() or self.canIModerate()) and not self.getRawTranslation_of()  
    159  
    160  
    161  
    162  
    16367registerType(Material, PROJECTNAME) 
  • trunk/MemberFolder.py

    r2994 r2998  
    545545                elif res.meta_type=='Collection': 
    546546                    dict['Collections'].append(res) 
    547                 elif res.meta_type=='Piece' or res.meta_type=='LeMillReference'
     547                elif res.meta_type=='Piece'
    548548                    dict['Pieces'].append(res) 
    549549            return dict                    
  • trunk/MultimediaMaterial.py

    r2791 r2998  
    2525from Schemata import no_description, material_schema, community_editing_schema, draft_schema 
    2626from Material import Material 
     27from Branchable import Branchable 
    2728from permissions import MODIFY_CONTENT 
    2829import re 
     
    5960 
    6061 
    61 class MultimediaMaterial(Material): 
     62class MultimediaMaterial(Branchable, Material): 
    6263    """Web page""" 
    6364 
  • trunk/PILOTMaterial.py

    r2949 r2998  
    2525from Products.CMFPlone import PloneMessageFactory as PMF 
    2626from Material import Material 
     27from Branchable import Branchable 
    2728 
    2829pilotmaterial_schema = Schema(( 
     
    8687 
    8788 
    88 class PILOTMaterial(Material): 
     89class PILOTMaterial(Branchable, Material): 
    8990    """ PILOT Material """ 
    9091 
  • trunk/Resource.py

    r2997 r2998  
    9292        self.recalculateAuthors() 
    9393        self.recalculateScore() 
    94         # if in MATERIAL_TYPES, see if state has to be changed 
    9594        if self.hasComplexWorkflow(): 
    9695            if self.getHideDrafts(): 
     
    823822            f.set(self, reason) 
    824823        self.setState('deleted') 
    825         if self.meta_type in MATERIAL_TYPES: 
    826             self.aliases['(Default)']='base_view' 
     824        self.aliases['(Default)']='base_view' 
    827825        try: 
    828826            self.reindexObject(['getState']) 
     
    834832    def rescue(self, REQUEST): 
    835833        """Undelete a resource """ 
    836         if self.meta_type in MATERIAL_TYPES: 
    837             self.aliases['(Default)']='fullscreen_view' 
     834        self.aliases['(Default)']=self.__class__().aliases['(Default)'] 
    838835        self.undeleteResource() 
    839836        return REQUEST.RESPONSE.redirect(self.absolute_url()) 
  • trunk/SchoolProjectMaterial.py

    r2949 r2998  
    2525from config import PROJECTNAME, MODIFY_CONTENT, VIEW 
    2626from Material import Material 
     27from Branchable import Branchable 
    2728 
    2829schoolprojectmaterial_schema = Schema(( 
     
    101102#schema['bodyText'].widget.visible = {'edit':'invivible', 'view':'invisible'} 
    102103 
    103 class SchoolProjectMaterial(Material): 
     104class SchoolProjectMaterial(Branchable, Material): 
    104105    """ School Project Material """ 
    105106 
  • trunk/config.py

    r2986 r2998  
    104104REMOTE_SERVERS = ["http://lemill.net"]  
    105105 
    106 MATERIAL_TYPES = ('PresentationMaterial', 'MultimediaMaterial', 'PILOTMaterial', 'ExerciseMaterial','LessonPlan', 'SchoolProjectMaterial'
    107 CONTENT_TYPES = ('Piece','LeMillReference','LeMillPrintResource') + MATERIAL_TYPES 
     106MATERIAL_TYPES = ('PresentationMaterial', 'MultimediaMaterial', 'PILOTMaterial', 'ExerciseMaterial','LessonPlan', 'SchoolProjectMaterial', 'LeMillReference'
     107CONTENT_TYPES = ('Piece','LeMillPrintResource') + MATERIAL_TYPES 
    108108ACTIVITY_TYPES = ('Activity',) 
    109109TOOLS_TYPES = ('Tool',) 
     
    282282    {'id':'drafts', 'title':'Draft', 'view':'lemill_published_view', 'sortby':'getLatestEdit', 'reversed':True,'criterions':[('ATCurrentAuthorCriterion','Creator',''),('ATSelectionCriterion','getState',['draft','private'])]},)), 
    283283    # +++++++++++++++++++++++ 
    284     (MATERIAL_TYPES+('LeMillReference','LeMillPrintResource',), (  
     284    (MATERIAL_TYPES+('LeMillPrintResource',), (  
    285285    {'id':'language', 'title':'Language', 'getmethod':'Language', 'view':'lemill_browse_content'}, 
    286286    {'id':'subject_area', 'title':'Subject area', 'getmethod':'getSubject_area', 'view':'lemill_browse_content'}, 
     
    296296    {'id':'browse_pieces', 'title':'Pieces', 'view':'lemill_content_titlecloud'},)), 
    297297    # +++++++++++++++++++++++ 
    298      (MATERIAL_TYPES+ACTIVITY_TYPES+TOOLS_TYPES+COMMUNITY_TYPES+('LeMillReference','LeMillPrintResource',), ( 
     298     (MATERIAL_TYPES+ACTIVITY_TYPES+TOOLS_TYPES+COMMUNITY_TYPES+('LeMillPrintResource',), ( 
    299299    {'id':'recent', 'title':"What's going on", 'getmethod':'getLatestEdit', 'sortby':'getLatestEdit', 'reversed':True, 'view':'lemill_recent_view'},)) 
    300300    # +++++++++++++++++++++++ 
  • trunk/skins/lemill/cached_script_featured_content.py

    r2949 r2998  
    1010SCORE_THRESHOLD=5 
    1111 
    12 featured_types=list(context.getMaterialTypes())+['LeMillReference'] 
     12featured_types=context.getMaterialTypes() 
    1313top3_categories={'top3languages':'Language', 'top3tags':'getTags', 'top3subject_areas':'getSubject_area', 'top3target_groups':'getTarget_group'} 
    1414