Exemplo n.º 1
0
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]
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
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')
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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',[]))
Exemplo n.º 7
0
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')
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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")
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
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')
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
 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)
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())
Exemplo n.º 17
0
 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)
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 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)
Exemplo n.º 20
0
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)
    #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())
Exemplo n.º 21
0
 def uploadVerificationFile(self, request):
     vfilename = ""
     portal = self.pps.portal()
     try:
         vfile = request.get("verification_file")
         vfilename, vftitle = cookId("", "", vfile)
         portal.manage_addFile(id="", file=vfile)
         portal[vfilename].manage_addProperty(
             'CreatedBy', 'quintagroupt.plonegooglesitemaps','string')
     except BadRequestException, e:
         return False, str(e)
Exemplo n.º 22
0
 def testVerificationFileCreation(self):
     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()
     vf_created = hasattr(self.portal, fname)
     self.assert_(vf_created, 'Verification file not created')
Exemplo n.º 23
0
 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
     while self.storage._getOb(id, None):
         i += 1
         id = '%s-%u' % (id, i)
     id = manage_addImage(self.storage, id, file, title)
     if REQUEST:
         return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
     ob = self.storage._getOb(id)
     return ob
Exemplo n.º 24
0
 def handleUpload(self, file):
     """
     Upload a file from disk.
     """
     if file != '':
         if hasattr(file, 'filename'):
             if file.filename != '':
                 data, size = self._read_data(file)
                 content_type = self._get_content_type(file, data, self.__name__, 'application/octet-stream')
                 self.update_data(data, content_type, size)
         else:
             self.update_data(file)
     self._p_changed = 1
     return cookId('', '', file)[0]
Exemplo n.º 25
0
def addNyPhoto(self, id='', title='', author='', source='', description='', sortorder='',
    topitem='', onfrontfrom='', onfrontto='', file='', precondition='', content_type='',
    quality='', lang=None, discussion='', releasedate='', REQUEST=None):
    """
    Create a Photo type of object.
    """
    #process parameters
    id, title = cookId(id, title, file)
    id = self.utCleanupId(id)
    if not id: id = PREFIX_NYPHOTO + self.utGenRandomId(6)
    try: sortorder = abs(int(sortorder))
    except: sortorder = DEFAULT_SORTORDER
    if topitem: topitem = 1
    else: topitem = 0
    onfrontfrom = self.utConvertStringToDateTimeObj(onfrontfrom)
    onfrontto = self.utConvertStringToDateTimeObj(onfrontto)
    try: quality = abs(int(quality))
    except: quality = DEFAULT_QUALITY
    if quality <= 0 or quality > 100: quality = DEFAULT_QUALITY
    displays = self.displays.copy()
    if file != '':
        if hasattr(file, 'filename'):
            if file.filename == '': file = ''
    if self.glCheckPermissionPublishObjects():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 0, None
    releasedate = self.process_releasedate(releasedate)
    if lang is None: lang = self.gl_get_selected_language()
    #create object
    ob = NyPhoto(id, title, author, source, description, sortorder, topitem,
        onfrontfrom, onfrontto, precondition, content_type, quality,
        displays, approved, approved_by, releasedate, lang)
    self.gl_add_languages(ob)
    self._setObject(id, ob)
    #extra settings
    ob = self._getOb(id)
    ob.manage_upload(file)
    ob.submitThis()
    if discussion: ob.open_for_comments()
    self.recatalogNyObject(ob)
    #redirect if case
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'manage_addNyPhoto_html' or l_referer.find('manage_addNyPhoto_html') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'photo_add_html':
            self.setSession('referer', '%s/admin_html' % self.absolute_url())
            REQUEST.RESPONSE.redirect('%s/messages_html' % self.getSitePath())
