当前位置: 首页>>代码示例>>Python>>正文


Python Image.cookId函数代码示例

本文整理汇总了Python中OFS.Image.cookId函数的典型用法代码示例。如果您正苦于以下问题:Python cookId函数的具体用法?Python cookId怎么用?Python cookId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cookId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createShpToGmlFiles

def createShpToGmlFiles(shp_file, shx_file, dbf_file):
    from OFS.Image import cookId
    shp_filename, title = cookId('', '', shp_file)
    shx_filename, title = cookId('', '', shx_file)
    dbf_filename, title = cookId('', '', dbf_file)

    #temporary create files
#    fld_path = join(FILES_PATH, shp_filename[:-4])
#    if not os.path.isdir(fld_path):
#        os.mkdir(fld_path)

    shp_path = join(FILES_PATH, shp_filename)
    shp_data = shp_file.read()
    temp_shp_file = open(shp_path, 'wb')
    temp_shp_file.write(shp_data)
    temp_shp_file.close()
    
    shx_path = join(FILES_PATH, shx_filename)
    shx_data = shx_file.read()
    temp_shx_file = open(shx_path, 'wb')
    temp_shx_file.write(shx_data)
    temp_shx_file.close()
    
    dbf_path = join(FILES_PATH, dbf_filename)
    dbf_data = dbf_file.read()
    temp_dbf_file = open(dbf_path, 'wb')
    temp_dbf_file.write(dbf_data)
    temp_dbf_file.close()
    
    return shp_filename[:-4]
开发者ID:anton16,项目名称:reportek-converters,代码行数:30,代码来源:gml_converter.py

示例2: manage_addPhoto

def manage_addPhoto(dispatcher, id, title, file,
                    content_type='', precondition='',
                    store='Image', engine='ImageMagick', quality=75,
                    timeout=0, pregen=0, REQUEST=None):
    """Add Photo object."""
    id = cookId(id, title, file)[0]
    dest = dispatcher.Destination()
    photo = Photo(id, title, '', content_type, precondition,
                  store, engine, quality, pregen, timeout)
    photo._data = file.read()
    dest._setObject(id, photo)
    # Images are generated at this point by manage_afterAdd()
    
    self = dest._getOb(id)
    # Init properties and displays from Photo Folder if present
    parent = self.aq_parent
    if parent.meta_type == 'Photo Folder':
        props = parent.propertysheets.get('photos')
        for propid, value in props.propertyItems():
            try: self.manage_addProperty(propid, value, props.getPropertyType(propid))
            except: pass
        self._displays = parent._displays.copy()

    if REQUEST is not None:
        try:    url=dispatcher.DestinationURL()
        except: url=REQUEST['URL1']
        REQUEST.RESPONSE.redirect('%s/manage_main' % url)
    return id
开发者ID:peterbe,项目名称:zope_products,代码行数:28,代码来源:Photo.py

示例3: manage_addODFFile

def manage_addODFFile(
    self, id="", file="", title="", precondition="", content_type="", conversion="embedded", REQUEST=None
):
    """Add a new File object.

    Creates a new File object 'id' with the contents of 'file'"""

    id = str(id)
    title = str(title)
    conversion = str(conversion)
    content_type = str(content_type)
    precondition = str(precondition)

    suffix = ""
    newid, title = cookId(id, title, file)
    if id == "" and newid[-4:-2] == ".o" and newid[-2] in ["d", "t"]:
        id = newid[:-4]
        suffix = id[-3:]
    else:
        id = newid
    self = self.this()

    # First, we create the file without data:
    self._setObject(id, ODFFile(id, title, "", suffix, content_type, precondition, conversion))

    # Now we "upload" the data.  By doing this in two steps, we
    # can use a database trick to make the upload more efficient.
    if file:
        self._getOb(id).manage_upload(file)
    if content_type:
        self._getOb(id).content_type = content_type

    if REQUEST is not None:
        REQUEST["RESPONSE"].redirect(self.absolute_url() + "/manage_main")
开发者ID:bufke,项目名称:odfpy,代码行数:34,代码来源:ODFFile.py

示例4: uploadImage

    def uploadImage(self, file, REQUEST=None):
        """
        Upload image to the collection and then return to the referring URL.
        """

        sha1_hash = sha_hexdigest(file)
        for image in self.storage.objectValues('Image'):
            if not hasattr(image, 'sha1_hash'):
                image.sha1_hash = sha_hexdigest(image)
            if sha1_hash == image.sha1_hash:
                return image

        id, title = cookId(None, None, file)
        # first, determine if this is a utf-8 text and not ascii
        try:
            id.decode('ascii')
        except UnicodeError:
            id = id.decode('utf-8')

        orig_id = id
        id = make_id(self.storage, title=title)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob
