Beispiel #1
0
    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'])
Beispiel #2
0
    def ready(self):
        from .signals import change_staff_perms, set_default_perms_to_user, set_perms_to_staff
        User = get_user_model()

        post_save_changed.connect(change_staff_perms,
                                  sender=User,
                                  fields=('is_staff', ))
        post_save.connect(set_default_perms_to_user, sender=User)
        post_save.connect(set_perms_to_staff, sender=User)
        return super().ready()
Beispiel #3
0
    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)
Beispiel #4
0
    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'])