Exemplo n.º 26
0
def addNyPhoto(self, id='', title='', author='', source='', description='', sortorder='',
    topitem='', onfrontfrom='', onfrontto='', file='', precondition='', content_type='',
    quality='', lang=None, discussion='', releasedate='', REQUEST=None):
    """
    Create a Photo type of object.
    """
    #process parameters
    id, title = cookId(id, title, file)
    id = self.utCleanupId(id)
    if not id: id = PREFIX_NYPHOTO + self.utGenRandomId(6)
    try: sortorder = abs(int(sortorder))
    except: sortorder = DEFAULT_SORTORDER
    if topitem: topitem = 1
    else: topitem = 0
    onfrontfrom = self.utConvertStringToDateTimeObj(onfrontfrom)
    onfrontto = self.utConvertStringToDateTimeObj(onfrontto)
    try: quality = abs(int(quality))
    except: quality = DEFAULT_QUALITY
    if quality <= 0 or quality > 100: quality = DEFAULT_QUALITY
    displays = self.displays.copy()
    if file != '':
        if hasattr(file, 'filename'):
            if file.filename == '': file = ''
    if self.glCheckPermissionPublishObjects():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 0, None
    releasedate = self.process_releasedate(releasedate)
    if lang is None: lang = self.gl_get_selected_language()
    #create object
    ob = NyPhoto(id, title, author, source, description, sortorder, topitem,
        onfrontfrom, onfrontto, precondition, content_type, quality,
        displays, approved, approved_by, releasedate, lang)
    self.gl_add_languages(ob)
    self._setObject(id, ob)
    #extra settings
    ob = self._getOb(id)
    ob.manage_upload(file)
    ob.submitThis()
    if discussion: ob.open_for_comments()
    self.recatalogNyObject(ob)
    #redirect if case
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'manage_addNyPhoto_html' or l_referer.find('manage_addNyPhoto_html') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'photo_add_html':
            self.setSession('referer', '%s/admin_html' % self.absolute_url())
            REQUEST.RESPONSE.redirect('%s/messages_html' % self.getSitePath())
Exemplo n.º 27
0
 def handleUpload(self, file):
     """
     Upload a file from disk.
     """
     if file != '':
         if hasattr(file, 'filename'):
             if file.filename != '':
                 data, size = self._read_data(file)
                 content_type = self._get_content_type(
                     file, data, self.__name__, 'application/octet-stream')
                 self.update_data(data, content_type, size)
         else:
             self.update_data(file)
     self._p_changed = 1
     return cookId('', '', file)[0]
Exemplo n.º 28
0
def addCNXMLFile(self, id, title='', file='', idprefix=None, **kw):
    """ Add a CNXML File object to the portal """

    id, title = cookId(id, title, file)
    self = self.this()

    self._setObject(id, PortalCNXMLFile(id, title, '', **kw))

    # 'Upload' the file.  This is done now rather than in the
    # constructor because the object is now in the ZODB and
    # can span ZODB objects.
    obj = self._getOb(id)
    obj.manage_upload(file, idprefix=idprefix)

    # Force content type to text/xml since form uploading gets it wrong
    obj.content_type="text/xml"
Exemplo n.º 29
0
 def _get_upload_file(self, source, file, url, parent):
     if source=='file':
         if file != '':
             if hasattr(file, 'filename'):
                 filename = cookId('', '', file)[0]
                 if filename != '':
                     data, size = self._read_data(file)
                     content_type = self._get_content_type(file, data, self.__name__, 'application/octet-stream')
                     return data, content_type, size, filename
             else:
                 return file, '', None, ''
     elif source=='url':
         if url != '':
             l_data, l_ctype = parent.grabFromUrl(url)
             if l_data is not None:
                 return l_data, l_ctype, None, ''
     return '', '', None, ''
Exemplo n.º 30
0
 def _get_upload_file(self, source, file, url, parent):
     if source=='file':
         if file != '':
             if hasattr(file, 'filename'):
                 filename = cookId('', '', file)[0]
                 if filename != '':
                     data, size = self._read_data(file)
                     content_type = mimetypes.guess_type(file.filename)[0]
                     if content_type is None:
                         content_type = self._get_content_type(file, data, self.__name__, 'application/octet-stream')
                     return data, content_type, size, filename
             else:
                 return file, '', None, ''
     elif source=='url':
         if url != '':
             l_data, l_ctype = parent.grabFromUrl(url)
             if l_data is not None:
                 return l_data, l_ctype, None, ''
     return '', '', None, ''
Exemplo n.º 31
0
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')
Exemplo n.º 32
0
 def handleUpload(self, source, file, url, parent):
     """
     Upload a file from disk or from a given URL.
     """
     if source=='file':
         if file != '':
             if hasattr(file, 'filename'):
                 filename = cookId('', '', file)[0]
                 if filename != '':
                     data, size = self._read_data(file)
                     content_type = self._get_content_type(file, data, self.__name__, 'application/octet-stream')
                     self.update_data(data, content_type, size, filename)
             else:
                 self.update_data(file)
     elif source=='url':
         if url != '':
             l_data, l_ctype = parent.grabFromUrl(url)
             if l_data is not None:
                 self.update_data(l_data, l_ctype)
                 self.content_type = l_ctype
     self._p_changed = 1
