コード例 #1
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject(
        ):  #Check if user can edit the content
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            self = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        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', ''))
        form_errors = self.process_submitted_form(
            schema_raw_data, _lang, _override_releasedate=_releasedate)

        self.start_date = self.utConvertStringToDateTimeObj(
            schema_raw_data.get('start_date', None))
        self.end_date = self.utConvertStringToDateTimeObj(
            schema_raw_data.get('end_date', None))

        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
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                return REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                                 (self.absolute_url(), _lang))

        if schema_raw_data.get('discussion', None):
            self.open_for_comments()
        else:
            self.close_for_comments()
        self._p_changed = 1
        self.recatalogNyObject(self)

        # Create log
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)

        zope.event.notify(NyContentObjectEditEvent(self, contributor))

        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            return REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                             (self.absolute_url(), _lang))
コード例 #2
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
        else:
            obj = self

        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', ''), obj.releasedate)

        #Process uploaded file
        _uploaded_file = schema_raw_data.pop('organisation_picture', None)
        if _uploaded_file is not None and _uploaded_file.filename:
            self.picture = make_blobfile(_uploaded_file,
                                         removed=False,
                                         timestamp=datetime.utcnow())

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

        if not form_errors:
            if self.discussion: self.open_for_comments()
            else: self.close_for_comments()
            self._p_changed = 1
            self.recatalogNyObject(self)
            #log date
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
            auth_tool = self.getAuthenticationTool()
            auth_tool.changeLastPost(contributor)
            notify(NyContentObjectEditEvent(self, contributor))
            if REQUEST:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
        else:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error
コード例 #3
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED(EXCEPTION_NOTAUTHORIZED_MSG)

        obj = self

        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', ''), obj.releasedate)

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

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

        if not form_errors:
            # Upload file
            if _source:
                self.saveUpload(source=_source,
                                file=_file,
                                url=_url,
                                lang=_lang)

            if self.discussion:
                self.open_for_comments()
            else:
                self.close_for_comments()
            self._p_changed = 1
            self.recatalogNyObject(self)
            # log date
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
            auth_tool = self.getAuthenticationTool()
            auth_tool.changeLastPost(contributor)
            notify(NyContentObjectEditEvent(self, contributor))
            if REQUEST:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
        else:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
            else:
                raise ValueError(form_errors.popitem()[1])  # pick an error
コード例 #4
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
        else:
            obj = self

        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))

        info_type = schema_raw_data.pop('info_type', None)
        self.info_type = info_type
        FolderMetaTypes(self).set_values(self.get_meta_types())

        self.set_categories()

        form_errors = self.process_submitted_form(schema_raw_data, _lang)

        if not form_errors:
            if self.discussion: self.open_for_comments()
            else: self.close_for_comments()
            self._p_changed = 1
            self.recatalogNyObject(self)
            #log date
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
            auth_tool = self.getAuthenticationTool()
            auth_tool.changeLastPost(contributor)
            notify(NyContentObjectEditEvent(self, contributor))
            if REQUEST:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
        else:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error
コード例 #5
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
        else:
            obj = self

        if REQUEST is not None:
            schema_raw_data = dict(REQUEST.form)
        else:
            schema_raw_data = kwargs
            #Remove first '/'
        if ('pointer' in schema_raw_data
                and schema_raw_data['pointer'].startswith('/')):
            schema_raw_data['pointer'] = schema_raw_data['pointer'][1:]

        _lang = schema_raw_data.pop('_lang', schema_raw_data.pop('lang', None))
        _releasedate = self.process_releasedate(
            schema_raw_data.pop('releasedate', ''), obj.releasedate)

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

        if not form_errors:
            self._p_changed = 1
            self.recatalogNyObject(self)
            #log date
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
            auth_tool = self.getAuthenticationTool()
            auth_tool.changeLastPost(contributor)
            notify(NyContentObjectEditEvent(self, contributor))
            if REQUEST:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
        else:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error
コード例 #6
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        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', ''), self.releasedate)
        _uploaded_file = schema_raw_data.pop('uploaded_file', None)
        versions_to_remove = schema_raw_data.pop('versions_to_remove', [])

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

        if form_errors:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
                return
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error

        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()

        for ver_id in reversed(versions_to_remove):
            self.remove_version(int(ver_id) - 1, _lang, contributor)

        self._p_changed = 1
        self.recatalogNyObject(self)
        #log date
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)

        if file_has_content(_uploaded_file):
            self._save_file(_uploaded_file, _lang, contributor)

        notify(NyContentObjectEditEvent(self, contributor))

        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                      (self.absolute_url(), _lang))
