Changeset 1321


Ignore:
Timestamp:
01/31/07 22:25:01 (13 years ago)
Author:
jukka
Message:

Fixed #1121. When uploading pieces in mmediapage and like, checks if content type is in whitelist. Also fixes error when uploading just piece and leaving file empty.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/FieldsWidgets.py

    r1289 r1321  
    2323from Products.Archetypes.Widget import TextAreaWidget, StringWidget, SelectionWidget, TypesWidget, MultiSelectionWidget, VisualWidget, FileWidget 
    2424from Products.Archetypes.ReferenceEngine import Reference 
    25 from config import to_unicode 
     25from config import to_unicode, MIMETYPE_WHITELIST 
    2626from Products.Archetypes import config 
    2727from string import letters, punctuation 
     
    757757            if chapter and hasattr(chapter, 'filename'): 
    758758                # This is a file, so create a piece from it, get its uid and give that to be the content of this chapter 
    759                 id = instance.generateUniqueId('Piece') 
    760                 portal_url = getToolByName(instance, 'portal_url') 
    761                 filename=chapter.filename.split('/')[-1] # Windows brings in the whole path as filename, take only last part 
    762  
    763                 new_id = portal_url.getPortalObject().content.invokeFactory('Piece', id, title='-'.join((instance.Title(),filename))) 
    764                 new_piece = getattr(instance.content, new_id) 
    765                 new_piece.edit(file=chapter) 
    766                  
    767                 # file is uploaded and piece is made, but is it a piece of correct type?                
    768                 if new_piece.isImage() and (allowed_types_sequence[sequence_index]=='image' or ignore_type): 
    769                     new_piece.edit(image=chapter) 
    770                     chapter = new_piece.UID() 
    771                     fine_piece = True               
    772                 elif new_piece.isAudio() and (allowed_types_sequence[sequence_index]=='audio' or ignore_type): 
    773                     chapter = new_piece.UID() 
    774                     fine_piece = True                 
    775                 else: 
    776                     fine_piece = False 
    777                     if allowed_types_sequence[sequence_index]=='image': 
     759                if chapter.headers['Content-Type'] not in MIMETYPE_WHITELIST: 
     760                    fine_piece=False 
     761                    if allowed_types_sequence[sequence_index]=='image' or ignore_type: 
    778762                        chapter = 'thisisamediapiecethisisamediapie' 
    779763                    elif allowed_types_sequence[sequence_index]=='audio': 
     
    781765                    else: 
    782766                        chapter = None  
     767 
     768                else:                 
     769                    id = instance.generateUniqueId('Piece') 
     770                    portal_url = getToolByName(instance, 'portal_url') 
     771                    filename=chapter.filename.split('/')[-1] # Windows brings in the whole path as filename, take only last part 
     772     
     773                    new_id = portal_url.getPortalObject().content.invokeFactory('Piece', id, title='-'.join((instance.Title(),filename))) 
     774                    new_piece = getattr(instance.content, new_id) 
     775                    new_piece.edit(file=chapter)                         
     776                     
     777                    # file is uploaded and piece is made, but is it a piece of correct type?                
     778                    if new_piece.isImage() and (allowed_types_sequence[sequence_index]=='image' or ignore_type): 
     779                        new_piece.edit(image=chapter) 
     780                        chapter = new_piece.UID() 
     781                        fine_piece = True               
     782                    elif new_piece.isAudio() and (allowed_types_sequence[sequence_index]=='audio' or ignore_type): 
     783                        chapter = new_piece.UID() 
     784                        fine_piece = True 
     785                    else: 
     786                        fine_piece = False                 
    783787 
    784788                # store UID in session so that we can edit these new pieces  
  • trunk/LargeSectionFolder.py

    r1318 r1321  
    754754        """ 
    755755        file = REQUEST.get('file') 
    756         if file==None: 
     756        if file==None or not getattr(file, 'headers',{}).has_key('Content-Type'): 
    757757            return REQUEST.RESPONSE.redirect('lemill_explain_upload_fail')         
    758758        user_description = REQUEST.get('user_description') 
     
    876876 
    877877    schema=communityschema 
     878 
     879    ### If MemberFolder for logged in user does not exist, it is created here 
    878880     
    879881    def my_page(self): 
     
    883885        if not member: return 
    884886        if member.getHomeFolder()==None: 
    885             member.createMemberarea() 
    886         folder=member.getHomeFolder()     
     887            member.createMemberarea()             
     888        folder=member.getHomeFolder() 
     889        if not hasattr(folder.aq_base,'collections'): 
     890            folder.invokeFactory('CollectionsFolder', id='collections') 
     891        if not hasattr(folder.aq_base,'stories'): 
     892            folder.invokeFactory('StoryFolder', id='stories')                 
    887893        return folder.absolute_url()    
    888894 
  • trunk/PresentationMaterial.py

    r1298 r1321  
    2525from Piece import Piece 
    2626 
    27 from config import PROJECTNAME, MODIFY_CONTENT, VIEW 
     27from config import PROJECTNAME, MODIFY_CONTENT, VIEW, MIMETYPE_WHITELIST 
    2828from FieldsWidgets import * 
    2929from SharedMetadata import * 
     
    198198            if file and hasattr(file, 'filename'):     
    199199                # This is a file, so create a piece from it, get its uid and give that to be the content of this chapter 
    200                 id = self.generateUniqueId('Piece') 
    201                 new_id = portal_url.getPortalObject().content.invokeFactory('Piece', id) 
    202                 #new_piece= Piece(id) 
    203                 #new_id = portal_url.getPortalObject().content._setObject(id, new_piece) 
    204                 new_piece = getattr(self.content, new_id) 
    205                 new_piece.setFile(file) 
    206                 filename=file.filename.split('/')[-1] # Windows brings in the whole path as filename, take only last part 
    207                 new_piece.setTitle('-'.join((self.Title(),filename)))                
    208                 # file is uploaded and piece is made, but is it a piece of correct type?                
    209                 if new_piece.isImage(): 
    210                     #new_piece.setImage(file) #not needed, setFile does this 
    211                     uid = new_piece.UID() 
    212                     fine_piece = True               
    213                 else: 
    214                     fine_piece = False 
     200                if file.headers['Content-Type'] not in MIMETYPE_WHITELIST: 
     201                    fine_piece=False 
    215202                    uid = 'thisisamediapiecethisisamediapie' 
    216                     self.content.manage_delObjects([id]) 
     203                else:                 
     204                    id = self.generateUniqueId('Piece') 
     205                    new_id = portal_url.getPortalObject().content.invokeFactory('Piece', id) 
     206                    #new_piece= Piece(id) 
     207                    #new_id = portal_url.getPortalObject().content._setObject(id, new_piece) 
     208                    new_piece = getattr(self.content, new_id) 
     209                    new_piece.setFile(file) 
     210                    filename=file.filename.split('/')[-1] # Windows brings in the whole path as filename, take only last part 
     211                    new_piece.setTitle('-'.join((self.Title(),filename)))                
     212                    # file is uploaded and piece is made, but is it a piece of correct type?                
     213                    if new_piece.isImage(): 
     214                        #new_piece.setImage(file) #not needed, setFile does this 
     215                        uid = new_piece.UID() 
     216                        fine_piece = True               
     217                    else: 
     218                        fine_piece = False 
     219                        uid = 'thisisamediapiecethisisamediapie' 
     220                        self.content.manage_delObjects([id]) 
    217221                if fine_piece: 
    218222                    # store UID in session so that we can edit these new pieces  
Note: See TracChangeset for help on using the changeset viewer.