def search_instance_save(model_name, pk): try: instance = get_instance(model_name, pk) registry.update(instance) registry.update_related(instance) except Exception as e: logger.exception(e)
def delete_document(sender, **kwargs): """Update document on deleted records. Updates Book document from index if related `books.Publisher` (`publisher`), `books.Author` (`authors`), `books.Tag` (`tags`) fields have been removed from database. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'recipes': # If it is `books.Author` that is being updated. if model_name == 'author': instances = instance.books.all() for _instance in instances: registry.update(_instance) # registry.delete(_instance, raise_on_error=False) # If it is `books.Tag` that is being updated. if model_name == 'recipe': instances = instance.books.all() for _instance in instances: registry.update(_instance)
def sync_task(obj_id, delete: bool = False) -> None: if delete: obj = model(id=obj_id) registry.delete(obj, raise_on_error=False) else: obj = document().get_queryset().prefetch_related(None).get( id=obj_id) registry.update(obj)
def save(self, *args, **kwargs): #sql = kwargs.pop('sql', True) if self._meta.managed is False: registry.update(self) registry.update_related(self) else: super().save(*args, **kwargs)
def update_document_task(app_label, object_name, instance_id): instance = _instance(app_label, object_name, instance_id) registry.update(instance) return { 'app': app_label, 'model': object_name, 'instance_id': instance_id }
def handle_save_task(pk, app_label, model_name): model_cls = apps.get_model(app_label, model_name) try: instance = model_cls.objects.get(pk=pk) registry.update(instance) registry.update_related(instance) except model_cls.DoesNotExist: # it can happen that the instance is already deleted before processed. pass
def update_with_related_task(app_label, object_name, instance_id): instance = _instance(app_label, object_name, instance_id) registry.update(instance) registry.update_related(instance) return { 'app': app_label, 'model': object_name, 'instance_id': instance_id }
def index_product(brand=None, exclude=None): qs = Product.objects.filter(is_valid=True) if brand: qs = qs.filter(brand=brand) if exclude: qs = qs.exclude(brand=exclude) for p in qs: logger.debug(f'index: {p.id}') registry.update(p)
def registry_update_task(pk, app_label, model_name): try: model = apps.get_model(app_label, model_name) except LookupError as e: sentry.log_error(e) pass else: registry.update( model.objects.get(pk=pk) )
def delete_with_related_task(related_instances_data, app_label, object_name, instance_id): for data in related_instances_data: instance = _instance(**data) registry.update(instance) model = apps.get_model(app_label, object_name) registry_proxy = ProxyDocumentRegistry(registry) registry_proxy.delete_documents_by_model_and_id(model, instance_id, raise_on_error=False) return { 'related_instances_data': related_instances_data, 'app': app_label, 'model': object_name, 'instance_id': instance_id }
def delete_document(sender, **kwargs): app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] # print(':::::::::::::::::::::::::::::::::::::',kwargs['instance']) if app_label == 'twit': # If it is `books.Publisher` that is being updated. if model_name == 'company': instances = instance.company.all() for _instance in instances: registry.update(_instance)
def update_application_document(sender, **kwargs): app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs["instance"] """ To keep the index fresh we need to update them whenever the underlying data is updated. The immediate attributes of the index are handled by django_elasticsearch_dsl but additional changes are required to update the related models. The registry update code requires model corresponding to the index which is BaseApplication in our case. We intercept the signals and update the index. """ if issubclass(sender, BaseApplication): registry.update(instance.baseapplication) try: if app_label == "cases" and model_name == "caseassignment": registry.update(instance.case.baseapplication) elif app_label == "cases" and model_name == "case": registry.update(instance.baseapplication) elif app_label == "goods" and model_name == "good": for good in instance.goods_on_application.all(): registry.update(good.application) elif app_label == "parties" and model_name == "party": for party in instance.parties_on_application.all(): registry.update(party.application) elif app_label == "organisations" and model_name == "organisation": for case in instance.cases.all(): registry.update(case.baseapplication) except ObjectDoesNotExist: pass
def delete_document(sender, **kwargs): app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'products': if model_name == 'Category': instances = instance.books.all() for _instance in instances: registry.update(_instance) # registry.delete(_instance, raise_on_error=False) if model_name == 'Product': instances = instance.books.all() for _instance in instances: registry.update(_instance)
def update_document(sender, **kwargs): """Update document on added/changed records. Update Book document index if related `books.Publisher` (`publisher`), `books.Author` (`authors`), `books.Tag` (`tags`) fields have been updated in the database. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] # print(':::::::::::::::::::::::::::::::::::::',kwargs['instance']) if app_label == 'twit': # If it is `books.Publisher` that is being updated. if model_name == 'company': instances = instance.company.all() for _instance in instances: registry.update(_instance)
def update_document(sender, **kwargs): """Update document on added/changed records. Updates index if fields exercise_title or related muscle groups is updated """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'feed': if model_name == 'exercise': instances = instance.exercises.all() for _instance in instances: print(_instance) registry.update(_instance) if model_name == 'muscleGroup': instances = instance.exercises.all() for _instance in instances: registry.update(_instance)
def update_document(sender, instance, **kwargs): model_name = sender._meta.model_name if model_name == "propertyrules": registry.update(instance.property) if model_name == "propertyamenities": registry.update(instance.property) if model_name == "propertyimage": registry.update(instance.property) if model_name == "propertyaddress": registry.update(instance.property)
def delete_document(sender, **kwargs): """ Update document on deleted records. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'library': if model_name == 'person': instances = instance.books.all() for _instance in instances: registry.update(_instance) # registry.delete(_instance, raise_on_error=False) if model_name == 'genre': instances = instance.books.all() for _instance in instances: registry.update(_instance) # registry.delete(_instance, raise_on_error=False)
def update_document(sender, **kwargs): """ Update document on added/changed records. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'news': # If it is `news.stock` that is being updated. if model_name == 'stock': instances = instance.news.all() for _instance in instances: registry.update(_instance) # If it is `news.Author` that is being updated. if model_name == 'author': instances = instance.news.all() for _instance in instances: registry.update(_instance)
def update_document(sender, **kwargs): """ Update document on added/changed records. Update Movie document index if related `library.Person`, `library.Genre` fields have been updated in the database. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'library': if model_name == 'person': instances = instance.movies.all() for _instance in instances: registry.update(_instance) if model_name == 'genre': instances = instance.movies.all() for _instance in instances: registry.update(_instance)
def update_document(sender, **kwargs): """Update document on added/changed records. Update Review document index if related `Category` (`category`), `Biz` (`biz`), High Category ('high_category)) fields have been updated in the database. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'businesses': # If it is `businesses.Biz` that is being updated. if model_name == 'biz': instances = instance.businesses.all() for _instance in instances: registry.update(_instance) # If it is `businesses.Categories` that is being updated. if model_name == 'categories': instances = instance.businesses.all() for _instance in instances: registry.update(_instance) # If it is `businesses.HighCategories` that is being updated. if model_name == 'highcategories': instances = instance.businesses.all() for _instance in instances: registry.update(_instance)
def update_document(sender, **kwargs): """Update document on added/changed records. Update Product document index if related `Product.Category` (`Category`) fields have been updated in the database. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'products': # If it is `books.Publisher` that is being updated. if model_name == 'Category': instances = instance.books.all() for _instance in instances: registry.update(_instance) # If it is `books.Author` that is being updated. if model_name == 'Product': instances = instance.books.all() for _instance in instances: registry.update(_instance)
def setUp(self): super().setUp() self.log = QALogs.objects.create( id=2, knowledge_base=self.knowledge_base_1, question="t2est", answer="te123st", language=self.context_1.language, confidence=0.0505176697224809, user_agent="python-requests/2.20.1", from_backend=True, nlp_log=json.dumps({ "answers": [ { "text": "bias123es", "confidence": 0.9994810819625854 }, { "text": "dou1123btes", "confidence": 0.039212167263031006 }, { "text": "negat123ivees", "confidence": 0.0 }, { "text": "affir132mativees", "confidence": 0.0 }, ], "id": 1, }), user=self.owner, ) requests.delete( f"{settings.ELASTICSEARCH_DSL['default']['hosts']}/_data_stream/{REPOSITORYQANLPLOG_INDEX_NAME}" ) registry.update(self.log)
def update_document(sender, **kwargs): """Update document on added/changed records. Update Books document index if related `books.Author` (`authors`), `books.Recipe` (`recipes`) fields have been updated in the database. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'recipe': # If it is `recipes.Author` that is being updated. if model_name == 'author': instances = instance.books.all() for _instance in instances: registry.update(_instance) # If it is `books.Recipe` that is being updated. if model_name == 'recipe': instances = instance.books.all() for _instance in instances: registry.update(_instance)
def delete_document(sender, **kwargs): """ Update document on deleted records. """ app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'news': # If it is `news.stock` that is being updated. if model_name == 'stock': instances = instance.news.all() for _instance in instances: registry.update(_instance) registry.delete(_instance, raise_on_error=False) # If it is `books.Author` that is being updated. if model_name == 'author': instances = instance.news.all() for _instance in instances: registry.update(_instance) registry.delete(_instance, raise_on_error=False)
def update_document(sender, **kwargs): """Update address document on added/changed records.""" app_label = sender._meta.app_label model_name = sender._meta.model_name instance = kwargs['instance'] if app_label == 'search': if model_name == 'city': instances = instance.address.all() for _instance in instances: registry.update(_instance) if model_name == 'country': instances = instance.address.all() for _instance in instances: registry.update(_instance) if model_name == 'continent': instances = instance.address.all() for _instance in instances: registry.update(_instance)
def update_elastic_registry(post): registry.update(post)
def add_to_ingrs_index(instance): registry.update(instance)
def handle_save(pk, app_label, model_name): sender = apps.get_model(app_label, model_name) instance = sender.objects.get(pk=pk) registry.update(instance) registry.update_related(instance)
def __handle_save(instance): registry.update(instance) registry.update_related(instance)
def update_elastic_registry(user_id): Author = apps.get_model('user.Author') user_author = Author.objects.get(user_id=user_id) registry.update(user_author)
def handle_save_task(pk, app_label, model_name): instance = apps.get_model(app_label, model_name).objects.get(pk=pk) registry.update(instance) registry.update_related(instance)