Exemplo n.º 1
0
 def connect(self,
             signal: ModelSignal,
             receiver: Callable = default_receiver,
             model_class: Optional[Type[models.Model]] = None) -> None:
     """
     Connects signal with all related models to any existing active
     resource.
     """
     model_classes = [model_class] if model_class else self.related_models()
     for model_class in model_classes:
         signal.connect(receiver, sender=model_class)
         logger.info(
             f'Signal {signal}: {model_class} -> {default_receiver}')
Exemplo n.º 2
0
def after_save_instance_handler(sender, **kwargs: ModelSignal):
    if "created" in kwargs.keys():
        created: bool = kwargs["created"]
    else:
        created: bool = False

    if isinstance(kwargs["instance"], Message):
        message: Message = kwargs["instance"]

        if message.instant_send:
            async_to_sync(get_channel_layer().group_send)(
                "chat_group",
                {
                    "type": "chat_message",
                    "message": message.to_json(created=created)
                },
            )

    if isinstance(kwargs["instance"], Node):
        node_update: Node = kwargs["instance"]

        async_to_sync(get_channel_layer().group_send)(
            "chat_group",
            {
                "type": "chat_message",
                "message": node_update.to_json(created=created)
            },
        )
Exemplo n.º 3
0
 def disconnect(
     self,
     signal: ModelSignal,
     receiver: Callable = default_receiver,
     model_class: Optional[Type[models.Model]] = None
 ) -> Dict[Type[models.Model], bool]:
     """
     Disconnects signal with all related models to any existing active
     resource.
     """
     model_classes = [model_class] if model_class else self.related_models()
     return {
         model_class: signal.disconnect(receiver, sender=model_class)
         for model_class in model_classes
     }
Exemplo n.º 4
0
from django.db.models.signals import ModelSignal

expired = ModelSignal(providing_args=["instance"], use_caching=True)

Exemplo n.º 5
0
from django.db.models.signals import ModelSignal

pre_softdelete = ModelSignal(use_caching=True)
post_softdelete = ModelSignal(use_caching=True)
post_undelete = ModelSignal(use_caching=True)
Exemplo n.º 6
0
# -*- coding: utf-8 -*-
# author:CY
# datetime:2020/7/14 20:18
from django.db.models.signals import ModelSignal

pre_ud_save = ModelSignal(providing_args=["sender", "queryset", 'request'],
                          use_caching=True)
aft_ud_save = ModelSignal(providing_args=["sender", "queryset", 'request'],
                          use_caching=True)
Exemplo n.º 7
0
from django.db.models.signals import ModelSignal

# Behaves like Djangos normal pre-/post_save signals signals with the
# added arguments ``target`` and ``position`` that matches those of
# ``move_to``.
# If the signal is called from ``save`` it'll not be pass position.

node_moved = ModelSignal(providing_args=[
    'instance',
    'target',
    'position'
])
Exemplo n.º 8
0
from django.db.models.signals import ModelSignal

data_refreshed = ModelSignal()
from django.db.models.signals import ModelSignal

authenticated_pre_save = ModelSignal(
    providing_args=["instance", "raw", "using", "update_fields", "request"],
    use_caching=True)
authenticated_post_save = ModelSignal(providing_args=[
    "instance", "raw", "created", "using", "update_fields", "request"
],
                                      use_caching=True)
authenticated_save = authenticated_post_save
authenticated_pre_delete = ModelSignal(
    providing_args=["instance", "using", "request"], use_caching=True)
authenticated_post_delete = ModelSignal(
    providing_args=["instance", "using", "request"], use_caching=True)
authenticated_delete = authenticated_pre_delete
Exemplo n.º 10
0
from django.db.models.signals import ModelSignal

post_softdelete = ModelSignal(providing_args=["instance", "using"],
                              use_caching=True)
post_softcreate = ModelSignal(providing_args=["instance", "using"],
                              use_caching=True)
Exemplo n.º 11
0
from django.db.models.signals import ModelSignal

pre_softdelete = ModelSignal()
post_softdelete = ModelSignal()
Exemplo n.º 12
0
from django.template.defaultfilters import default

logger = logging.getLogger(__name__)


def content_file_name(instance, filename):
    return 'upload/{0}/{1}/'.format(instance.author, filename)


def profile_file_name(instance, filename):
    return 'upload/{0}/{1}/'.format(instance.username, filename)


from django.db.models.signals import ModelSignal

pre_bulk_update = ModelSignal(use_caching=True)
post_bulk_update = ModelSignal(use_caching=True)


class UpdateManager(models.QuerySet):
    """
    updateの前後でSignalを定義。
    """
    def update(self, **kwargs):
        pre_bulk_update.send(sender=self.model,
                             queryset=self,
                             update_kwargs=kwargs)
        res = super(UpdateManager, self).update(**kwargs)
        post_bulk_update.send(sender=self.model,
                              queryset=self,
                              update_kwargs=kwargs)
Exemplo n.º 13
0
from django.db.models.signals import ModelSignal

pre_safe_delete = ModelSignal(providing_args=["instance", "using"],
                              use_caching=True)
post_safe_delete = ModelSignal(providing_args=["instance", "using"],
                               use_caching=True)
# -*- coding: utf-8 -*-
# ++ This file `signals.py` is generated at 2/15/17 7:52 PM ++
from django.db.models.signals import ModelSignal

__author__ = 'Md Nazrul Islam<*****@*****.**>'

queryset_update = ModelSignal(providing_args=["queryset", "update_kwargs"],
                              use_caching=True)
Exemplo n.º 15
0
from django.dispatch import receiver
from notifications.signals import notify
from django.db.models.signals import post_save 
from django.db.models.signals import ModelSignal
from django.conf import settings

