class PropertyAdminForm(models.ModelForm):
    amenities = models.ModelMultipleChoiceField(
        queryset=AmenityType.objects.all(),
        widget=FilteredSelectMultiple(("amenities"), False),
        label=("Select Amenities."))
    tags = models.ModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           label="Select tags",
                                           widget=FilteredSelectMultiple(
                                               "tags", False))

    class Meta:
        model = Property
        fields = "__all__"

    class Media:
        def __init__(self):
            pass

        css = {'all': "/media/css/widgets.css"}

        js = "/admin/jsi18n/"

    def clean(self):
        cleaned_data = super(PropertyAdminForm, self).clean()

        return cleaned_data
Example #2
0
class CustomerForm(ModelForm):
    services = models.ModelMultipleChoiceField(
        queryset=Service.objects.all(),
        widget=widgets.CheckboxSelectMultiple,
        help_text=_(
            'Select all services this customer will be subscribed to.'))

    class Meta:
        model = Customer
        exclude = ('account', )
        widgets = {
            'address': widgets.Textarea,
        }

    @transaction.commit_on_success
    def save(self, commit=True):
        if not self.instance:
            # We're dealing with a new customer.
            account = Account.objects.create(id=uuid.uuid4().hex)
            customer = super(CustomerForm, self).save(commit=False)
            customer.account = account
            if commit:
                customer.save()
                self.save_m2m()
            # Pop this customer in our queue:
            customer_dict = models.model_to_dict(customer)
            customer_created(customer_dict)
            # Return our brand-new customer:
            return customer
        else:
            return super(CustomerForm, self).save(commit=commit)
Example #3
0
class TeacherEditModelForm(StarkModelForm):
    birthday = Ffields.DateField(
        required=False,
        label='生日',
        widget=Fwidgets.DateInput(attrs={
            'type': 'date',
            'style': 'width: 600px'
        }))
    identity = form_models.ModelChoiceField(
        required=False,
        empty_label=None,
        label='职务',
        queryset=teamodels.Identity.objects.all(),
        widget=Fwidgets.RadioSelect())
    course = form_models.ModelMultipleChoiceField(
        required=False,
        label='所带课程',
        queryset=scmodels.Course.objects.all(),
        widget=Fwidgets.CheckboxSelectMultiple())
    gender = Ffields.ChoiceField(required=False,
                                 label='性别',
                                 choices=((1, '男'), (2, '女')),
                                 widget=Fwidgets.RadioSelect())

    class Meta:
        model = teamodels.TeacherInfo
        fields = ('last_name', 'first_name', 'gender', 'birthday', 'telephone',
                  'wechat', 'school', 'identity', 'course')
        widgets = {
            "last_name": Fwidgets.TextInput(attrs={'style': 'width: 600px'}),
            "first_name": Fwidgets.TextInput(attrs={'style': 'width: 600px'}),
            'wechat': Fwidgets.TextInput(attrs={'style': 'width: 600px'}),
            'telephone': Fwidgets.TextInput(attrs={'style': 'width: 600px'}),
            'school': Fwidgets.Select(attrs={'style': 'width: 600px'}),
        }
        error_messages = {
            "last_name": {
                "required": "请输入老师姓"
            },
            "first_name": {
                "required": "请输入老师名"
            },
            "gender": {
                "required": "请选择性别"
            },
        }
        labels = {
            'last_name': '老师姓(必填)',
            'first_name': '老师名(必填)',
        }
class PostCategoryIndexForm(BaseUrlForm):
    categories = models.ModelMultipleChoiceField(
        required=True, queryset=Category.objects.all(), widget=MpttTreeWidget)

    def get_path(self):
        paths = []
        for category in self.cleaned_data['categories']:
            ancestors = list(category.get_ancestors()) + [
                category,
            ]
            path = '/'.join([force_unicode(i.slug) for i in ancestors])
            paths.append(path)
        return ",".join([path for path in paths])

    def submit(self):
        url = "'%s' '%s'" % (self.Meta.url_name, self.get_path())
        return url

    class Meta:
        verbose_name = 'List by category'
        url_name = 'post_archive_index'