开发者ID:eaudeweb,项目名称:Products.Naaya,代码行数:26,代码来源:NyImageContainer.py

示例5: addNyPhoto

def addNyPhoto(self, id='', REQUEST=None, _klass=None, **kwargs):
    """
    Create a Photo type of object.
    """
    if self.is_full():
        return None

    if REQUEST is not None:
        schema_raw_data = dict(REQUEST.form)
    else:
        schema_raw_data = kwargs

    if _klass is None:
        _klass = NyPhoto
    _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None))
    if schema_raw_data.get('sortorder', '') == '':
        schema_raw_data['sortorder'] = DEFAULT_SORTORDER
    _releasedate = self.process_releasedate(schema_raw_data.pop('releasedate', ''))
    _content_type = schema_raw_data.pop('content_type', '')
    schema_raw_data.setdefault('discussion', getattr(self, 'discussion', 0)) # Fallback from album
    _title = schema_raw_data.pop('title','')

    _file = schema_raw_data.pop('file', '')
    if _file != '' and getattr(_file, 'filename', None) == '':
        _file = ''

    #process parameters
    id, _title = cookId(id, _title, _file)
    id = make_id(self, id=id, title=_title, prefix=PREFIX_NYPHOTO)
    schema_raw_data['title'] = _title

    ob = _klass(id, content_type=_content_type, displays=self.displays.copy())
    self.gl_add_languages(ob)
    self._setObject(id, ob)
    ob = self._getOb(id)

    form_errors = ob.process_submitted_form(schema_raw_data, _lang, _override_releasedate=_releasedate)
    if form_errors:
        raise ValueError(form_errors.popitem()[1]) # pick a random error

    if self.glCheckPermissionPublishObjects():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 1, None
    ob.approveThis(approved, approved_by)

    #extra settings
    ob.update_data(_file)
    ob.submitThis()
    if ob.discussion:
        ob.open_for_comments()
    else:
        ob.close_for_comments()
    self.recatalogNyObject(ob)

    #redirect if case
    if REQUEST is not None:
        REQUEST.RESPONSE.redirect(self.absolute_url())

    return ob.getId()
开发者ID:eaudeweb,项目名称:naaya,代码行数:60,代码来源:NyPhoto.py

示例6: manage_addCNXMLFile

def manage_addCNXMLFile(self,id,file='',title='',precondition='', content_type='text/xml', REQUEST=None):
    """Add a new CNXML File object.
    Creates a new CNXML File object 'id' with the contents of 'file'
    """

    id=str(id)
    title=str(title)
    content_type=str(content_type)
    precondition=str(precondition)

    (id, title) = cookId(id, title, file)

    self=self.this()

    # First, we create the file without data:
    self._setObject(id, CNXMLFile(id,title,'',content_type, precondition))

    # Now we "upload" the data.  By doing this in two steps, we
    # can use a database trick to make the upload more efficient.
    self._getOb(id).manage_upload(file)
    if content_type:
        self._getOb(id).content_type=content_type

    if REQUEST is not None:
        REQUEST['RESPONSE'].redirect(self.absolute_url()+'/manage_main')
开发者ID:maxfierke,项目名称:Products.CNXMLDocument,代码行数:25,代码来源:CNXMLFile.py

示例7: addDocFile

def addDocFile(self, id='', title='', description='', releasedate='',approved='', sortorder='', language='', keywords='', coverage='', author='', source='', f_source='', file='', precondition='', content_type='', downloadfilename='', file_version='', status='', REQUEST=None, **kwargs):
    """ add a new DocFile object """
    id, title = cookId(id, title, file)
    #id = self.utCleanupId(id)
    if downloadfilename == '': downloadfilename = self.utCleanupId(id)
    id = 'file' + self.utGenRandomId(6)
    #if id == '': id = 'file' + self.utGenRandomId(6)    
    try: sortorder = abs(int(sortorder))
    except: sortorder = 100
    #if self.checkPermissionPublishObjects(): approved = 1
    approved = 1
    #else: approved = 0
    if not releasedate: releasedate = self.utGetTodayDate()
    else: releasedate = self.utConvertStringToDateTimeObj(releasedate)
    creationdate = self.utGetTodayDate()
    ownerinfo = self.getAuthenticatedUser()
    if file_version=='': file_version = '1.0'
    #create  object
    ob = DocFile( id, title, description, creationdate, releasedate, ownerinfo, approved, sortorder, language, keywords, coverage, author, source, f_source, precondition, content_type, downloadfilename, file_version, status)
    self._setObject(id, ob)
    ob = self._getOb(id)
    #history
    ob.createHistory(HISTORY_ADD)
    #upload data
    if file: ob.uploadFile(file)
    ob.CatalogDMObject(ob)
    if content_type: ob.content_type = content_type
    #create new version if case
    ob.createVersion()
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'manage_addDocFile_html' or l_referer.find('manage_addDocFile_html') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'file_add_html':
            REQUEST.RESPONSE.redirect(self.absolute_url(0))