Exemplo n.º 33
0
 def handleUpload(self, source, file, url, parent):
     """
     Upload a file from disk or from a given URL.
     """
     if source=='file':
         if file != '':
             if hasattr(file, 'filename'):
                 filename = cookId('', '', file)[0]
                 if filename != '':
                     data, size = self._read_data(file)
                     content_type = self._get_content_type(file, data, self.__name__, 'application/octet-stream')
                     self.update_data(data, content_type, size, filename)
             else:
                 self.update_data(file)
     elif source=='url':
         if url != '':
             l_data, l_ctype = parent.grabFromUrl(url)
             if l_data is not None:
                 self.update_data(l_data, l_ctype)
                 self.content_type = l_ctype
     self._p_changed = 1
Exemplo n.º 34
0
 def _get_upload_file(self, source, file, url):
     """ grab file from disk or from a given url.
     Returns data, content_type, size, filename
     """
     if source=='file':
         if file != '':
             if hasattr(file, 'filename'):
                 filename = cookId('', '', file)[0]
                 if filename != '':
                     data, size = self._read_data(file)
                     content_type = mimetypes.guess_type(file.filename)[0]
                     if content_type is None:
                         content_type = self._get_content_type(file, data, self.__name__, 'application/octet-stream')
                     return data, content_type, size, filename
             else:
                 return file, '', None, ''
     elif source=='url':
         if url != '':
             l_data, l_ctype = self.grabFromUrl(url)
             if l_data is not None:
                 return l_data, l_ctype, None, ''
     return '', '', None, ''
Exemplo n.º 35
0
    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)
        orig_id = id
        i = 0
        while self.storage._getOb(id, None):
            i += 1
            id = '%s-%u' % (orig_id, i)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob
Exemplo n.º 36
0
 def _get_upload_file(self, source, file, url):
     """ grab file from disk or from a given url.
     Returns data, content_type, size, filename
     """
     if source == 'file':
         if file != '':
             if hasattr(file, 'filename'):
                 filename = cookId('', '', file)[0]
                 if filename != '':
                     data, size = self._read_data(file)
                     content_type = self._get_content_type(
                         file, data, self.__name__,
                         'application/octet-stream')
                     return data, content_type, size, filename
             else:
                 return file, '', None, ''
     elif source == 'url':
         if url != '':
             l_data, l_ctype = self.grabFromUrl(url)
             if l_data is not None:
                 return l_data, l_ctype, None, ''
     return '', '', None, ''
Exemplo n.º 37
0
    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)
        orig_id = id
        i = 0
        while self.storage._getOb(id, None):
            i += 1
            id = '%s-%u' % (orig_id, i)
        id = manage_addImage(self.storage, id, file, title)
        if REQUEST:
            return REQUEST.RESPONSE.redirect(REQUEST['HTTP_REFERER'])
        ob = self.storage._getOb(id)
        return ob
Exemplo n.º 38
0
def addNyExFile(self, id='', REQUEST=None, contributor=None, **kwargs):
    """
    Create a File type of object.
    """

    if REQUEST is not None:
        schema_raw_data = dict(REQUEST.form)
    else:
        schema_raw_data = kwargs
    _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None))
    _releasedate = self.process_releasedate(
        schema_raw_data.pop('releasedate', ''))

    _source = schema_raw_data.pop('source', 'file')
    _file = schema_raw_data.pop('file', '')
    _url = schema_raw_data.pop('url', '')
    _precondition = schema_raw_data.pop('precondition', '')

    title = schema_raw_data.get('title', '')
    if _source == 'file': id = cookId(id, title, _file)[0]  #upload from a file
    id = uniqueId(slugify(id or title or 'exfile', removelist=[]),
                  lambda x: self._getOb(x, None) is not None)

    if contributor is None:
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()

    ob = _create_NyExFile_object(self, id, contributor)

    form_errors = ob.process_submitted_form(schema_raw_data,
                                            _lang,
                                            _override_releasedate=_releasedate)

    if REQUEST is not None:
        submitter_errors = submitter.info_check(self, REQUEST, ob)
        form_errors.update(submitter_errors)

    if form_errors:
        if REQUEST is None:
            raise ValueError(form_errors.popitem()[1])  # pick a random error
        else:
            abort_transaction_keep_session(REQUEST)
            ob._prepare_error_response(REQUEST, form_errors, schema_raw_data)
            REQUEST.RESPONSE.redirect('%s/exfile_add_html' %
                                      self.absolute_url())
            return

    #process parameters
    if self.checkPermissionSkipApproval():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName(
        )
    else:
        approved, approved_by = 0, None
    ob.submitThis()
    ob.approveThis(approved, approved_by)
    ob.handleUpload(_source, _file, _url, _lang)

    self.recatalogNyObject(ob)
    notify(NyContentObjectAddEvent(ob, contributor, schema_raw_data))
    #log post date
    auth_tool = self.getAuthenticationTool()
    auth_tool.changeLastPost(contributor)
    #redirect if case
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'exfile_manage_add' or l_referer.find(
                'exfile_manage_add') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'exfile_add_html':
            self.setSession('referer', self.absolute_url())
            return ob.object_submitted_message(REQUEST)
            REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url())

    return ob.getId()
