from django import forms
from django_select2.forms import ModelSelect2MultipleWidget
from guardian.shortcuts import get_objects_for_user
from catalogues.models import Dataset
from catalogues.tools import get_dataset_for_anonymoususer


class SelectDatasetForm(forms.Form):

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(SelectDatasetForm, self).__init__(*args, **kwargs)
        datasets = get_objects_for_user(self.request.user,
            'catalogues.change_dataset', Dataset)
        if 'datasets' in self.request.session:
            selected_datasets = [dataset['uuid'] for dataset in self.
                request.session['datasets']]
        else:
            selected_datasets = list(get_dataset_for_anonymoususer().
                values_list('uuid', flat=True))
        print(datasets, selected_datasets)
        self.fields['datasets'] = forms.ModelMultipleChoiceField(initial=
            selected_datasets, queryset=datasets, widget=
            ModelSelect2MultipleWidget(queryset=datasets, search_fields=[
            'name__icontains']))

762196cc9d1e7f4f1f40967f29b6c9298e60340f
<mask token>

<mask token>


class SelectDatasetForm(forms.Form):
    <mask token>

<mask token>


class SelectDatasetForm(forms.Form):

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(SelectDatasetForm, self).__init__(*args, **kwargs)
        datasets = get_objects_for_user(self.request.user,
            'catalogues.change_dataset', Dataset)
        if 'datasets' in self.request.session:
            selected_datasets = [dataset['uuid'] for dataset in self.
                request.session['datasets']]
        else:
            selected_datasets = list(get_dataset_for_anonymoususer().
                values_list('uuid', flat=True))
        print(datasets, selected_datasets)
        self.fields['datasets'] = forms.ModelMultipleChoiceField(initial=
            selected_datasets, queryset=datasets, widget=
            ModelSelect2MultipleWidget(queryset=datasets, search_fields=[
            'name__icontains']))

from django import forms
from django_select2.forms import ModelSelect2MultipleWidget
from guardian.shortcuts import get_objects_for_user
from catalogues.models import Dataset
from catalogues.tools import get_dataset_for_anonymoususer


class SelectDatasetForm(forms.Form):

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(SelectDatasetForm, self).__init__(*args, **kwargs)
        datasets = get_objects_for_user(self.request.user,
            'catalogues.change_dataset', Dataset)
        if 'datasets' in self.request.session:
            selected_datasets = [dataset['uuid'] for dataset in self.
                request.session['datasets']]
        else:
            selected_datasets = list(get_dataset_for_anonymoususer().
                values_list('uuid', flat=True))
        print(datasets, selected_datasets)
        self.fields['datasets'] = forms.ModelMultipleChoiceField(initial=
            selected_datasets, queryset=datasets, widget=
            ModelSelect2MultipleWidget(queryset=datasets, search_fields=[
            'name__icontains']))