コード例 #7
0
 def commitVersion(self, REQUEST=None):
     """ """
     user = self.REQUEST.AUTHENTICATED_USER.getUserName()
     if not self.checkPermissionEditObject() or self.checkout_user != user:
         raise EXCEPTION_NOTAUTHORIZED(EXCEPTION_NOTAUTHORIZED_MSG)
     if not self.hasVersion():
         raise EXCEPTION_NOVERSION(EXCEPTION_NOVERSION_MSG)
     self.copy_naaya_properties_from(self.version)
     self.checkout = 0
     self.checkout_user = None
     self.version = None
     self._p_changed = 1
     self.recatalogNyObject(self)
     notify(NyContentObjectEditEvent(self, user))
     if REQUEST:
         REQUEST.RESPONSE.redirect('%s/index_html' % self.absolute_url())
コード例 #8
0
 def commitVersion(self, REQUEST=None):
     """ """
     user = self.REQUEST.AUTHENTICATED_USER.getUserName()
     if (not self.checkPermissionEditObject()) or (
         self.checkout_user != user):
         raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
     if not self.hasVersion():
         raise EXCEPTION_NOVERSION, EXCEPTION_NOVERSION_MSG
     version = self._getOb('version')
     self.copy_naaya_properties_from(version)
     self.copyFileItems(version, self)
     self.checkout = 0
     self.checkout_user = None
     if 'version' in self.objectIds():
         self.manage_delObjects(['version'])
     self._p_changed = 1
     self.recatalogNyObject(self)
     notify(NyContentObjectEditEvent(self, user))
     if REQUEST: REQUEST.RESPONSE.redirect('%s/index_html' % self.absolute_url())
コード例 #9
0
ファイル: semnews_item.py プロジェクト: eaudeweb/trunk-eggs
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject(
        ):  #Check if user can edit the content
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            self = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        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', ''))
        old_news_date = self.news_date
        form_errors = self.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
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                return REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                                 (self.absolute_url(), _lang))

        new_news_date = self.utConvertStringToDateTimeObj(
            schema_raw_data.get('news_date', None))
        moved = False
        #If month or year changed then move the item to other folder
        if ((new_news_date.month(), new_news_date.year()) !=
            (old_news_date.month(), old_news_date.year())):
            self.news_date = new_news_date
            month_folder = create_month_folder(
                self.aq_parent.aq_parent.aq_parent, self.contributor,
                schema_raw_data)
            cut_data = self.aq_parent.manage_cutObjects([
                self.id,
            ])
            month_folder.manage_pasteObjects(cut_data)
            moved = True

        if 'file' in schema_raw_data:  # Upload file
            self.handleUpload(schema_raw_data['file'])

        if schema_raw_data.get('discussion', None):
            self.open_for_comments()
        else:
            self.close_for_comments()
        self._p_changed = 1
        if moved:
            month_folder.recatalogNyObject(month_folder._getOb(self.getId()))
        else:
            self.recatalogNyObject(self)
        # Create log
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)

        zope.event.notify(NyContentObjectEditEvent(self, contributor))

        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            if moved:  #Redirect to moved location
                url = month_folder._getOb(self.id).absolute_url()
            else:
                url = self.absolute_url()
            return REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                             (url, _lang))