Exemplo n.º 39
0
def addNyFile(self, id='', title='', description='', coverage='', keywords='', sortorder='',
    source='file', file='', url='', precondition='', content_type='', downloadfilename='',
    contributor=None, releasedate='', discussion='', lang=None, REQUEST=None, **kwargs):
    """
    Create a File type of object.
    """
    #process parameters
    if source=='file': id = cookId(id, title, file)[0] #upload from a file
    id = self.utCleanupId(id)
    if id == '': id = PREFIX_OBJECT + self.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]
    if not(l_referer == 'file_manage_add' or l_referer.find('file_manage_add') != -1) and REQUEST:
        r = self.getSite().check_pluggable_item_properties(METATYPE_OBJECT, id=id, title=title, \
            description=description, coverage=coverage, keywords=keywords, sortorder=sortorder, \
            releasedate=releasedate, discussion=discussion, file=file, url=url, \
            downloadfilename=downloadfilename)
    else:
        r = []
    if not len(r):
        #process parameters
        if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        if self.glCheckPermissionPublishObjects():
            approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
        else:
            approved, approved_by = 0, None
        releasedate = self.process_releasedate(releasedate)
        if lang is None: lang = self.gl_get_selected_language()
        #create object
        ob = NyFile(id, title, description, coverage, keywords, sortorder, '', precondition, content_type,
            downloadfilename, contributor, releasedate, lang)
        self.gl_add_languages(ob)
        ob.createDynamicProperties(self.processDynamicProperties(METATYPE_OBJECT, REQUEST, kwargs), lang)
        self._setObject(id, ob)
        #extra settings
        ob = self._getOb(id)
        ob.updatePropertiesFromGlossary(lang)
        ob.submitThis()
        ob.approveThis(approved, approved_by)
        ob.handleUpload(source, file, url)
        ob.createVersion(self.REQUEST.AUTHENTICATED_USER.getUserName())
        if discussion: ob.open_for_comments()
        self.recatalogNyObject(ob)
        self.notifyFolderMaintainer(self, ob)
        #redirect if case
        if REQUEST is not None:
            if l_referer == 'file_manage_add' or l_referer.find('file_manage_add') != -1:
                return self.manage_main(self, REQUEST, update_menu=1)
            elif l_referer == 'file_add_html':
                self.setSession('referer', self.absolute_url())
                REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url())
    else:
        if REQUEST is not None:
            self.setSessionErrors(r)
            self.set_pluggable_item_session(METATYPE_OBJECT, id=id, title=title, \
                description=description, coverage=coverage, keywords=keywords, \
                sortorder=sortorder, releasedate=releasedate, discussion=discussion, \
                url=url, downloadfilename=downloadfilename, lang=lang)
            REQUEST.RESPONSE.redirect('%s/file_add_html' % self.absolute_url())
        else:
            raise Exception, '%s' % ', '.join(r)
