Ejemplo n.º 1
0
from django.core.signals import Signal

deleting = Signal(providing_args=['del_objs', 'rel_objs'])
Ejemplo n.º 2
0
from django.apps import apps
from django.contrib.auth.signals import user_logged_in, user_logged_out
from django.contrib.sessions.backends.cache import KEY_PREFIX
from django.core.cache import cache
from django.core.signals import Signal
from django.db.models import Model
from django.db.models.signals import post_save, pre_delete
from django.dispatch import receiver
from django.http.request import HttpRequest
from prometheus_client import Gauge

from authentik.root.monitoring import monitoring_set

# Arguments: user: User, password: str
password_changed = Signal()

GAUGE_MODELS = Gauge("authentik_models", "Count of various objects",
                     ["model_name", "app"])

if TYPE_CHECKING:
    from authentik.core.models import AuthenticatedSession, User


@receiver(monitoring_set)
# pylint: disable=unused-argument
def monitoring_set_models(sender, **kwargs):
    """set models gauges"""
    for model in apps.get_models():
        GAUGE_MODELS.labels(
            model_name=model._meta.model_name,
Ejemplo n.º 3
0
# This file is part of Shuup.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.core.signals import Signal

post_compute_source_lines = Signal(providing_args=["source", "lines"],
                                   use_caching=True)
order_creator_finished = Signal(providing_args=["order", "source"],
                                use_caching=True)
Ejemplo n.º 4
0
from django.core.signals import Signal

user_profile_was_changed = Signal(
    providing_args=['user', 'picture_small', 'full_name'])
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
# @Time  : 2020/8/21 下午11:17
# @Author : 司云中
# @File : signals.py
# @Software: Pycharm

from django.core.signals import Signal

login_user_browser_times = Signal(providing_args=["instance"])  # 每天登录的用户浏览总数统计

user_browser_times = Signal(providing_args=["ip"])  # 每天所有用户的浏览次数

buy_category = Signal(providing_args=["category"])  # 购买商品记录,商品种类记录+1

user_recommend = Signal(providing_args=["category", "instance"])  # 用户推荐记录+1
Ejemplo n.º 6
0
"""p2 signals"""
import hashlib

from django.core.signals import Signal
from django.db.models.signals import post_save, pre_delete, pre_save
from django.dispatch import receiver
from structlog import get_logger

from p2.core import constants
from p2.core.models import Blob
from p2.lib.hash import chunked_hasher_multiple

LOGGER = get_logger()

BLOB_PAYLOAD_UPDATED = Signal(providing_args=['blob'])
BLOB_ACCESS = Signal(providing_args=['status_code', ''])
BLOB_PRE_SAVE = Signal(providing_args=['blob'])
BLOB_POST_SAVE = Signal(providing_args=['blob'])


@receiver(pre_save, sender=Blob)
# pylint: disable=unused-argument
def blob_pre_save(sender, instance, **kwargs):
    """Trigger BLOB_PRE_SAVE"""
    BLOB_PRE_SAVE.send(sender=sender, blob=instance)


@receiver(post_save, sender=Blob)
# pylint: disable=unused-argument
def blob_post_save(sender, instance, **kwargs):
    """Trigger BLOB_POST_SAVE"""
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.core.signals import Signal

# Modifying signals
get_basket_command_handler = Signal(providing_args=["command"],
                                    use_caching=True)

# Completion signals
order_complete_viewed = Signal(providing_args=["order", "request"],
                               use_caching=True)
Ejemplo n.º 8
0
from django.core.signals import Signal

push = Signal(providing_args=["payload"])
tag_push = Signal(providing_args=["payload"])
issue = Signal(providing_args=["payload"])
note = Signal(providing_args=["payload"])
merge_request = Signal(providing_args=["payload"])
wiki_page = Signal(providing_args=["payload"])
pipeline = Signal(providing_args=["payload"])
job = Signal(providing_args=["payload"])
Ejemplo n.º 9
0
# coding: utf-8

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import absolute_import
from __future__ import division
from django.core.signals import Signal

disguise_applied = Signal(providing_args=['original_user', 'new_user'])
disguise_disapplied = Signal(providing_args=['original_user', 'old_user'])
Ejemplo n.º 10
0
from django.shortcuts import render
from django.views import View
from django.http.response import HttpResponse
from django.core.signals import request_finished
from django.dispatch import receiver
from django.core.signals import Signal

mysignal = Signal(providing_args=['info'])


class IndexView(View):
    def get(self, request):
        mysignal.send(sender=self.__class__, info="index_view")
        return HttpResponse("This is home page to show signal's demo ")


def index(request):
    return HttpResponse("This is home page to show signal's demo ")


def handler_request_finish(sender, **kwargs):
    print("the home page is visited ")


mysignal.connect(receiver=handler_request_finish)
Ejemplo n.º 11
0
from datetime import datetime
from dateutil.relativedelta import relativedelta
from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser
from django.core.signals import Signal

user_registrated = Signal(providing_args=['instance'])


def user_registrated_dispatcher(**kwargs):
    send_activation_notification(kwargs['instance'])


user_registrated.connect(user_registrated_dispatcher)

reset_password = Signal(providing_args=['instance'])


def reset_password_dispatcher(**kwargs):
    send_request_reset_password(kwargs['instance'])


reset_password.connect(reset_password_dispatcher)

pay_subscription = Signal(providing_args=['card', 'settings'])


def pay_subscription_dispatcher(**kwargs):
    continue_subscription(card=kwargs['card'], settings=kwargs['settings'])
Ejemplo n.º 12
0
from django.core.signals import Signal

pre_bulk_update = Signal(providing_args=["queryset", "update_kwargs"])
post_bulk_update = Signal(providing_args=["updated_pks", "update_kwargs"])
Ejemplo n.º 13
0
__all__ = [
    'graphs_updated', 'graph_updated', 'resources_updated', 'resource_updated',
    'update_completed'
]


# From http://dougalmatthews.com/2011/10/10/making-django%27s-signals-asynchronous-with-celery/
# Prevents celery trying to pickle Signal.lock.
# Warning. Monkey patch.
def reducer(self):
    return (Signal, (self.providing_args, ))


Signal.__reduce__ = reducer

graphs_updated = Signal(providing_args=['store', 'graphs', 'when'])
graph_updated = Signal(providing_args=['store', 'graph', 'when'])

resources_updated = Signal(providing_args=['store', 'uris', 'when'])
resource_updated = Signal(providing_args=['store', 'uri', 'when'])

update_completed = Signal(
    providing_args=['update_definition', 'store_graphs', 'when'])


@receiver(graphs_updated)
def _graphs_updated(sender, store, graphs, when, **kwargs):
    for graph in graphs:
        graph_updated.send(sender,
                           store=store,
                           graph=graph,
Ejemplo n.º 14
0
# -*- coding: utf-8 -*-
#
# django-agpl -- tools to aid releasing Django projects under the AGPL
# Copyright (C) 2008, 2009, 2016 Chris Lamb <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from django.core.signals import Signal

project_downloaded = Signal()
Ejemplo n.º 15
0
from datetime import datetime

from django.core.signals import Signal
from django.dispatch import receiver
from pytz import UTC

from .models import Base, Log

# signal for update base doc visualization
visualised_base_signal = Signal(providing_args=["instance"])
updated_base_signal = Signal(providing_args=["instance", "new_data"])


@receiver(visualised_base_signal, sender=Base)
def handle_visualised_base(sender, **kwargs):
    base = kwargs['instance']
    timestamp = datetime.now(tz=UTC)

    log = Log(pk=base.pk,
              operation='visualisation',
              timestamp=timestamp,
              text='[{0}] Base {1} ({2},{3}) visualised.'.format(
                  timestamp, base.pk, base.value, base.text))
    log.save()


@receiver(updated_base_signal, sender=Base)
def handle_updated_base(sender, **kwargs):
    base = kwargs['instance']
    new_data = kwargs['new_data']
    timestamp = datetime.now(tz=UTC)
Ejemplo n.º 16
0
def lazy_class_prepared(app_label, object_name, callback):
    """
    Lazily execute a callback upon model class preparation.
    """
    model = get_model(app_label,
                      object_name.lower(),
                      seed_cache=False,
                      only_installed=False)
    if model:
        callback(model)
    else:

        def receiver(sender, **kwargs):
            opts = sender._meta
            if (opts.app_label == app_label
                    and opts.object_name == object_name):
                class_prepared.disconnect(receiver)
                callback(sender)

        class_prepared.connect(receiver, weak=False)


pre_schema_creation = Signal(providing_args=['tenant', 'using'])
post_schema_creation = Signal(providing_args=['tenant', 'using'])

pre_models_creation = Signal(providing_args=['tenant', 'using'])
post_models_creation = Signal(providing_args=['tenant', 'using'])

pre_schema_deletion = Signal(providing_args=['tenant', 'using'])
post_schema_deletion = Signal(providing_args=['tenant', 'using'])
Ejemplo n.º 17
0
from django.core.signals import Signal

ip_assigned = Signal()
ip_unassigned = Signal()

VPNSender = object()
Ejemplo n.º 18
0
# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2021, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from django.core.signals import Signal

# Modifying signals
from shuup.core.signals import get_basket_command_handler  # noqa

# Completion signals
order_complete_viewed = Signal(providing_args=["order", "request"],
                               use_caching=True)

checkout_complete = Signal(providing_args=["request", "user", "order"],
                           use_caching=True)
login_allowed = Signal(providing_args=["request", "user"], use_caching=True)
person_registration_save = Signal(
    providing_args=["request", "user", "contact"], use_caching=True)
company_registration_save = Signal(
    providing_args=["request", "user", "company"], use_caching=True)
Ejemplo n.º 19
0

@receiver([post_save, post_delete], sender=Article, dispatch_uid=2)
def invalidate_by_Article_boats_app(sender, instance, **kwargs):
    try:
        cache_key = "boat_detail_view" + str(instance.foreignkey_to_boat_id)
        cache.delete(cache_key)
    except AttributeError:
        pass


@receiver(post_revision_commit, sender=Version)
def invalidate_by_Version(sender, instance, **kwargs):
    cache_key = "boat_detail_view" + instance.object_id
    cache.delete(cache_key)





#---------------------------------------------------------------------------------------------------
user_registrated = Signal(providing_args=["instance"])
"""Сигнал user_registrated #573  431  437"""


def user_registrated_dispatcher(sender, **kwargs):
    send_activation_notofication(kwargs["instance"])


user_registrated.connect(user_registrated_dispatcher)
Ejemplo n.º 20
0
"""authentik prompt stage signals"""
from django.core.signals import Signal

# Arguments: password: str, plan_context: dict[str, Any]
password_validate = Signal()
Ejemplo n.º 21
0
# -*- coding: utf-8 -*-
# This file is part of Shoop.
#
# Copyright (c) 2012-2016, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.core.signals import Signal

# Modifying signals
get_basket_command_handler = Signal(providing_args=["command"],
                                    use_caching=True)
get_method_validation_errors = Signal(providing_args=["method", "source"],
                                      use_caching=True)

# Completion signals
order_complete_viewed = Signal(providing_args=["order", "request"],
                               use_caching=True)
Ejemplo n.º 22
0
# -*- coding: utf-8 -*-
from django.core.signals import Signal

__all__ = [
    'before_test',
    'after_test',
]

before_test = Signal()
after_test = Signal()
Ejemplo n.º 23
0
"""authentik user_write signals"""
from django.core.signals import Signal

# Arguments: request: HttpRequest, user: User, data: dict[str, Any], created: bool
user_write = Signal()
Ejemplo n.º 24
0
"""Web API signals."""

from __future__ import unicode_literals

from django.core.signals import Signal


#: A signal indicating a WebAPI token has been created.
#:
#: Args:
#:     instance (djblets.webapi.models.WebAPIToken):
#:         The created instance.
#:
#:     auto_generated (bool):
#:         Whether or not the token was automatically generated.
webapi_token_created = Signal(providing_args=['instance', 'auto_generated'])


#: A signal indicating a WebAPI token has been updated.
#:
#: Args:
#:     instance (djblets.webapi.models.WebAPIToken):
#:         The updated instance.
webapi_token_updated = Signal(providing_args=['instance'])
Ejemplo n.º 25
0
from django.core.signals import Signal

notify_user = Signal(providing_args=['user', 'notice_type', 'context'])
Ejemplo n.º 26
0
# This file is part of Shoop.
#
# Copyright (c) 2012-2015, Shoop Ltd. All rights reserved.
#
# This source code is licensed under the AGPLv3 license found in the
# LICENSE file in the root directory of this source tree.
from django.core.signals import Signal

post_compute_source_lines = Signal(providing_args=["source", "lines"],
                                   use_caching=True)
Ejemplo n.º 27
0
"""authentik invitation signals"""
from django.core.signals import Signal

# Arguments: request: HttpRequest, invitation: Invitation
invitation_used = Signal()
from django.core.signals import Signal

process_finished = Signal(
    providing_args=['result_text', 'result_data', 'files', 'profile', 'logs'])
process_aborted = Signal(
    providing_args=['error_text', 'result_data', 'profile', 'logs'])
Ejemplo n.º 29
0
# -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2018, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from django.core.signals import Signal

# Modifying signals
from shuup.core.signals import get_basket_command_handler  # noqa

# Completion signals
order_complete_viewed = Signal(providing_args=["order", "request"], use_caching=True)
Ejemplo n.º 30
0
import decimal
import json
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from django.core.signals import Signal
from codeschool.jinja.filters import markdown
from codeschool import models
from codeschool.utils import md5hash
from cs_core.models.activity import Response


#: This signal is emitted when a response item finishes its autograde() method
#: successfully and sets the ResponseItem status to STATUS_DONE.
autograde_signal = Signal(providing_args=['response_item', 'given_grade'])


class ResponseItem(models.CopyMixin,
                   models.TimeStampedStatusModel,
                   models.PolymorphicModel):
    """
    Represents a student's response to some activity.

    Response objects have 4 different states:

    pending:
        The response has been sent, but was not graded. Grading can be manual or
        automatic, depending on the activity.
    waiting:
        Waiting for manual feedback.
    incomplete:
        For long-term activities, this tells that the student started a response