Exemplo n.º 1
0
    def save_model(self, request, obj, form, change):
        super(FeatureSubscriptionAdmin,
              self).save_model(request, obj, form, change)
        '''
        #get waffle.flag for feature
            if not exist - create one
            iterate over organization list
                get all users belonging to this organization
                add users to waffle.flag entity users list
                
                - later - on post add / remove of user object, we need to update this list of waffle.flag
        #
        
        '''
        flags = Flag.objects.filter(name=self.feature_name(obj))[:1]
        if flags:
            flag = flags[0]
        else:
            flag = Flag(name=self.feature_name(obj))
            flag.save()

        flag.users.clear()
        user_ids = []
        #         reloaded_feature_subscription = FeatureSubscription.objects.get(id=obj.id)
        #         org_ids = form.cleaned_data.get('organizations')
        org_ids = [
            organization.org_id
            for organization in form.cleaned_data.get('organizations', [])
        ]
        #         org_ids = [organization.org_id for organization in reloaded_feature_subscription.organizations.all()]
        for org_id in org_ids:
            user_profiles = NGOUserProfile.objects.filter(org_id=org_id)
            org_user_ids = [
                user_profile.user_id for user_profile in user_profiles
            ]
            user_ids.extend(org_user_ids)
        for user_id in user_ids:
            flag.users.add(user_id)
Exemplo n.º 2
0
            def _give_me_waffles(*args, **kwargs):
                origvalue = None
                # Avoid circular imports
                from waffle.models import Flag
                try:
                    flag = Flag.objects.filter(name=flagname)[0]
                    origvalue = flag.everyone
                    flag.everyone = flagvalue
                except waffle.Flag.DoesNotExist:
                    flag = Flag(name=flagname, everyone=True)
                flag.save()

                try:
                    return func(*args, **kwargs)
                except Exception:
                    # FIXME: This breaks if saving the flag also
                    # raises an exception, but that really shouldn't
                    # happen in our test suite and if it does, we've
                    # probably got other more serious issues to deal
                    # with.
                    if origvalue is not None:
                        flag.everyone = origvalue
                        flag.save()
                    raise
Exemplo n.º 3
0
            def _give_me_waffles(*args, **kwargs):
                origvalue = None
                # Avoid circular imports
                from waffle.models import Flag
                try:
                    flag = Flag.objects.filter(name=flagname)[0]
                    origvalue = flag.everyone
                    flag.everyone = flagvalue
                except waffle.Flag.DoesNotExist:
                    flag = Flag(name=flagname, everyone=True)
                flag.save()

                try:
                    return func(*args, **kwargs)
                except Exception:
                    # FIXME: This breaks if saving the flag also
                    # raises an exception, but that really shouldn't
                    # happen in our test suite and if it does, we've
                    # probably got other more serious issues to deal
                    # with.
                    if origvalue is not None:
                        flag.everyone = origvalue
                        flag.save()
                    raise
def reverse_func(state, schema):
    flag = Flag(name='ember_support_page', everyone=False)
    flag.save()