示例#1
0
def obj_perms(obj):

    t = '<span class="perm-%s">%s</span>'

    if obj.allow_anonymous_view:
        value = t % ('public','Public')
    elif obj.allow_user_view:
        value = t % ('users','Users')
    elif obj.allow_member_view:
        value = t % ('members','Members')
    elif groups_with_perms(obj):
        value = t % ('groups','Groups')
    else:
        value = t % ('private','Private')

    return value
示例#2
0
    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)
        else:
            self.user = None
        super(TendenciBaseForm, self).__init__(*args, **kwargs)

        # needs to update the choices on every pull
        # in case groups get added
        if 'group_perms' in self.fields:
            self.fields['group_perms'].choices = group_choices()

        if 'instance' in kwargs:
            instance = kwargs['instance']
            if 'group_perms' in self.fields:
                self.fields['group_perms'].initial = groups_with_perms(instance)
            if 'user_perms' in self.fields:
                self.fields['user_perms'].initial = user_perm_bits(instance)
            if 'member_perms' in self.fields:
                self.fields['member_perms'].initial = member_perm_bits(instance)