コード例 #1
0
    def _save_new(self):
        try:
            data_dict = dict(request.params)
            self._check_data_dict(data_dict)
            context = {
                'model': model,
                'user': c.user,
                'session': model.Session,
                'schema': harvest_source_form_schema()
            }

            source = p.toolkit.get_action('harvest_source_create')(context,
                                                                   data_dict)
            context = {
                'model': model,
                'user': c.user or c.author,
                'auth_user_obj': c.userobj
            }

            # Create a harvest job for the new source
            p.toolkit.get_action('harvest_job_create')(
                context, {
                    'source_id': source['id']
                })

            h.flash_success(
                _('New harvest source added successfully.'
                  'A new harvest job for the source has also been created.'))
            redirect('/harvest/%s' % source['id'])
        except p.toolkit.NotAuthorized, e:
            abort(401, self.not_auth_message)
コード例 #2
0
ファイル: view.py プロジェクト: tbalaz/test
    def _check_data_dict(self, data_dict):
        '''Check if the return data is correct'''
        surplus_keys_schema = ['id','publisher_id','user_id','config','save']
        schema_keys = harvest_source_form_schema().keys()
        keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

        # user_id is not yet used, we'll set the logged user one for the time being
        if not data_dict.get('user_id',None):
            if c.userobj:
                data_dict['user_id'] = c.userobj.id
        if keys_in_schema - set(data_dict.keys()):
            err = "%s, %s" % (data_dict.keys(), keys_in_schema,)
            raise Exception(err)
コード例 #3
0
ファイル: view.py プロジェクト: atrawog/ckanext-harvest
    def _check_data_dict(self, data_dict):
        '''Check if the return data is correct'''
        surplus_keys_schema = ['id','publisher_id','user_id','config','save']
        schema_keys = harvest_source_form_schema().keys()
        keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

        # user_id is not yet used, we'll set the logged user one for the time being
        if not data_dict.get('user_id',None):
            if c.userobj:
                data_dict['user_id'] = c.userobj.id
        if keys_in_schema - set(data_dict.keys()):
            log.info(_('Incorrect form fields posted'))
            raise DataError(data_dict)
コード例 #4
0
ファイル: view.py プロジェクト: tbalaz/test
    def _save_edit(self,id):
        try:
            data_dict = dict(request.params)
            data_dict['id'] = id
            self._check_data_dict(data_dict)
            context = {'model':model, 'user':c.user, 'session':model.Session,
                       'schema':harvest_source_form_schema()}

            source = p.toolkit.get_action('harvest_source_update')(context,data_dict)

            h.flash_success(_('Harvest source edited successfully.'))
            redirect('/harvest/%s' %id)
        except p.toolkit.NotAuthorized,e:
            abort(401,self.not_auth_message)
コード例 #5
0
    def _check_data_dict(self, data_dict):
        '''Check if the return data is correct'''
        surplus_keys_schema = [
            'id', 'publisher_id', 'user_id', 'config', 'save'
        ]
        schema_keys = harvest_source_form_schema().keys()
        keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

        # user_id is not yet used, we'll set the logged user one for the time being
        if not data_dict.get('user_id', None):
            if c.userobj:
                data_dict['user_id'] = c.userobj.id
        if keys_in_schema - set(data_dict.keys()):
            log.info(_('Incorrect form fields posted'))
            raise DataError(data_dict)
コード例 #6
0
ファイル: view.py プロジェクト: atrawog/ckanext-harvest
    def _save_new(self):
        try:
            data_dict = dict(request.params)
            self._check_data_dict(data_dict)
            context = {'model':model, 'user':c.user, 'session':model.Session,
                       'schema':harvest_source_form_schema()}

            source = get_action('harvest_source_create')(context,data_dict)

            # Create a harvest job for the new source
            get_action('harvest_job_create')(context,{'source_id':source['id']})

            h.flash_success(_('New harvest source added successfully.'
                    'A new harvest job for the source has also been created.'))
            redirect('/harvest/%s' % source['id'])
        except NotAuthorized,e:
            abort(401,self.not_auth_message)
コード例 #7
0
    def _check_data_dict(self, data_dict):
        '''Check if the return data is correct'''
        surplus_keys_schema = [
            'id', 'publisher_id', 'user_id', 'config', 'save'
        ]
        schema_keys = harvest_source_form_schema().keys()
        keys_in_schema = set(schema_keys) - set(surplus_keys_schema)

        # user_id is not yet used, we'll set the logged user one for the time being
        if not data_dict.get('user_id', None):
            if c.userobj:
                data_dict['user_id'] = c.userobj.id
        if keys_in_schema - set(data_dict.keys()):
            err = "%s, %s" % (
                data_dict.keys(),
                keys_in_schema,
            )
            raise Exception(err)
コード例 #8
0
    def _save_edit(self, id):
        try:
            data_dict = dict(request.params)
            data_dict['id'] = id
            self._check_data_dict(data_dict)
            context = {
                'model': model,
                'user': c.user,
                'session': model.Session,
                'schema': harvest_source_form_schema()
            }

            source = get_action('harvest_source_update')(context, data_dict)

            h.flash_success(_('Harvest source edited successfully.'))
            redirect('/harvest/%s' % id)
        except NotAuthorized, e:
            abort(401, self.not_auth_message)