Exemplo n.º 40
0
def addNySMAPExpert(self, id='', REQUEST=None, contributor=None, **kwargs):
    """
    Create a Expert type of object.
    """

    if REQUEST is not None:
        schema_raw_data = dict(REQUEST.form)
    else:
        schema_raw_data = kwargs
    _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None))
    _releasedate = self.process_releasedate(schema_raw_data.pop('releasedate', ''))

    _file = schema_raw_data.pop('file', '')
    _precondition = schema_raw_data.pop('precondition', '')
    _content_type = schema_raw_data.pop('content_type', '')
    _subtopics = schema_raw_data.pop('subtopics', '')
    _downloadfilename = schema_raw_data.pop('downloadfilename', '')
    _send_notifications = schema_raw_data.pop('_send_notifications', True)

    _subtopics = self.utConvertToList(_subtopics)
    res = {}
    for x in _subtopics:
        res[x.split('|@|')[0]] = ''
    _maintopics = res.keys()

    _title = '%s %s' % (schema_raw_data.get('surname',''), schema_raw_data.get('name',''))
    schema_raw_data['title'] = _title

    #process parameters
    if _downloadfilename == '': _downloadfilename = cookId('', _title, _file)[0]
    if id == '': id = PREFIX_OBJECT + self.utGenRandomId(6)
    if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()

    ob = _create_NySMAPExpert_object(self, id, _title, '', _precondition, _content_type, contributor)

    form_errors = ob.process_submitted_form(schema_raw_data, _lang, _override_releasedate=_releasedate)

    if form_errors:
        if REQUEST is None:
            raise ValueError(form_errors.popitem()[1]) # pick a random error
        else:
            import transaction; transaction.abort() # because we already called _crete_NyZzz_object
            ob._prepare_error_response(REQUEST, form_errors, schema_raw_data)
            REQUEST.RESPONSE.redirect('%s/expert_add_html' % self.absolute_url())
            return

    #process parameters
    if self.glCheckPermissionPublishObjects():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 0, None
    ob.submitThis()
    ob.approveThis(approved, approved_by)

    ob.subtopics = _subtopics
    ob.maintopics = _maintopics
    ob.downloadfilename = _downloadfilename

    ob.handleUpload(_file)

    if ob.discussion: ob.open_for_comments()
    self.recatalogNyObject(ob)
    if _send_notifications:
        self.notifyFolderMaintainer(self, ob)
    #log post date
    auth_tool = self.getAuthenticationTool()
    auth_tool.changeLastPost(contributor)
    #redirect if case
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'expert_manage_add' or l_referer.find('expert_manage_add') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'expert_add_html':
            self.setSession('referer', self.absolute_url())
            REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url())

    return ob.getId()
Exemplo n.º 41
0
def addNySMAPExpert(self,
                    id='',
                    title='',
                    description='',
                    coverage='',
                    keywords='',
                    surname='',
                    name='',
                    ref_lang='',
                    country='',
                    subtopics='',
                    sortorder='',
                    file='',
                    precondition='',
                    content_type='',
                    downloadfilename='',
                    email='',
                    contributor=None,
                    releasedate='',
                    discussion='',
                    lang=None,
                    REQUEST=None,
                    **kwargs):
    """
    Create a Expert type of object.
    """
    #process parameters
    if downloadfilename == '': downloadfilename = cookId('', title, file)[0]
    if id == '': id = PREFIX_OBJECT + self.utGenRandomId(6)
    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]
    if not (l_referer == 'expert_manage_add'
            or l_referer.find('expert_manage_add') != -1) and REQUEST:
        r = self.getSite().check_pluggable_item_properties(
            METATYPE_OBJECT,
            id=id,
            title=title,
            description=description,
            coverage=coverage,
            keywords=keywords,
            sortorder=sortorder,
            surname=surname,
            name=name,
            ref_lang=ref_lang,
            country=country,
            subtopics=subtopics,
            releasedate=releasedate,
            discussion=discussion,
            file=file,
            downloadfilename=downloadfilename,
            email=email)
    else:
        r = []
    if not len(r):
        #process parameters
        if contributor is None:
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        if self.glCheckPermissionPublishObjects():
            approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName(
            )
        else:
            approved, approved_by = 0, None
        releasedate = self.process_releasedate(releasedate)
        subtopics = self.utConvertToList(subtopics)
        res = {}
        for x in subtopics:
            res[x.split('|@|')[0]] = ''
        maintopics = res.keys()
        if lang is None: lang = self.gl_get_selected_language()
        #check if the id is invalid (it is already in use)
        i = 0
        while self._getOb(id, None):
            i += 1
            id = '%s-%u' % (id, i)
        #create object
        ob = NySMAPExpert(id, title, description, coverage, keywords, surname,
                          name, ref_lang, country, maintopics, subtopics,
                          sortorder, '', precondition, content_type,
                          downloadfilename, email, contributor, releasedate,
                          lang)
        self.gl_add_languages(ob)
        ob.createDynamicProperties(
            self.processDynamicProperties(METATYPE_OBJECT, REQUEST, kwargs),
            lang)
        self._setObject(id, ob)
        #extra settings
        ob = self._getOb(id)
        ob.updatePropertiesFromGlossary(lang)
        ob.submitThis()
        ob.approveThis(approved, approved_by)
        ob.handleUpload(file)
        #ob.createVersion(self.REQUEST.AUTHENTICATED_USER.getUserName())
        if discussion: ob.open_for_comments()
        self.recatalogNyObject(ob)
        self.notifyFolderMaintainer(self, ob)
        #redirect if case
        if REQUEST is not None:
            if l_referer == 'expert_manage_add' or l_referer.find(
                    'expert_manage_add') != -1:
                return self.manage_main(self, REQUEST, update_menu=1)
            elif l_referer == 'expert_add_html':
                self.setSession('referer', self.absolute_url())
                REQUEST.RESPONSE.redirect('%s/messages_html' %
                                          self.absolute_url())
    else:
        if REQUEST is not None:
            self.setSessionErrors(r)
            self.set_pluggable_item_session(METATYPE_OBJECT,
                                            id=id,
                                            title=title,
                                            description=description,
                                            coverage=coverage,
                                            keywords=keywords,
                                            sortorder=sortorder,
                                            surname=surname,
                                            name=name,
                                            ref_lang=ref_lang,
                                            country=country,
                                            subtopics=subtopics,
                                            releasedate=releasedate,
                                            discussion=discussion,
                                            downloadfilename=downloadfilename,
                                            email=email)
            REQUEST.RESPONSE.redirect('%s/expert_add_html' %
                                      self.absolute_url())
        else:
            raise Exception, '%s' % ', '.join(r)