コード例 #10
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if self.hasVersion():
            obj = self.version
            if self.checkout_user != \
                    self.REQUEST.AUTHENTICATED_USER.getUserName():
                raise EXCEPTION_NOTAUTHORIZED(EXCEPTION_NOTAUTHORIZED_MSG)
        else:
            obj = self

        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', ''), obj.releasedate)

        edit_species = schema_raw_data.pop('edit_species', None)
        delete_picture = schema_raw_data.pop('delete_picture', None)
        schema_raw_data['title'] = obj.title

        ambassador_species = schema_raw_data.get('ambassador_species', '')
        ambassador_species_description = schema_raw_data.get(
            'ambassador_species_description', '')

        delete_species = sorted(
            list(schema_raw_data.pop('delete_species', '')), reverse=True)
        if edit_species is None:
            for list_index in delete_species:
                self.species.pop(int(list_index))

        # picture processing
        upload_picture_url = schema_raw_data.pop('upload_picture_url', None)
        if upload_picture_url:
            temp_folder = self.getSite().temp_folder
            picture_id = unquote(upload_picture_url.split('/')[-1])
            ambassador_species_picture = getattr(temp_folder, picture_id)
        else:
            ambassador_species_picture = None
        x1 = schema_raw_data.pop('x1')
        y1 = schema_raw_data.pop('y1')
        x2 = schema_raw_data.pop('x2')
        y2 = schema_raw_data.pop('y2')
        crop_coordinates = (x1, y1, x2, y2)

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

        species_success = self.process_species(
            edit_species, delete_picture, ambassador_species,
            ambassador_species_description, ambassador_species_picture,
            crop_coordinates, form_errors)

        if form_errors:
            if REQUEST is not None:
                if not species_success:
                    schema_raw_data['ambassador_species'] = ambassador_species
                    schema_raw_data['ambassador_species_description'] = \
                        ambassador_species_description
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                if edit_species is not None and not species_success:
                    REQUEST.RESPONSE.redirect(
                        '%s/edit_html?lang=%s&edit_species=%s' % (
                            self.absolute_url(), _lang, edit_species))
                else:
                    REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                              (self.absolute_url(), _lang))
                return
            else:
                raise ValueError(form_errors.popitem()[1])  # pick an error

        if self.discussion:
            self.open_for_comments()
        else:
            self.close_for_comments()

        # if the user doesn't have permission to publish objects,
        # the object must be unapproved
        if not self.glCheckPermissionPublishObjects():
            self.approveThis(0, None)
            self.sendEmailNotificationWhenUnapproved()

        # Overwrite any inconsistent values in the choice property
        if not self.species and self.choice == u'3':
            self.choice = u'1'
        if self.species:
            self.choice = u'3'

        self._p_changed = 1
        self.recatalogNyObject(self)
        # log date
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)
        notify(NyContentObjectEditEvent(self, contributor))
        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                      (self.absolute_url(), _lang))
コード例 #11
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
        else:
            obj = self

        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', ''), obj.releasedate)

        _subtitle = schema_raw_data.pop('subtitle', '')
        _subtitle_file = schema_raw_data.pop('subtitle_file', None)
        _startup_image = schema_raw_data.pop('startup_image', '')
        _delete_startup_image = schema_raw_data.pop('delete_startup_image', '')
        _source = schema_raw_data.pop('source', None)
        _file = schema_raw_data.pop('file', '')

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

        # TODO: check if video file is good video file

        if form_errors:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
                return
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error

        if _subtitle_file:
            _subtitle = force_to_unicode(_subtitle_file.read())
        self._setLocalPropValue('subtitle', _lang, _subtitle)
        if _delete_startup_image:
            self.startup_image = None
        if _startup_image:
            self.startup_image = make_blobfile(_startup_image)
        if _source:
            self.saveUpload(file=_file, lang=_lang)

        self._p_changed = 1
        self.recatalogNyObject(self)
        #log date
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)
        notify(NyContentObjectEditEvent(self, contributor))
        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                      (self.absolute_url(), _lang))