social_request_accepted = ModelSignal(providing_args=['instance',])
social_request_rejected = ModelSignal(providing_args=['instance',])


@receiver(post_save, sender='marathon.SocialRequest')
def generate_notification(sender, created, instance,  **kwargs):
  if created: 
    notify.send(
      instance.by.user,
      recipient=instance.to.user,
      verb='request',
      description=instance.tile,
      target=instance
      )

@receiver(social_request_rejected, sender='marathon.SocialRequest')
@receiver(social_request_accepted, sender='marathon.SocialRequest')
def mark_disabled(sender, instance, **kwargs):
  if instance.label in settings.MARK_DISABLED:
    same_type_requests = instance.__class__.objects.filter(
      label=instance.label,
      status=instance.__class__.PENDING,
      to=instance.to,
      data=instance.data,
    ).exclude(pk=instance.pk)
Exemplo n.º 16
0
from mezzanine.core.models import CONTENT_STATUS_PUBLISHED

from html2text import html2text

from happystamp.util import generate_key
from happystamp.util import generate_form
from happystamp.util import generate_reward_form

from happystamp.util import app_sticker_template
from happystamp.util import redeem_card_template
from happystamp.util import reward_card_template

from happystamp.gcm import GCMMessage
from happystamp.gcm import post_push

new_customer = ModelSignal(providing_args=["instance"])


def upload_directory_path(instance, filename):
    return 'user_{0}/{1}'.format(instance.user.id, filename)


###############################################################################
#                              Customer                                       #
###############################################################################
class mCustomer(User):
    class Meta:
        verbose_name = _("Customer")
        verbose_name_plural = _("My Customers")
        proxy = True
Exemplo n.º 17
0
from django.db.models.signals import ModelSignal, post_save
from django.dispatch import receiver

from libs.core.cms.api.configs import CMSCoreConfig
from webdjango.exceptions import BadRequest
from webdjango.signals.CoreSignals import (config_group_register,
                                           config_register)
from webdjango.utils.JsonLogic import jsonLogic

from .models.Form import FormSubmitted
from .models.Page import Page
from .models.Menu import MenuItem

from django.core.cache import cache

pre_get_page = ModelSignal(providing_args=["request", "args", "kwargs"],
                           use_caching=True)
post_get_page = ModelSignal(
    providing_args=["instance", "request", "args", "kwargs"], use_caching=True)

form_action_triggered = django.dispatch.Signal(
    providing_args=["instance", "formSubmitted"])


@receiver(config_register)
def register_configs(*args, **kwargs):
    return CMSCoreConfig.INPUTS


@receiver(config_group_register)
def register_config_group(*args, **kwargs):
    return CMSCoreConfig.GROUP
from django.db.models.signals import ModelSignal

tenant_prepared = ModelSignal(providing_args=["tenant"])
Exemplo n.º 19
0
    set_auth_groups_collection_permissions,
    set_auth_groups_page_permissions,
    PAGE_AUTH_GROUP_TYPES,
    MODERATORS_PAGE_PERMISSIONS,
    EDITORS_PAGE_PERMISSIONS,
    COMMON_COLLECTION_NAME,
    MODERATORS_COLLECTION_PERMISSIONS,
    EDITORS_COLLECTION_PERMISSIONS,
    get_auth_groups,
    set_auth_groups_wagtailadmin_access,
)
from .models import LocalGroup, LocalGroupPage, HomeSubPage, HomePage

# Custom Signals

local_group_create = ModelSignal(providing_args=["instance"])
local_group_name_change = ModelSignal(
    providing_args=["instance", "old_name", "new_name"])

# LocalGroup


@receiver(
    local_group_name_change,
    sender=LocalGroup,
    dispatch_uid="update_pages_auth_group_names_once",
)
def update_pages_auth_group_names(sender,
                                  instance=None,
                                  created=False,
                                  **kwargs):
Exemplo n.º 20
0
from django.db.models.signals import ModelSignal

# Behaves like Djangos normal pre-/post_save signals signals with the
# added arguments ``target`` and ``position`` that matches those of
# ``move_to``.
# If the signal is called from ``save`` it'll not be pass position.

node_moved = ModelSignal()
Exemplo n.º 21
0
from django.db.models.signals import ModelSignal
from core.exceptions import ApplicationValidationError

model_validation = ModelSignal(
    providing_args=["instance", "raw", "using", "update_fields"], use_caching=True
)


class ModelValidationMixin:
    def clean(self):
        model_validation.send(sender=self.__class__, instance=self)


def validate_fields_with_abilities(ability, data, **kwargs):
    for field, action in kwargs.items():
        if field in data and not ability.can(action, data[field]):
            raise ApplicationValidationError(
                {field: [f"Cannot {action} {field} {data[field]}"]}
            )
Exemplo n.º 22
0
from django.db.models.signals import ModelSignal


# These signals are sent when model instances are created in bulk
pre_bulk_create = ModelSignal(providing_args=['instances'])
post_bulk_create = ModelSignal(providing_args=['instances'])


# These signals are sent when a model is updated homogeneously (i.e.: queryset.update(field=value)
pre_update = ModelSignal(providing_args=['instances'])
post_update = ModelSignal(providing_args=['instances'])


# These signals are sent when a model's fields are updated heterogeously (i.e.: queryset.update_fields(...))
pre_update_fields = ModelSignal(providing_args=[
    'instances',
    'field_names',
    'field_defaults',
    'batch_size'
])

post_update_fields = ModelSignal(providing_args=[
    'instances',
    'queryset',
    'field_names',
    'field_defaults',
    'batch_size',
    'n'
])