Exemplo n.º 42
0
def addNySMAPExpert(
    self,
    id="",
    title="",
    description="",
    coverage="",
    keywords="",
    surname="",
    name="",
    ref_lang="",
    country="",
    subtopics="",
    sortorder="",
    file="",
    precondition="",
    content_type="",
    downloadfilename="",
    email="",
    contributor=None,
    releasedate="",
    discussion="",
    lang=None,
    REQUEST=None,
    **kwargs
):
    """
    Create a Expert type of object.
    """
    # process parameters
    if downloadfilename == "":
        downloadfilename = cookId("", title, file)[0]
    if id == "":
        id = PREFIX_OBJECT + self.utGenRandomId(6)
    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]
    if not (l_referer == "expert_manage_add" or l_referer.find("expert_manage_add") != -1) and REQUEST:
        r = self.getSite().check_pluggable_item_properties(
            METATYPE_OBJECT,
            id=id,
            title=title,
            description=description,
            coverage=coverage,
            keywords=keywords,
            sortorder=sortorder,
            surname=surname,
            name=name,
            ref_lang=ref_lang,
            country=country,
            subtopics=subtopics,
            releasedate=releasedate,
            discussion=discussion,
            file=file,
            downloadfilename=downloadfilename,
            email=email,
        )
    else:
        r = []
    if not len(r):
        # process parameters
        if contributor is None:
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        if self.glCheckPermissionPublishObjects():
            approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
        else:
            approved, approved_by = 0, None
        releasedate = self.process_releasedate(releasedate)
        subtopics = self.utConvertToList(subtopics)
        res = {}
        for x in subtopics:
            res[x.split("|@|")[0]] = ""
        maintopics = res.keys()
        if lang is None:
            lang = self.gl_get_selected_language()
        # check if the id is invalid (it is already in use)
        i = 0
        while self._getOb(id, None):
            i += 1
            id = "%s-%u" % (id, i)
        # create object
        ob = NySMAPExpert(
            id,
            title,
            description,
            coverage,
            keywords,
            surname,
            name,
            ref_lang,
            country,
            maintopics,
            subtopics,
            sortorder,
            "",
            precondition,
            content_type,
            downloadfilename,
            email,
            contributor,
            releasedate,
            lang,
        )
        self.gl_add_languages(ob)
        ob.createDynamicProperties(self.processDynamicProperties(METATYPE_OBJECT, REQUEST, kwargs), lang)
        self._setObject(id, ob)
        # extra settings
        ob = self._getOb(id)
        ob.updatePropertiesFromGlossary(lang)
        ob.submitThis()
        ob.approveThis(approved, approved_by)
        ob.handleUpload(file)
        # ob.createVersion(self.REQUEST.AUTHENTICATED_USER.getUserName())
        if discussion:
            ob.open_for_comments()
        self.recatalogNyObject(ob)
        self.notifyFolderMaintainer(self, ob)
        # redirect if case
        if REQUEST is not None:
            if l_referer == "expert_manage_add" or l_referer.find("expert_manage_add") != -1:
                return self.manage_main(self, REQUEST, update_menu=1)
            elif l_referer == "expert_add_html":
                self.setSession("referer", self.absolute_url())
                REQUEST.RESPONSE.redirect("%s/messages_html" % self.absolute_url())
    else:
        if REQUEST is not None:
            self.setSessionErrors(r)
            self.set_pluggable_item_session(
                METATYPE_OBJECT,
                id=id,
                title=title,
                description=description,
                coverage=coverage,
                keywords=keywords,
                sortorder=sortorder,
                surname=surname,
                name=name,
                ref_lang=ref_lang,
                country=country,
                subtopics=subtopics,
                releasedate=releasedate,
                discussion=discussion,
                downloadfilename=downloadfilename,
                email=email,
            )
            REQUEST.RESPONSE.redirect("%s/expert_add_html" % self.absolute_url())
        else:
            raise Exception, "%s" % ", ".join(r)