コード例 #12
0
class CSVImporterTask(Persistent):
    """ An import task for rows from Excel/CSV files
    """

    payload = None
    template = None
    error = None
    status = 'unfinished'

    def __init__(self, *args, **kwargs):
        super(CSVImporterTask, self).__init__(*args, **kwargs)
        self.warnings = PersistentList()
        self.errors = PersistentList()

    def on_failure(self, *args, **kwargs):
        self.status = 'failed'

    def on_success(self, *args, **kwargs):
        self.status = 'finished'

    def run(self, *args, **kwargs):

        self.payload = kwargs['payload']
        self.template = kwargs['template']
        self.rec_id = kwargs['rec_id']

        site = getSite()

        user = getSecurityManager().getUser()
        acl_users = site.acl_users
        user = user.__of__(acl_users)
        user_id = kwargs['user_id']

        request = BaseRequest()
        request.response = Response()
        request.AUTHENTICATED_USER = user
        request['PARENTS'] = [site]
        request['URL'] = kwargs['url']
        request.steps = []
        request.cookies = {}
        request.form = {}

        import_location = site.unrestrictedTraverse(kwargs['import_path'])

        import_location.REQUEST = request
        site.REQUEST = request

        geo_fields = kwargs['geo_fields']
        self.prop_map = kwargs['properties']
        meta_type = kwargs['meta_type']

        header = self.template
        row = self.payload
        record_number = self.rec_id

        content_type = import_location.getSite().get_pluggable_item(meta_type)
        add_object = content_type['add_method']

        properties = {}
        extra_properties = {}
        address = None

        for column, value in zip(header, row):

            if value == '':
                continue

            if column not in self.prop_map:
                extra_properties[column] = value
                continue

            key = self.prop_map[column]['column']
            widget = self.prop_map[column]['widget']
            widget = widget.__of__(import_location)
            convert = widget.convert_from_user_string
            properties[key] = convert(value)

        try:
            properties = do_geocoding(geo_fields, properties)
        except GeocoderServiceError, e:
            msg = (
                'Warnings: could not find a valid address '
                'for row ${record_number}: ${error}',
                {
                    'record_number': record_number + 1,  # account for header
                    'error': str(e)
                })
            self.warnings.append(msg)
            address = properties.pop(geo_fields['address'])

        ob_id = add_object(import_location,
                           _send_notifications=False,
                           **properties)
        ob = import_location._getOb(ob_id)
        if address:
            setattr(ob, geo_fields['address'].split('.')[0],
                    Geo(address=address))
            notify(NyContentObjectEditEvent(ob, user_id))
        if extra_properties:
            adapter = ICSVImportExtraColumns(ob, None)
            if adapter is not None:
                extra_props_messages = adapter.handle_columns(extra_properties)
                if extra_props_messages:
                    self.errors.append(extra_props_messages)
        #obj_ids.append(ob.getId())
        ob.submitThis()
        ob.approveThis(_send_notifications=False)

        del import_location.REQUEST
        del site.REQUEST
コード例 #13
0
ファイル: youtube_item.py プロジェクト: eaudeweb/trunk-eggs
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED(EXCEPTION_NOTAUTHORIZED_MSG)

        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', ''), self.releasedate)

        if schema_raw_data['iframe_width'] in ['', '0']:
            schema_raw_data['iframe_width'] = 640
        if schema_raw_data['iframe_height'] in ['', '0']:
            schema_raw_data['iframe_height'] = 360

        if len(schema_raw_data['youtube_id']) > 11:
            try:
                schema_raw_data['youtube_id'] = schema_raw_data[
                    'youtube_id'].split('watch?v=')[1][:11]
            except IndexError:
                schema_raw_data['youtube_id'] = schema_raw_data[
                    'youtube_id'].split('&v=')[1][:11]

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

        try:
            schema_raw_data['iframe_width'] = int(
                schema_raw_data['iframe_width'])
        except ValueError:
            form_errors['iframe_width'] = ['Integer value required.']
        try:
            schema_raw_data['iframe_height'] = int(
                schema_raw_data['iframe_height'])
        except ValueError:
            form_errors['iframe_height'] = ['Integer value required.']
        if not schema_raw_data['youtube_id']:
            form_errors['youtube_id'] = ['Youtube Id is mandatory']

        if schema_raw_data['youtube_id']:
            yt_service = YouTubeService()
            try:
                yt_service.GetYouTubeVideoEntry(
                    video_id=schema_raw_data['youtube_id'])
            except RequestError:
                form_errors['youtube_id'] = [
                    'Invalid Youtube ID (inexisting video)'
                ]

        if not form_errors:
            if self.discussion:
                self.open_for_comments()
            else:
                self.close_for_comments()
            self._p_changed = 1
            self.recatalogNyObject(self)
            # log date
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
            auth_tool = self.getAuthenticationTool()
            auth_tool.changeLastPost(contributor)
            notify(NyContentObjectEditEvent(self, contributor))
            if REQUEST:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
        else:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
            else:
                raise ValueError(form_errors.popitem()[1])  # pick an error
