def _delete_and_rebuild_datadict(self, resource):
        import json
        import unicodedata

        if 'datadict' in resource and 'id' in resource:
            record = resource.pop('datadict')

            if record:
                # Cleanse of errant unicode characters
                record = unicodedata.normalize('NFKD', record).encode('ascii', 'ignore')

                try:
                    json_record = json.loads(record)
                except ValueError as err:
                    # Invalid JSON, so don't remove old data
                    error_message = "Error saving data dictionary: {0}.  Data was: {1}".format(err, record)
                    flash_error(error_message)
                    return

                try:
                    ds.delete_datastore_json(resource['id'], 'datadict')
                # don't fail if the filter is bad! (e.g., title_colname doesn't exist)
                except (tk.ObjectNotFound, tk.ValidationError), err:
                    # code review: write tests for this.
                    error_message = "Error saving data dictionary: {0}.  Data was: {1}".format(e, record)
                    flash_error(error_message)
                    pass

            try:
                ds.create_datastore(resource['id'], json_title='datadict', json_record=json_record)
            except UnicodeEncodeError as err:
                error_message = "Error saving data dictionary: {0}.  Data was: {1}".format(e, record)
                flash_error(error_message)
 def _delete_and_rebuild_datadict(self, resource):
     import json
     if 'datadict' in resource and 'id' in resource:
         record = resource['datadict']
         resource.pop('datadict')
         json_record = json.loads(record)
         try:
             ds.delete_datastore_json(resource['id'], 'datadict')
         except tk.ObjectNotFound, err:
             pass
         except tk.ValidationError, err:
             # don't fail if the filter is bad! (e.g., title_colname doesn't exist)
             pass
示例#3
0
 def _delete_and_rebuild_datadict(self, resource):
     import json
     if 'datadict' in resource and 'id' in resource:
         record = resource['datadict']
         resource.pop('datadict')
         json_record = json.loads(record)
         try:
             ds.delete_datastore_json(resource['id'], 'datadict')
         # don't fail if the filter is bad! (e.g., title_colname doesn't exist)
         except (tk.ObjectNotFound, tk.ValidationError), err:
             # code review: write tests for this.
             pass
         ds.create_datastore(resource['id'],
                             json_title='datadict',
                             json_record=json_record)
    def _delete_and_rebuild_datadict(self, resource):
        import json
        import unicodedata

        if 'datadict' in resource and 'id' in resource:
            record = resource.pop('datadict')

            if record:
                # Cleanse of errant unicode characters
                record = unicodedata.normalize('NFKD', record).encode(
                    'ascii', 'ignore')

                try:
                    json_record = json.loads(record)
                except ValueError as err:
                    # Invalid JSON, so don't remove old data
                    error_message = "Error saving data dictionary: {0}.  Data was: {1}".format(
                        err, record)
                    flash_error(error_message)
                    return

                try:
                    ds.delete_datastore_json(resource['id'], 'datadict')
                # don't fail if the filter is bad! (e.g., title_colname doesn't exist)
                except (tk.ObjectNotFound, tk.ValidationError), err:
                    # code review: write tests for this.
                    error_message = "Error saving data dictionary: {0}.  Data was: {1}".format(
                        e, record)
                    flash_error(error_message)
                    pass

            try:
                ds.create_datastore(resource['id'],
                                    json_title='datadict',
                                    json_record=json_record)
            except UnicodeEncodeError as err:
                error_message = "Error saving data dictionary: {0}.  Data was: {1}".format(
                    e, record)
                flash_error(error_message)