Exemplo n.º 43
0
def addNyFile(self, id='', REQUEST=None, contributor=None, **kwargs):
    """
    Create a File type of object.
    """

    if REQUEST is not None:
        schema_raw_data = dict(REQUEST.form)
    else:
        schema_raw_data = kwargs
    _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None))
    _releasedate = self.process_releasedate(schema_raw_data.pop('releasedate', ''))

    _source = schema_raw_data.pop('source', 'file')
    _file = schema_raw_data.pop('file', '')
    _url = schema_raw_data.pop('url', '')
    _precondition = schema_raw_data.pop('precondition', '')

    title = schema_raw_data.get('title', '')
    _contact_word = schema_raw_data.get('contact_word', '')

    #process parameters
    if _source=='file': id = cookId(id, title, _file)[0] #upload from a file
    id = self.utCleanupId(id)
    if not id: id = self.utGenObjectId(title)
    if not id: id = 'file' + self.utGenRandomId(5)
    if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()

    ob = _create_NyFile_object(self, id, title, '', _precondition, contributor)

    form_errors = ob.process_submitted_form(schema_raw_data, _lang, _override_releasedate=_releasedate)

    #check Captcha/reCaptcha
    if not self.checkPermissionSkipCaptcha():
        captcha_validator = self.validateCaptcha(_contact_word, REQUEST)
        if captcha_validator:
            form_errors['captcha'] = captcha_validator

    if form_errors:
        if REQUEST is None:
            raise ValueError(form_errors.popitem()[1]) # pick a random error
        else:
            import transaction; transaction.abort() # because we already called _crete_NyZzz_object
            ob._prepare_error_response(REQUEST, form_errors, schema_raw_data)
            REQUEST.RESPONSE.redirect('%s/file_add_html' % self.absolute_url())
            return

    #process parameters
    if self.glCheckPermissionPublishObjects():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 0, None
    ob.submitThis()
    ob.approveThis(approved, approved_by)
    ob.handleUpload(_source, _file, _url)

    if ob.discussion: ob.open_for_comments()
    self.recatalogNyObject(ob)
    notify(NyContentObjectAddEvent(ob, contributor, schema_raw_data))
    #log post date
    auth_tool = self.getAuthenticationTool()
    auth_tool.changeLastPost(contributor)
    #redirect if case
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'file_manage_add' or l_referer.find('file_manage_add') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'file_add_html':
            self.setSession('referer', self.absolute_url())
            return ob.object_submitted_message(REQUEST)
            REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url())

    return ob.getId()
