Exemple #1
0
    def __init__(self, *args, **kwargs):
        """Initialize TaskForm.

        Filter available choices of Data items.
        """
        if kwargs.has_key('request'):
            request = kwargs.pop('request')
        else:
            request = None

        if kwargs.has_key('default_arg'):
            cur_slug = kwargs.pop('default_arg')
            cur_data = Data.get_object(cur_slug)
        else:
            cur_data = None

        # super needs to be called before to have attribute fields
        super(RepositoryForm, self).__init__(*args, **kwargs)
        if request:
            cv = Data.objects.filter(Q(is_current=True) &
                Q(is_approved=True) &
                (Q(user=request.user) | Q(is_public=True))
            )
            ids = [d.id for d in cv]
            qs = Data.objects.filter(pk__in=ids)
            self.fields['data'].queryset = qs
            self.fields['data_heldback'].queryset = qs
            choices = [(d.id, d.name) for d in qs]
            if cur_data:
                self.fields['data'].choices = [(cur_data.id, cur_data.name)]
            else:
                self.fields['data'].choices = choices
            choices.insert(0, ('', '---------'))
            #choices.append(('', '-----'))
            self.fields['data_heldback'].choices = choices
Exemple #2
0
    def __init__(self, *args, **kwargs):
        """Initialize TaskForm.

        Filter available choices of Data items.
        """
        if kwargs.has_key('request'):
            request = kwargs.pop('request')
        else:
            request = None

        if kwargs.has_key('default_arg'):
            cur_slug = kwargs.pop('default_arg')
            cur_data = Data.get_object(cur_slug)
        else:
            cur_data = None

        # super needs to be called before to have attribute fields
        super(RepositoryForm, self).__init__(*args, **kwargs)
        if request:
            cv = Data.objects.filter(
                Q(is_current=True) & Q(is_approved=True)
                & (Q(user=request.user) | Q(is_public=True)))
            ids = [d.id for d in cv]
            qs = Data.objects.filter(pk__in=ids)
            self.fields['data'].queryset = qs
            self.fields['data_heldback'].queryset = qs
            choices = [(d.id, d.name) for d in qs]
            if cur_data:
                self.fields['data'].choices = [(cur_data.id, cur_data.name)]
            else:
                self.fields['data'].choices = choices
            choices.insert(0, ('', '---------'))
            #choices.append(('', '-----'))
            self.fields['data_heldback'].choices = choices