Example #5
0
class UserForm(forms.Form):
    username = fields.CharField(label='用户名')
    email = fields.EmailField(label='邮箱')

    user_type1 = fields.ChoiceField(
        choices=models.UserType.objects.values_list('id', 'name'))

    user_type2 = models_fields.ModelChoiceField(
        queryset=models.UserType.objects.all(),
        empty_label='请选择用户类型',
        to_field_name="id",
        limit_choices_to={'id': 1})

    user_type3 = models_fields.ModelMultipleChoiceField(
        queryset=models.UserType.objects.all(),
        to_field_name="id",
        limit_choices_to={'id': 1})

    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['user_type1'].widget.choices = models.UserType.objects.all(
        ).values_list('id', 'name')

    def clean_username(self):
        #
        value = self.cleaned_data['username']
        if value == 'root':
            return value
        else:
            raise ValidationError('你不是我的...')

    def clean(self):
        v1 = self.cleaned_data['username']
        v2 = self.cleaned_data['email']
        if v1 == "root" and v2 == "*****@*****.**":
            pass
        else:
            raise ValidationError('用户名或邮箱错误!!!')

        return self.cleaned_data
Example #6
0
class AuthorForm(forms.Form):
    a_name = forms.CharField(max_length=64, label='作者的名字')
    # 下拉框多选
    books = form_model.ModelMultipleChoiceField(
        queryset=models.Book.objects.all())
Example #7
0
class TeacherModelForm(StarkModelForm):
    birthday = Ffields.DateField(
        required=False,
        label='生日',
        widget=Fwidgets.DateInput(attrs={
            'class': 'form-control',
            'type': 'date',
            'style': 'width: 600px'
        }))
    identity = form_models.ModelChoiceField(
        initial=1,
        empty_label=None,
        label='职务',
        queryset=teamodels.Identity.objects.all(),
        widget=Fwidgets.RadioSelect())
    course = form_models.ModelMultipleChoiceField(
        required=False,
        label='所带课程',
        queryset=scmodels.Course.objects.all(),
        widget=Fwidgets.CheckboxSelectMultiple())
    gender = Ffields.ChoiceField(required=False,
                                 label='性别',
                                 choices=((1, '男'), (2, '女')),
                                 widget=Fwidgets.RadioSelect())

    def __init__(self, *args, **kwargs):
        school_id = kwargs.pop('school_id')
        super(TeacherModelForm, self).__init__(*args, **kwargs)
        if school_id:
            self.school_id = school_id
            grade = form_models.ModelChoiceField(
                required=False,
                queryset=scmodels.Grade.objects.filter(
                    stuclass__school_id=school_id).distinct(),
                widget=Fwidgets.Select(attrs={
                    'class': 'form-control',
                    'id': 'grade'
                }),
                empty_label=None)
            self.fields['grade'] = grade

    class Meta:
        model = teamodels.TeacherInfo
        fields = ('last_name', 'first_name', 'gender', 'birthday', 'telephone',
                  'wechat', 'identity', 'course')
        widgets = {
            "last_name":
            Fwidgets.TextInput(attrs={
                'class': 'form-control',
                'style': 'width: 600px'
            }),
            "first_name":
            Fwidgets.TextInput(attrs={
                'class': 'form-control',
                'style': 'width: 600px'
            }),
            'wechat':
            Fwidgets.TextInput(attrs={
                'class': 'form-control',
                'style': 'width: 600px'
            }),
            'telephone':
            Fwidgets.TextInput(attrs={
                'class': 'form-control',
                'style': 'width: 600px'
            }),
        }
        error_messages = {
            "last_name": {
                "required": "请输入老师姓"
            },
            "first_name": {
                "required": "请输入老师名"
            },
            "gender": {
                "required": "请选择性别"
            },
        }
        labels = {
            'last_name': '老师姓(必填)',
            'first_name': '老师名(必填)',
        }

    def clean(self):
        '''
        校验该教师是否已经存在
        :return:
        '''
        birthday = self.cleaned_data.get('birthday')
        last_name = self.cleaned_data.get('last_name')
        first_name = self.cleaned_data.get('first_name')
        teacher_obj = teamodels.TeacherInfo.objects.filter(
            birthday=birthday,
            first_name=first_name,
            last_name=last_name,
            school=self.school_id)
        if teacher_obj:
            raise ValidationError('该教师已存在')
        return self.cleaned_data