开发者ID:eaudeweb,项目名称:naaya,代码行数:35,代码来源:DocFile.py

示例8: testMultiplyVerificationFiles

    def testMultiplyVerificationFiles(self):
        verifyConfigUrl = '/'+self.portal.absolute_url(1) + '/prefs_gsm_verification'
        fnames = []
        for i in [1,2]:
            fp, fname, response = None, None, None
            try:
                fupload, fp = prepareUploadFile(prefix=str(i))
                fname, ftitle = cookId('', '', fupload)
                form = {'form.button.CreateFile': 'Create verification file',
                        'form.submitted': 1}
                extra_update = {'verification_file': fupload}
                response = self.publish(verifyConfigUrl, request_method='POST',
                                        stdin=StringIO(urlencode(form)),
                                        basic=self.auth, extra=extra_update)
            finally:
                if fp: fp.close()
            
            self.assertEqual(response.getStatus(), 200)
            self.assert_(fname in self.gsm_props.getProperty('verification_filenames',[]),
                             self.gsm_props.getProperty('verification_filenames',[]))
            fnames.append(fname)

        self.assertEqual(len([1 for vf in fnames \
            if vf in self.gsm_props.getProperty('verification_filenames',[])]), 2,
            self.gsm_props.getProperty('verification_filenames',[]))
开发者ID:kroman0,项目名称:products,代码行数:25,代码来源:testqPloneGoogleSitemaps.py

示例9: manage_addGuardedFile

def manage_addGuardedFile(self, id, file, title='', precondition='', content_type='', REQUEST=None):
    """
    Add a new GuardedFile object.

    Creates a new GuardedFile object 'id' with the content of 'file'.
    """
    # Object creation stuff, cribbed from OFS.Image.manage_addFile().
    id, title = cookId(id, title, file)
    self = self.this()
    self._setObject(id, GuardedFile(id, title, '', content_type, precondition))
    obj = self._getOb(id)
    obj.manage_upload(file)

    # Unset permission acquisition.
    obj.manage_acquiredPermissions()

    # Create a proxy role and set a specific permission for it.
    proxy_role = "proxy_for_%s" % id
    self._addRole(proxy_role)
    obj.manage_role(proxy_role, ['View'])
    uname = getSecurityManager().getUser().getUserName()
    self.manage_addLocalRoles(uname, (proxy_role,), REQUEST)

    # Feedback.
    if REQUEST: return MessageDialog(
        title  ='Success!',
        message='GuardedFile "%s" has been created.' % id,
        action ='manage_main')
开发者ID:0xkag,项目名称:M2Crypto,代码行数:28,代码来源:GuardedFile.py

示例10: testVerificationForm

    def testVerificationForm(self):
        verifyConfigUrl = '/'+self.portal.absolute_url(1) + '/prefs_gsm_verification'
        verif_config = self.publish(verifyConfigUrl, self.auth).getBody()
        rexp_input_acitve = re.compile('<input\s+name="verification_file"\s+([^>]*)>', re.I|re.S)
        rexp_button_acitve = re.compile('<input\s+name="form.button.CreateFile"\s+([^>]*)>', re.I|re.S)
        rexp_delete_button = re.compile('<input\s+name="form.button.DeleteFile"\s+[^>]*>', re.I|re.S)

        input_acitve = rexp_input_acitve.search(verif_config)
        button_acitve = rexp_button_acitve.search(verif_config)
        delete_button = rexp_delete_button.match(verif_config)

        self.assert_(input_acitve and not 'disabled' in input_acitve.groups(1))
        self.assert_(button_acitve and not 'disabled' in button_acitve.groups(1))
        self.assert_(not delete_button)

        fp, fname = None, None
        try:
            fupload, fp = prepareUploadFile()
            fname, ftitle = cookId('', '', fupload)
            self.portal.REQUEST.form['verification_file'] = fupload
            self.portal.gsm_create_verify_file()
        finally:
            if fp: fp.close()

        input_acitve = rexp_input_acitve.search(verif_config)
        button_acitve = rexp_button_acitve.search(verif_config)
        delete_button = rexp_delete_button.match(verif_config)

        verif_config = self.publish(verifyConfigUrl, self.auth).getBody()
        self.assert_(input_acitve and not 'disabled' in input_acitve.groups(1))
        self.assert_(not delete_button)
开发者ID:kroman0,项目名称:products,代码行数:31,代码来源:testqPloneGoogleSitemaps.py