コード例 #14
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
        else:
            obj = self

        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', ''), obj.releasedate)

        self.last_modification = time.localtime()

        #geo-location: 'geo_location' should always be removed from the schema_raw_data
        #because the form should contain 'geo_location.lat' type of data
        if schema_raw_data.has_key('geo_location'):
            schema_raw_data.pop('geo_location')
        _city = schema_raw_data.get('organisation_city', None)
        _country = schema_raw_data.get('organisation_country', None)
        _address = ''
        if _city or _country:
            _address = _city + ', ' + _country
        if _address:
            old_geo_location = self.geo_location not in (
                None, Geo()) and self.geo_location.address != _address
            no_geo_location = self.geo_location in (None, Geo())
            if old_geo_location or no_geo_location:
                _lat, _lon = self.do_geocoding(_address)
            else:
                _lat, _lon = self.geo_location.lat, self.geo_location.lon
            schema_raw_data['geo_location.lat'] = _lat
            schema_raw_data['geo_location.lon'] = _lon
            schema_raw_data['geo_location.address'] = _address

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

        if form_errors:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
                return
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error

        if self.discussion: self.open_for_comments()
        else: self.close_for_comments()

        self._p_changed = 1
        self.recatalogNyObject(self)
        #log date
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)
        notify(NyContentObjectEditEvent(self, contributor))
        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                      (self.absolute_url(), _lang))
コード例 #15
0
ファイル: expert_item.py プロジェクト: eaudeweb/trunk-eggs
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED(EXCEPTION_NOTAUTHORIZED_MSG)

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != \
                    self.REQUEST.AUTHENTICATED_USER.getUserName():
                raise EXCEPTION_NOTAUTHORIZED(EXCEPTION_NOTAUTHORIZED_MSG)
        else:
            obj = self

        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', ''), obj.releasedate)

        schema_raw_data['title'] = (schema_raw_data['name'] + ' ' +
                                    schema_raw_data['surname'])

        # Process uploaded file
        self.save_file(schema_raw_data, 'picture', 'expert_picture')
        self.save_file(schema_raw_data, 'cv', 'expert_cv')

        # Process employment history
        start = schema_raw_data.pop('start', None)
        end = schema_raw_data.pop('end', None)
        current = schema_raw_data.pop('current', None)
        organisation = schema_raw_data.pop('organisation', None)
        self.add_EmploymentRecord(start, end, organisation, current)

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

        if form_errors:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect(
                    '%s/edit_html?lang=%s' % (self.absolute_url(), _lang))
                return
            else:
                raise ValueError(form_errors.popitem()[1])  # pick an error

        if self.discussion:
            self.open_for_comments()
        else:
            self.close_for_comments()

        self._p_changed = 1
        self.recatalogNyObject(self)
        # log date
        contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
        auth_tool = self.getAuthenticationTool()
        auth_tool.changeLastPost(contributor)
        notify(NyContentObjectEditEvent(self, contributor))
        if REQUEST:
            self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                     date=self.utGetTodayDate())
            REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                      (self.absolute_url(), _lang))
コード例 #16
0
    def saveProperties(self, REQUEST=None, **kwargs):
        """ """
        if not self.checkPermissionEditObject():
            raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG

        if self.hasVersion():
            obj = self.version
            if self.checkout_user != self.REQUEST.AUTHENTICATED_USER.getUserName(
            ):
                raise EXCEPTION_NOTAUTHORIZED, EXCEPTION_NOTAUTHORIZED_MSG
        else:
            obj = self

        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', ''), obj.releasedate)

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

        spatial_scale = schema_raw_data.get('spatial_scale')
        geographical_scope = schema_raw_data.get('geographical_scope')
        if (spatial_scale == 'regional-case-study-covers-more-one-country'
                and len(geographical_scope) < 2):
            form_errors.setdefault('geographical_scope', [])
            form_errors['geographical_scope'].append(
                'For regional case studies please select at least 2 countries')
        if (spatial_scale and
                spatial_scale != 'regional-case-study-covers-more-one-country'
                and len(geographical_scope) > 1):
            form_errors.setdefault('geographical_scope', [])
            form_errors['geographical_scope'].append(
                'For national or sub-national case studies please select exactly '
                'one country')

        if not form_errors:
            self._p_changed = 1
            self.recatalogNyObject(self)
            #log date
            contributor = self.REQUEST.AUTHENTICATED_USER.getUserName()
            auth_tool = self.getAuthenticationTool()
            auth_tool.changeLastPost(contributor)
            notify(NyContentObjectEditEvent(self, contributor))
            if REQUEST:
                self.setSessionInfoTrans(MESSAGE_SAVEDCHANGES,
                                         date=self.utGetTodayDate())
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
        else:
            if REQUEST is not None:
                self._prepare_error_response(REQUEST, form_errors,
                                             schema_raw_data)
                REQUEST.RESPONSE.redirect('%s/edit_html?lang=%s' %
                                          (self.absolute_url(), _lang))
            else:
                raise ValueError(
                    form_errors.popitem()[1])  # pick a random error