Ejemplo n.º 1
0
 def on_save(self, obj):
     if obj.__fields_values__[self.name] is None:
         obj.__fields_values__[self.name] = self.default
     if obj.id is None:
         if self.unique:
             unique_field_key = "%s__%s" % (
                                 obj.__get_elastic_type_name__(),
                                 self.name
                                 )
             unique_data = {'_id': obj.__fields_values__[self.name],
                            '_type': unique_field_key}
             try:
                 ElasticOSMConnection.get_connection().index(
                                     unique_data,
                                     ElasticOSMConnection.get_uniques_db(),
                                     unique_data['_id'],
                                     unique_data['_type'],
                                     op_type='create'
                                     )
             except AlreadyExistsException:
                 raise UniqueFieldExistsException('Value %s exists for ' + \
                                                  'field %s' % (
                                                     unique_data['_id'],
                                                     self.name)
                                                  )