def test_modelchoicefield_objects_assignment(self):
        field = CachedModelChoiceField(objects=self.cached_list)
        field2 = CachedModelChoiceField(objects=self.cached_list[:2])
        field.objects = self.cached_list[:2]

        self.assertEqual(field.objects, field2.objects)
        self.assertEqual(field.choices, field2.choices)
    def test_modelchoicefield_objects_arg(self):
        '''
        Test, how the field accepts different types of ``objects`` argument.
        '''
        as_list = CachedModelChoiceField(objects=lambda: self.cached_list)
        as_iterable = CachedModelChoiceField(
            objects=lambda: iter(self.cached_list))
        list_of_tuples = [(x.pk, x) for x in self.cached_list]
        as_list_of_tuples = CachedModelChoiceField(
            objects=lambda: list_of_tuples)
        as_dict = CachedModelChoiceField(objects=lambda: dict(list_of_tuples))

        choices_without_empty_label = as_list.choices[:]
        if as_list.empty_label is not None:
            choices_without_empty_label.pop(0)

        # make sure all of the ``choices`` attrs are the same
        self.assertTrue(as_list.choices == as_iterable.choices ==
                        as_list_of_tuples.choices == as_dict.choices)

        # same for ``objects``
        self.assertTrue(as_list.objects == as_iterable.objects ==
                        as_list_of_tuples.objects == as_dict.objects)

        # ``objects`` should be a dict as ``{smart_text(pk1): obj1, ...}``
        self.assertEqual(set(as_list.objects.keys()),
                         set(smart_text(x.pk) for x in self.cached_list))
        self.assertEqual(set(as_list.objects.values()), set(self.cached_list))

        # ``choices`` should be a list as ``[(smart_text(pk1), smart_text(obj1)), ...]``
        self.assertEqual(choices_without_empty_label,
                         [(smart_text(x.pk), smart_text(x))
                          for x in self.cached_list])
    def test_modelchoicefield_objects_assignment(self):
        field = CachedModelChoiceField(objects=self.cached_list)
        field2 = CachedModelChoiceField(objects=self.cached_list[:2])
        field.objects = self.cached_list[:2]

        self.assertEqual(field.objects, field2.objects)
        self.assertEqual(field.choices, field2.choices)
Esempio n. 4
0
class PVEItemAnnotationForm(forms.Form):
    item_id = forms.IntegerField(label="item_id")
    status = CachedModelChoiceField(
        objects=lambda: CommentStatus.objects.all(), required=False)
    annotation = forms.CharField(label="annotation",
                                 max_length=1000,
                                 widget=forms.Textarea,
                                 required=False)
    kostenConsequenties = forms.DecimalField(
        label="(Optioneel) Kosten Consequenties", required=False)
Esempio n. 5
0
class VacancyForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(VacancyForm, self).__init__(*args, **kwargs)
        self.fields['specialty'].objects = Specialty.objects.all()

    title = forms.CharField(max_length=50, widget=forms.TextInput(
        attrs=default_attrs
    ), label='Название вакансии')

    salary_min = forms.IntegerField(required=False, widget=forms.NumberInput(
        attrs=default_attrs
    ), label='Зарплата от')

    salary_max = forms.IntegerField(required=False, widget=forms.NumberInput(
        attrs=default_attrs
    ), label='Зарплата до')

    specialty = CachedModelChoiceField(
        widget=forms.Select(attrs={
            'class': 'custom-select mr-sm-2'
        }),
        label='Специализация'
    )

    skills = forms.ModelMultipleChoiceField(
        queryset=Skill.objects.all(),
        widget=autocomplete.ModelSelect2Multiple(
            url='skill-autocomplete',
            attrs={
                'data-minimum-input-length': 1
            }),
        label='Требуемые навыки'
    )

    class Meta:
        model = Vacancy
        fields = (
            'title',
            'specialty',
            'salary_min',
            'salary_max',
            'description',
            'is_remote',
            'skills',
        )
        labels = {
            'is_remote': 'Удаленно',
            'description': 'Описание вакансии',
        }
        widgets = {
            'description': forms.Textarea(attrs={
                'class': 'form-control',
                'rows': '13'
            }),
        }
Esempio n. 6
0
class CommentReplyForm(forms.Form):
    CHOICES = [("True", "Ja"), ("False", "Nee")]

    comment_id = forms.IntegerField(label="comment_id")
    status = CachedModelChoiceField(
        objects=lambda: CommentStatus.objects.all(), required=False)
    annotation = forms.CharField(label="annotation",
                                 max_length=1000,
                                 widget=forms.Textarea,
                                 required=False)
    kostenConsequenties = forms.DecimalField(
        label="(Optioneel) Kosten Consequenties", required=False)
    accept = forms.ChoiceField(choices=CHOICES, required=False)
 class FormSingle(forms.Form):
     obj = CachedModelChoiceField(objects=lambda: self.cached_list,
                                  required=False)
Esempio n. 8
0
class ResumeForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(ResumeForm, self).__init__(*args, **kwargs)
        self.fields['specialty'].objects = Specialty.objects.all()

    name = forms.CharField(max_length=50, widget=forms.TextInput(
        attrs=default_attrs
    ), label='Имя')

    surname = forms.CharField(max_length=50, widget=forms.TextInput(
        attrs=default_attrs
    ), label='Фамилия')

    salary = forms.IntegerField(required=False, widget=forms.NumberInput(
        attrs=default_attrs
    ), label='Ожидаемое вознаграждение')

    specialty = CachedModelChoiceField(
        widget=forms.Select(attrs={
            'class': 'custom-select mr-sm-2'
        }),
        label='Специализация'
    )

    portfolio = forms.CharField(max_length=300, widget=forms.TextInput(
        attrs={
            'class': 'form-control',
            'placeholder': 'http://anylink.github.io'
        }
    ), label='Ссылка на портфолио')

    class Meta:
        model = Resume
        fields = (
            'name',
            'surname',
            'salary',
            'experience',
            'portfolio',
            'institution',
            'status',
            'grade',
            'education',
            'specialty'
        )
        labels = {
            'education': 'Образование',
            'grade': 'Квалификация',
            'status': 'Готовность к работе',
            'institution': 'Учебное заведение',
            'experience': 'Опыт работы',
        }
        widgets = {
            'education': forms.Select(attrs={'class': 'custom-select mr-sm-2'}),
            'grade': forms.Select(attrs={'class': 'custom-select mr-sm-2'}),
            'status': forms.Select(attrs={'class': 'custom-select mr-sm-2'}),

            'experience': forms.Textarea(attrs={
                'class': 'form-control',
                'rows': '4'
            }),
            'institution': forms.Textarea(attrs={
                'class': 'form-control text-uppercase',
                'rows': '4'
            }),
        }