Exemplo n.º 44
0
def addNyExFile(self, id='', REQUEST=None, contributor=None, **kwargs):
    """
    Create a File type of object.
    """

    if REQUEST is not None:
        schema_raw_data = dict(REQUEST.form)
    else:
        schema_raw_data = kwargs
    _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None))
    _releasedate = self.process_releasedate(schema_raw_data.pop('releasedate', ''))

    _source = schema_raw_data.pop('source', 'file')
    _file = schema_raw_data.pop('file', '')
    _url = schema_raw_data.pop('url', '')
    _precondition = schema_raw_data.pop('precondition', '')

    title = schema_raw_data.get('title', '')
    if _source=='file': id = cookId(id, title, _file)[0] #upload from a file
    id = uniqueId(slugify(id or title or 'exfile', removelist=[]),
                  lambda x: self._getOb(x, None) is not None)

    if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()

    ob = _create_NyExFile_object(self, id, contributor)

    form_errors = ob.process_submitted_form(schema_raw_data, _lang, _override_releasedate=_releasedate)

    if REQUEST is not None:
        submitter_errors = submitter.info_check(self, REQUEST, ob)
        form_errors.update(submitter_errors)

    if form_errors:
        if REQUEST is None:
            raise ValueError(form_errors.popitem()[1]) # pick a random error
        else:
            abort_transaction_keep_session(REQUEST)
            ob._prepare_error_response(REQUEST, form_errors, schema_raw_data)
            REQUEST.RESPONSE.redirect('%s/exfile_add_html' % self.absolute_url())
            return

    #process parameters
    if self.checkPermissionSkipApproval():
        approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
    else:
        approved, approved_by = 0, None
    ob.submitThis()
    ob.approveThis(approved, approved_by)
    ob.handleUpload(_source, _file, _url, _lang)

    self.recatalogNyObject(ob)
    notify(NyContentObjectAddEvent(ob, contributor, schema_raw_data))
    #log post date
    auth_tool = self.getAuthenticationTool()
    auth_tool.changeLastPost(contributor)
    #redirect if case
    if REQUEST is not None:
        l_referer = REQUEST['HTTP_REFERER'].split('/')[-1]
        if l_referer == 'exfile_manage_add' or l_referer.find('exfile_manage_add') != -1:
            return self.manage_main(self, REQUEST, update_menu=1)
        elif l_referer == 'exfile_add_html':
            self.setSession('referer', self.absolute_url())
            return ob.object_submitted_message(REQUEST)
            REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url())

    return ob.getId()
Exemplo n.º 45
0
def addNyFile(self, id='', title='', description='', coverage='', keywords='', sortorder='',
    source='file', file='', url='', precondition='', content_type='', downloadfilename='',
    contributor=None, releasedate='', discussion='', lang=None, REQUEST=None, **kwargs):
    """
    Create a File type of object.
    """
    #process parameters
    if source=='file': id = cookId(id, title, file)[0] #upload from a file
    id = self.utCleanupId(id)
    if id == '': id = PREFIX_OBJECT + self.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]
    if not(l_referer == 'file_manage_add' or l_referer.find('file_manage_add') != -1) and REQUEST:
        r = self.getSite().check_pluggable_item_properties(METATYPE_OBJECT, id=id, title=title, \
            description=description, coverage=coverage, keywords=keywords, sortorder=sortorder, \
            releasedate=releasedate, discussion=discussion, file=file, url=url, \
            downloadfilename=downloadfilename)
    else:
        r = []
    if not len(r):
        #process parameters
        if contributor is None: contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        if self.glCheckPermissionPublishObjects():
            approved, approved_by = 1, self.REQUEST.AUTHENTICATED_USER.getUserName()
        else:
            approved, approved_by = 0, None
        releasedate = self.process_releasedate(releasedate)
        if lang is None: lang = self.gl_get_selected_language()
        #create object
        ob = NyFile(id, title, description, coverage, keywords, sortorder, '', precondition, content_type,
            downloadfilename, contributor, releasedate, lang)
        self.gl_add_languages(ob)
        ob.createDynamicProperties(self.processDynamicProperties(METATYPE_OBJECT, REQUEST, kwargs), lang)
        self._setObject(id, ob)
        #extra settings
        ob = self._getOb(id)
        ob.updatePropertiesFromGlossary(lang)
        ob.submitThis()
        ob.approveThis(approved, approved_by)
        ob.handleUpload(source, file, url)
        ob.createVersion(self.REQUEST.AUTHENTICATED_USER.getUserName())
        if discussion: ob.open_for_comments()
        self.recatalogNyObject(ob)
        self.notifyFolderMaintainer(self, ob)
        #redirect if case
        if REQUEST is not None:
            if l_referer == 'file_manage_add' or l_referer.find('file_manage_add') != -1:
                return self.manage_main(self, REQUEST, update_menu=1)
            elif l_referer == 'file_add_html':
                self.setSession('referer', self.absolute_url())
                REQUEST.RESPONSE.redirect('%s/messages_html' % self.absolute_url())
    else:
        if REQUEST is not None:
            self.setSessionErrors(r)
            self.set_pluggable_item_session(METATYPE_OBJECT, id=id, title=title, \
                description=description, coverage=coverage, keywords=keywords, \
                sortorder=sortorder, releasedate=releasedate, discussion=discussion, \
                url=url, downloadfilename=downloadfilename, lang=lang)
            REQUEST.RESPONSE.redirect('%s/file_add_html' % self.absolute_url())
        else:
            raise Exception, '%s' % ', '.join(r)