示例11: addAttachmentForComment

 def addAttachmentForComment(self, attachment, commentId):
     """Add an attachment to comment"""
     if attachment.filename != '':
         #upload file
         attachmentId, attachmentTitle = cookId(None, None, attachment)
         attachmentId = str(commentId) + '_' + attachmentId
         attachmentTitle = ATTACHMENT_FOR_COMMENT_LABEL + str(commentId)
         self.manage_addFile(attachmentId, attachment, attachmentTitle)
开发者ID:eaudeweb,项目名称:naaya,代码行数:8,代码来源:Issue.py

示例12: addAttachmentForIssue

 def addAttachmentForIssue(self, attachment):
     """Add an attachment to comment"""
     if attachment != '':
         if attachment.filename != '':
             #upload file
             attachmentId, attachmentTitle = cookId(None, None, attachment)
             attachmentId = str(self.id) + '_' + attachmentId
             attachmentTitle = ATTACHMENT_FOR_ISSUE_LABEL
             self.manage_addFile(attachmentId, attachment, attachmentTitle)
开发者ID:eaudeweb,项目名称:naaya,代码行数:9,代码来源:Issue.py

示例13: addSurveyAttachment

def addSurveyAttachment(container, id='', title='', description='', coverage='', keywords='', sortorder='',
    source='file', file='', url='', precondition='', content_type='', downloadfilename='',
    contributor=None, releasedate='', discussion='', lang=None, REQUEST=None, **kwargs):
    """ """
    if source=='file': id = cookId(id, title, file)[0] #upload from a file
    id = container.utCleanupId(id)
    if id == '': id = 'attachment_' + container.utGenRandomId(6)
    if downloadfilename == '': downloadfilename = id
    try: sortorder = abs(int(sortorder))
    except: sortorder = DEFAULT_SORTORDER

    #check mandatory fiels
    l_referer = ''
    if REQUEST is not None: l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]

    #process parameters
    if contributor is None: contributor = container.REQUEST.AUTHENTICATED_USER.getUserName()
    if container.glCheckPermissionPublishObjects():
        approved, approved_by = 1, container.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 0, None
    releasedate = container.process_releasedate(releasedate)
    if lang is None: lang = container.gl_get_selected_language()
    #check if the id is invalid (it is already in use)
    i = 0
    while container._getOb(id, None):
        i += 1
        id = '%s-%u' % (id, i)
    #create object
    ob = SurveyAttachment(id, contributor)
    container._setObject(ob.getId(), ob)
    ob = container._getOb(id)
    ob.saveProperties(title=title, description=description, coverage=coverage, keywords=keywords,
                      sortorder=sortorder, precondition=precondition, content_type=content_type,
                      downloadfilename=downloadfilename, releasedate=releasedate, lang=lang)
    container.gl_add_languages(ob)
    #ob.createDynamicProperties(container.processDynamicProperties(METATYPE_OBJECT, REQUEST, kwargs), lang) # ???
    #extra settings
    ob.updatePropertiesFromGlossary(lang)
    ob.submitThis()
    ob.approveThis(approved, approved_by)
    ob.handleUpload(source, file, url, lang)
    ob.createversion(container.REQUEST.AUTHENTICATED_USER.getUserName(), lang)
    if discussion: ob.open_for_comments()
    container.recatalogNyObject(ob)
    container.notifyFolderMaintainer(container, ob)
    #log post date
    auth_tool = container.getAuthenticationTool()
    auth_tool.changeLastPost(contributor)
    #redirect if case
    if REQUEST is not None:
        if l_referer == 'exfile_manage_add' or l_referer.find('exfile_manage_add') != -1:
            return container.manage_main(container, REQUEST, update_menu=1)
        elif l_referer == 'attachment_add':
            container.setSession('referer', container.absolute_url())
            REQUEST.RESPONSE.redirect('%s/messages_html' % container.absolute_url())
开发者ID:eaudeweb,项目名称:Products.NaayaSurvey,代码行数:56,代码来源:SurveyAttachment.py

示例14: uploadImage

 def uploadImage(self, file, REQUEST=None):
     """Upload image to the collection and then return to the referring URL."""
     id, title = cookId(None, None, file)
     i = 0
     storage = self._get_storage()
     while storage._getOb(id, None):
         i += 1
         id = '%s-%u' % (id, i)
     manage_addImage(storage, id, file, title)
     self._redirectBack(REQUEST)
开发者ID:eaudeweb,项目名称:naaya,代码行数:10,代码来源:NyImageContainer.py

示例15: handleUpload

 def handleUpload(self, file):
     """
     Upload a file from disk.
     """
     filename = getattr(file, 'filename', '')
     if not filename:
         return
     self.manage_delObjects(self.objectIds())
     file_id = cookId('', '', file)[0]   #cleanup id
     self.manage_addFile(id=file_id, file=file)
开发者ID:eaudeweb,项目名称:naaya.semide,代码行数:10,代码来源:semevent_item.py


注:本文中的OFS.Image.cookId函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。