def ready(self): def get_team_in_campaign_manager(campaign_slug): """ This is hacky manager, that enables filter by campaign for chained team field in ChangeTeamView. """ class TeamInCampaignManager(models.Manager): def __init__(self): ret_val = super().__init__() self.model = dpnk_models.Team return ret_val def get_queryset(self): return super().get_queryset().filter(campaign__slug=campaign_slug) return TeamInCampaignManager() from . import models as dpnk_models from fieldsignals import post_save_changed, pre_save_changed from django.conf import settings if not settings.DATABASE_CONFIGURED: return try: slugs = dpnk_models.Campaign.objects.values_list('slug', flat=True) for campaign_slug in slugs: setattr(dpnk_models.Team, 'team_in_campaign_%s' % campaign_slug, get_team_in_campaign_manager(campaign_slug)) setattr(dpnk_models.Team, 'team_in_campaign_testing-campaign', get_team_in_campaign_manager('testing-campaign')) except ProgrammingError: pass post_save_changed.connect(dpnk_models.change_invoice_payments_status, sender=dpnk_models.Invoice, fields=['paid_date']) pre_save_changed.connect(dpnk_models.pre_user_team_changed, sender=dpnk_models.UserAttendance, fields=['team']) post_save_changed.connect(dpnk_models.post_user_team_changed, sender=dpnk_models.UserAttendance, fields=['team'])
def ready(self): # Register custom system checks # See https://docs.djangoproject.com/en/2.2/topics/checks/ # And https://stackoverflow.com/questions/31619635/registering-django-system-checks-in-appconfigs-ready-method/36450374#36450374 import vino.sharekernel.checks # noqa: F401 # Connect field signals with pre_save and post_save models methods # See https://github.com/craigds/django-fieldsignals from fieldsignals import pre_save_changed, post_save_changed # type: ignore for model in self.models.values(): if hasattr(model, 'pre_save'): pre_save_changed.connect(model.pre_save, sender=model) if hasattr(model, 'post_save'): post_save_changed.connect(model.post_save, sender=model)
def ready(self): from . import models as dpnk_models from fieldsignals import post_save_changed, pre_save_changed from django.conf import settings if not settings.DATABASE_CONFIGURED: return post_save_changed.connect(dpnk_models.change_invoice_payments_status, sender=dpnk_models.Invoice, fields=['paid_date']) pre_save_changed.connect(dpnk_models.pre_user_team_changed, sender=dpnk_models.UserAttendance, fields=['team']) post_save_changed.connect(dpnk_models.post_user_team_changed, sender=dpnk_models.UserAttendance, fields=['team'])
def ready(self): from .models import Item, Property, Variant from .signals import on_create_item, on_delete_item, \ on_delete_property, on_delete_variant, \ item_field_changes, property_field_changes, \ variant_field_changes post_save.connect(on_create_item, sender=Item) post_delete.connect(on_delete_property, sender=Property) post_delete.connect(on_delete_variant, sender=Variant) post_delete.connect(on_delete_item, sender=Item) pre_save_changed.connect(item_field_changes, sender=Item) pre_save_changed.connect(variant_field_changes, sender=Variant) pre_save_changed.connect(property_field_changes, sender=Property)
changed_fields) for field, (old, new) in changed_fields.items(): logger.debug("%i: %s changed from %s to %s" % (instance.id or 0, field, old, new)) user = None if get_current_user() and get_current_user().is_authenticated: user = get_current_user() update_finding_status(instance, user, changed_fields) # also get signal when id is set/changed so we can process new findings pre_save_changed.connect(pre_save_finding_status_change, sender=Finding, fields=[ 'id', 'active', 'verfied', 'false_p', 'is_Mitigated', 'mitigated', 'mitigated_by', 'out_of_scope', 'risk_accepted' ]) # pre_save_changed.connect(pre_save_finding_status_change, sender=Finding) # post_save_changed.connect(pre_save_finding_status_change, sender=Finding, fields=['active', 'verfied', 'false_p', 'is_Mitigated', 'mitigated', 'mitigated_by', 'out_of_scope']) def update_finding_status(new_state_finding, user, changed_fields=None): now = timezone.now() is_new_finding = changed_fields and len( changed_fields) == 1 and 'id' in changed_fields # activated # reactivated
def ready(self): from updates.models import print_all_field_changes from fieldsignals import pre_save_changed from updates.models import Instance pre_save_changed.connect(print_all_field_changes, sender=Instance)