Beispiel #1
0
    def __init__(self, *args, **kwargs):
        self.choices = kwargs.pop('choices', ())
        self.template_name = kwargs.pop('template_name',
                                        'forms/widgets/transferselect.html')
        self.iterator = kwargs.pop('iterator', ModelChoiceIterator)

        self.ts_id = "%x" % random.randint(0, 16**6)

        kwargs.update({
            'widgets': (
                widgets.SelectMultiple(
                    choices=self.choices,
                    attrs={
                        'data-transfer-bucket': 'available',
                        'data-transfer-id': self.ts_id,
                    },
                ),
                widgets.SelectMultiple(
                    choices=(),
                    attrs={
                        'data-transfer-bucket': 'selected',
                        'data-transfer-id': self.ts_id,
                    },
                ),
            )
        })
        super(TransferSelect, self).__init__(*args, **kwargs)
Beispiel #2
0
    class ARForm(forms.ModelForm):
        class Media:
            js = ('js/jquery-1.7.1.min.js', 'js/activities.js')
            css = {'all': ('css/teacher_preferences.css', )}

        class Meta:
            model = ActivityRealization
            fields = '__all__'

        groups = RealizationMultipleModelGroupChoiceField(
            widget=widgets.SelectMultiple(
                attrs={'class': 'realization_group_select'}, ),
            queryset=a.groups.order_by("short_name"),
            required=False)
        teachers = forms.ModelMultipleChoiceField(
            widget=widgets.SelectMultiple(
                attrs={'class': 'realization_teacher_select'}, ),
            queryset=a.teachers,
            required=False)
        activity = forms.ModelChoiceField(
            queryset=Activity.objects.filter(id=a.id),
            initial=a.id,
            widget=forms.HiddenInput())
        activity.displayName = a.displayName

        def __init__(self, *args, **kwargs):
            self.allocations = []
            if timetable is not None and 'instance' in kwargs:
                self.allocations = timetable.allocations.filter(
                    activityRealization=kwargs['instance'])
            super(ARForm, self).__init__(*args, **kwargs)
Beispiel #3
0
class ApartmentFilter(filters.FilterSet):
    address = filters.ModelMultipleChoiceFilter(
        widget=widgets.SelectMultiple(attrs={'class': 'select2'}),
        queryset=Address.objects.all(),
        label='Адреса')
    client = filters.ModelMultipleChoiceFilter(
        widget=widgets.SelectMultiple(attrs={'class': 'select2'}),
        queryset=Client.objects.all(),
        label='Клиенты')

    class Meta:
        model = Apartment
        fields = ['address', 'client']
Beispiel #4
0
class TeacherForm(Form):
    name = fields.CharField(required=True,
                            error_messages={'required': '用户名不能为空'},
                            widget=widgets.TextInput(attrs={
                                'class': 'form-control',
                                'id': 'name'
                            }))
    age = fields.IntegerField(required=True,
                              error_messages={'required': '年龄不能为空'},
                              widget=widgets.NumberInput(attrs={
                                  'class': 'form-control',
                                  'id': 'age'
                              }))
    sex = fields.CharField(required=True,
                           error_messages={'required': '性别不能为空'},
                           widget=widgets.TextInput(attrs={
                               'class': 'form-control',
                               'id': 'sex'
                           }))
    tel = fields.IntegerField(required=True,
                              error_messages={'required': '电话不能为空'},
                              widget=widgets.NumberInput(attrs={
                                  'class': 'form-control',
                                  'id': 'tel'
                              }))
    salary = fields.IntegerField(required=True,
                                 error_messages={'required': '薪水不能为空'},
                                 widget=widgets.NumberInput(attrs={
                                     'class': 'form-control',
                                     'id': 'salary'
                                 }))
    class_list = fields.MultipleChoiceField(
        choices=models.Classes.objects.values_list("id", "name"),
        widget=widgets.SelectMultiple(attrs={
            'class': 'form-control',
            'id': 'classes'
        }))
    course_list = fields.MultipleChoiceField(
        choices=models.Course.objects.values_list("id", "name"),
        widget=widgets.SelectMultiple(attrs={
            'class': 'form-control',
            'id': 'course'
        }))
    userType = fields.ChoiceField(choices=models.UserType.objects.values_list(
        "id", "name"),
                                  widget=widgets.Select(attrs={
                                      'class': 'form-control',
                                      'id': 'usertype'
                                  }))
Beispiel #5
0
class BookForm(forms.Form):
    '''
	图书添加表单
	'''
    name = forms.CharField(
        max_length=32,
        min_length=2,
        widget=widgets.TextInput(attrs={
            'class': 'form-control',
            'placeholder': '书名',
            'id': 'bookname'
        }))
    publisher_year = forms.DateField(
        widget=widgets.DateInput(attrs={
            'class': 'form-control',
            'placeholder': '出版日期',
            'id': 'publisher_year'
        }), )

    price = forms.IntegerField(widget=widgets.NumberInput(
        attrs={
            'class': 'form-control',
            'placeholder': '价格',
            'id': 'price'
        }))
    stocks = forms.IntegerField(widget=widgets.NumberInput(
        attrs={
            'class': 'form-control',
            'placeholder': '库存',
            'id': 'stocks'
        }))
    status = forms.ChoiceField(
        choices=[(0, '未出版'), (1, '已出版')],
        widget=widgets.Select(attrs={
            'type': 'select',
            'id': 'status'
        }),
    )

    type = forms.ChoiceField(choices=TypeBook.objects.all().values_list(
        'id', 'type_book'),
                             widget=widgets.Select(
                                 attrs={
                                     "class": "form-control",
                                     "data-live-search": "true",
                                     "data-width": "100%",
                                     "id": "type"
                                 }))
    publisher = forms.ChoiceField(choices=Publisher.objects.all().values_list(
        'id', 'name'),
                                  widget=widgets.Select(
                                      attrs={
                                          "class": "form-control",
                                          "data-live-search": "true",
                                          "data-width": "100%",
                                          "id": "publisher"
                                      }))
    author = forms.MultipleChoiceField(
        choices=Author.objects.all().values_list('id', 'name'),
        widget=widgets.SelectMultiple(attrs={"id": "demo-cs-multiselect"}))
Beispiel #6
0
class RoleForm(forms.Form):
    name = forms.CharField(
        error_messages={"required": "请输入角色名"},
        widget=widgets.TextInput(attrs={"class": "form-control input-sm"}))

    menu = forms.MultipleChoiceField(
        error_messages={"required": "请选择菜单权限"},
        widget=widgets.SelectMultiple(
            attrs={"class": "form-control input-sm"}))

    comment = forms.CharField(required=False,
                              widget=widgets.Textarea(attrs={
                                  "class": "form-control input-sm",
                                  "rows": "5"
                              }))

    def __init__(self, *args, **kwargs):
        super(RoleForm, self).__init__(*args, **kwargs)
        self.fields["menu"].choices = models.Menu.objects.all().values_list(
            "id", "name")

    def clean_name(self):
        role_obj = models.Role.objects.filter(
            name=self.cleaned_data["name"]).first()
        if not role_obj:
            return self.cleaned_data["name"]
        else:
            # 如果获取的ID和查询的ID一样表示原值,不需要抛异常,如果不一样表示修的名称和数据中其他名称有相同
            if self.initial.get("id") == role_obj.id:
                return self.cleaned_data["name"]
            else:
                raise ValidationError("角色名已存在", code="name")
Beispiel #7
0
class LoginForm(Form):
    name = fields.CharField(
        label='用户名',
        required=True,
        error_messages={
            'required':'用户名不能为空'
        },
        widget=widgets.TextInput(attrs={'class':'form-control'})
    )
    pwd = fields.CharField(
        label='密码',
        required=True,
        error_messages={
            'required': '密码不能为空'
        },
        widget=widgets.PasswordInput(attrs={'class':'form-control'})
    )
    email = fields.EmailField(
        label="邮箱",
        required=True,
        error_messages={
            'required':"邮箱不能为空"
        },
        widget=widgets.EmailInput(attrs={'class':'form-control'})
    )
    roles = fields.MultipleChoiceField(
        label="组名",
        required=False,
        error_messages={
            'required':'组名不能为空'
        },
        choices=role_querset,#2,4
        widget=widgets.SelectMultiple(attrs={'class':'form-control'})
    )
Beispiel #8
0
    class Meta:
        model = Variable
        fields = '__all__'
        widgets = {
            'name':
            widgets.TextInput(attrs={
                'class': 'form-control',
            }),
            'desc':
            widgets.Textarea(attrs={
                'class': 'form-control',
                'cols': 80,
                'rows': 6
            }),
            'vars':
            widgets.Textarea(attrs={
                'class': 'form-control',
                'cols': 80,
                'rows': 6
            }),
            'assets':
            widgets.SelectMultiple(attrs={
                'class': 'form-control',
                'data-placeholder': '选择脚本类型'
            }),
        }

        help_texts = {
            'name':
            '* 必填项目,名字不可以重复,使用方法:在下面定义一个 path,  关联相关主机  在命令行 输入 echo {{ path }} 即可调用',
            'vars':
            '例如: {"path": "/tmp","name":"123"} , 默认变量  "hostname","inner_ip","network_ip","project"',
        }
Beispiel #9
0
    class Meta:
        model = models.Book
        fields = '__all__'
        widgets = {
            'date':widgets.TextInput(attrs={'type':'date','class':'form-control'}),
            'price':widgets.TextInput(attrs={'class':'form-control'}),
            'publish':widgets.Select(attrs={'class':'form-control'}),
            'title':widgets.TextInput(attrs={'class':'form-control'}),
            'authors':widgets.SelectMultiple(attrs={'class':'form-control'}),
        }
        labels = {
            'date':'日期',
            'title':'书名',
            'price':'价格',
            'publish':'出版社',
            'authors':'作者'
        }
        error_messages = {
            'title': {
                'required': ('不能为空'),
                'min_length': ('不能少于3位'),
                'max_length': ('不能大于5位'),
            },
            'price': {
                'invalid': '格式不正确',
                'required': ('不能为空'),
            }

        }
Beispiel #10
0
class ProductChartForm(forms.Form):
    """
    Form for creating a chart depicting the amount of product ordered, for a set of a particular product(s) over time. 
    """

    # Add in the dynamic choices which depend on the user.
    # For this chart we need which products to display -- all products
    # which belong to all categories which belong to the orgs the user
    # belongs to.
    def __init__(self, data=None, request=None, *args, **kwargs):
        if request is None:
            raise TypeError("Keyword argument 'request' must be supplied.")
        super(ProductChartForm, self).__init__(data, *args, **kwargs)
        self.request = request
        profiles = UserProfile.objects.filter(user__exact=request.user)

        prod_choices = []
        for up in profiles:
            cats = Category.objects.filter(org=up.org)
            prods = Product.objects.filter(categories__in=cats)
            for p in prods:
                name_str = '%s [%s]' % (p.name, up.org)
                prod_choices.append((p.id, name_str))
        self.fields['products'].choices = prod_choices

    products = forms.MultipleChoiceField(
        choices=(),
        required=True,
        widget=widgets.SelectMultiple(attrs={'size': '20'}))
Beispiel #11
0
class UserChartForm(forms.Form):
    """
    Form for creating a chart depicting the amount of a single product ordered, for comparing multiple users, over time. 
    """
    def __init__(self, data=None, request=None, *args, **kwargs):
        if request is None:
            raise TypeError("Keyword argument 'request' must be supplied.")
        super(UserChartForm, self).__init__(data, *args, **kwargs)
        self.request = request
        profiles = UserProfile.objects.filter(user__exact=request.user)
        orgs = [p.org for p in profiles]
        other_users = UserProfile.objects.filter(
            org__in=orgs, user__is_staff=False
        )  # no staff, otherwise user's chart could include InventoryHistory events which are mimic internal adjustments

        prod_choices, user_choices = [], []
        for up in other_users:
            if not (up.user.id, up.user.get_full_name()
                    ) in user_choices:  # make unique user list
                user_choices.append((up.user.id, up.user.get_full_name()))
        for o in orgs:
            cats = Category.objects.filter(org=o)
            prods = Product.objects.filter(categories__in=cats)
            for p in prods:
                name_str = '%s [%s]' % (p.name, o)
                prod_choices.append((p.id, name_str))
        self.fields['product'].choices = prod_choices
        self.fields['users'].choices = user_choices

    product = forms.ChoiceField(choices=(), required=True)
    users = forms.MultipleChoiceField(
        choices=(),
        required=True,
        widget=widgets.SelectMultiple(attrs={'size': '20'}))
Beispiel #12
0
class OrgChartForm(forms.Form):
    """
    Form for creating a chart depicting the amount of a single product ordered, for comparing multiple orgs, over time. 
    """
    def __init__(self, data=None, request=None, *args, **kwargs):
        if request is None:
            raise TypeError("Keyword argument 'request' must be supplied.")
        super(OrgChartForm, self).__init__(data, *args, **kwargs)
        self.request = request
        profiles = UserProfile.objects.filter(user__exact=request.user)

        prod_choices, org_choices = [], []
        for up in profiles:
            cats = Category.objects.filter(org=up.org)
            org_choices.append((up.org.id, up.org))
            prods = Product.objects.filter(categories__in=cats)
            for p in prods:
                name_str = '%s [%s]' % (p.name, up.org)
                prod_choices.append((p.id, name_str))
        self.fields['product'].choices = prod_choices
        self.fields['orgs'].choices = org_choices

    product = forms.ChoiceField(choices=(), required=True)
    orgs = forms.MultipleChoiceField(
        choices=(),
        required=True,
        widget=widgets.SelectMultiple(attrs={'size': '20'}))
    class Meta:
        model = models.Product
        localized_fields = ('price_valid_until',)
        fields = ['name', 'description', 'gender', 'price_ht', 'discount_pct', 'quantity', 'price_valid_until',
                  'collection', 'clothe_size', 'reference', 'sku', 'in_stock', 'active', 'our_favorite', 'discounted', 'google_category']
        widgets = {
            'name': widgets.TextInput(attrs={'class': 'form-control', 'placeholder': 'Nom du produit'}),
            'description': forms.widgets.Textarea(attrs={'class': 'form-control'}),
            'gender': widgets.Select(attrs={'class': 'form-control'}),

            'sku': widgets.TextInput(attrs={'class': 'form-control', 'placeholder': 'SKU'}),
            'reference': widgets.TextInput(attrs={'class': 'form-control', 'placeholder': 'Référence'}),

            'price_ht': widgets.NumberInput(attrs={'class': 'form-control', 'placeholder': 'Prix Hors Taxe', 'min': '0'}),
            'price_valid_until': custom_widgets.DateInput(),
            'discount_pct': widgets.NumberInput(attrs={'class': 'form-control', 'placeholder': 'Nombre en %', 'min': '5'}),
            'quantity': widgets.NumberInput(attrs={'class': 'form-control', 'step': '5', 'min': '0'}),

            'clothe_size': widgets.SelectMultiple(attrs={'class': 'form-control'}),
            'collection': widgets.Select(attrs={'class': 'form-control'}),
            'google_category': widgets.Select(attrs={'class': 'form-control'}),

            'in_stock': widgets.CheckboxInput(attrs={'class': 'custom-control-input', 'id': 'in_stock'}),
            'our_favorite': widgets.CheckboxInput(attrs={'class': 'custom-control-input'}),
            'discounted': custom_widgets.CheckBoxInput(),
            'active': widgets.CheckboxInput(attrs={'class': 'custom-control-input', 'id': 'active'}),
        }
Beispiel #14
0
    def value_from_datadict(self, data, files, name):
        value = widgets.SelectMultiple().value_from_datadict(data, files, name)

        if not value or value == [""]:
            return ""

        return value
Beispiel #15
0
    class Meta:
        model = models.Crontab
        fields = "__all__"
        labels = {
            'jobname':'任务名称',
            'minute':'分',
            'hour':'时',
            'day':'日',
            'month':'月',
            'weekday':'周',
            'jobcli':'命令',
            'cron_host':'host'

        }

        widgets = {
            'jobname':widgets.Input(attrs={"class":'form-control','placeholder':"请输入服务名","type":"text"}),
            'minute': widgets.Input(attrs={"class": 'form-control', 'placeholder': "请输入服务名", "type": "text"}),
            'hour': widgets.Input(attrs={"class": 'form-control', 'placeholder': "请输入服务名", "type": "text"}),
            'day': widgets.Input(attrs={"class": 'form-control', 'placeholder': "请输入服务名", "type": "text"}),
            'month': widgets.Input(attrs={"class": 'form-control', 'placeholder': "请输入服务名", "type": "text"}),
            'weekday': widgets.Input(attrs={"class": 'form-control', 'placeholder': "请输入服务名", "type": "text"}),
            'jobcli': widgets.Input(attrs={"class": 'form-control', 'placeholder': "请输入服务名", "type": "text"}),
            'cron_host':widgets.SelectMultiple(attrs={'class':'form-control select2','multiple':'multiple'}),

        }
Beispiel #16
0
class ServiceForm(Form):
    """
    业务线表单验证
    """
    def __init__(self, *args, **kwargs):
        super(ServiceForm, self).__init__(*args, **kwargs)
        self.fields['idc_id'].choices = models.Idc.objects.values_list(
            "id", "idc")
        self.fields['owner_id'].choices = models.User.objects.values_list(
            "id", "username")
        print("*" * 50)
        print(self.fields['idc_id'].choices)
        print(self.fields['owner_id'].choices)

    name = fields.CharField(required=True,
                            label=u'业务线名称',
                            max_length=32,
                            error_messages={"required": "业务线名称不能为空!"},
                            widget=widgets.TextInput(attrs={
                                'class': 'form-control',
                                'placeholder': u'业务线名称'
                            }))

    idc_id = fields.ChoiceField(
        required=True,
        label=u'所属机房',
        choices=[],
        widget=widgets.Select(attrs={'class': 'form-control'}))

    owner_id = fields.MultipleChoiceField(
        required=True,
        choices=[],
        error_messages={'required': "负责人不能为空!"},
        widget=widgets.SelectMultiple(attrs={'class': 'form-control'}))
Beispiel #17
0
 class Meta:
     model = models.Book
     fields = "__all__"
     widgets = {
         'name':
         widgets.TextInput(attrs={
             'class': 'form-control',
             'autocomplete': 'off'
         }),
         # 'autor':widgets.SelectMultiple(attrs={'class': 'form-control', 'autocomplete': 'off'}),
         # 'autor':widgets.CheckboxSelectMultiple(attrs={'class': 'form-control', 'autocomplete': 'off'}),
         # 'autor':widgets.ChoiceWidget(attrs={'class': 'form-control', 'autocomplete': 'off'}),
         'author':
         widgets.SelectMultiple(attrs={
             'class': 'form-control',
             'autocomplete': 'off'
         }),
         'publish':
         widgets.Select(attrs={
             'class': 'form-control',
             'autocomplete': 'off'
         }),
     }
     val = {"required": "该字段不能为空"}
     error_messages = {
         "name": val,
         "author": val,
         "publish": val,
     }
Beispiel #18
0
class UserForm(Form):
    username = fields.CharField(
        required=True,
        error_messages={'required': '用户名不能为空'},
        widget=widgets.TextInput(attrs={'class': 'form-control'}))
    password = fields.CharField(required=True,
                                error_messages={
                                    'required': '密码不能为空',
                                    'invalid': '密码格式错误'
                                })

    email = fields.EmailField(required=True,
                              error_messages={
                                  'required': '邮箱不能为空',
                                  'invalid': '邮箱格式错误'
                              })

    phone = fields.IntegerField(required=True,
                                error_messages={'required': '电话不能为空'})

    sl_id = fields.MultipleChoiceField(choices=[],
                                       widget=widgets.SelectMultiple())

    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['sl_id'].choices = models.Service_Line.objects.values_list(
            'id', 'service_line_name')
Beispiel #19
0
 class Meta:
     model = models.Role
     fields = "__all__"
     widgets = {
         'permissions':
         form_widgets.SelectMultiple(attrs={'style': 'height:200px;'})
     }
Beispiel #20
0
class TestForm(forms.Form):

    n1 = fields.CharField(widget=widgets.PasswordInput())

    n2 = fields.CharField(widget=widgets.Textarea())

    n3 = fields.CharField(widget=widgets.Select(choices=[
        (1, "上海"),
        (2, "北京"),
        (3, "广州"),
    ]))

    n4 = fields.ChoiceField(choices=[(1, "上海"), (2, "北京"), (3, "广州")],
                            widget=widgets.SelectMultiple())

    n5 = fields.IntegerField(widget=widgets.RadioSelect(choices=[
        (1, '上海'),
        (2, '北京'),
    ]))

    n6 = fields.CharField(widget=widgets.CheckboxInput())

    n7 = fields.ChoiceField(choices=[
        (1, '上海'),
        (2, '北京'),
    ],
                            widget=widgets.CheckboxSelectMultiple())

    n8 = fields.FileField()
Beispiel #21
0
    class Meta:
        model = models.Service
        fields = "__all__"
        labels = {
            's_name': '服务名称',
            's_type': '服务类型',
            'h_server': '关联主机',
        }

        widgets = {
            's_name':
            ws.Input(attrs={
                "class": 'form-control',
                'placeholder': "请输入服务名",
                "type": "text"
            }),
            's_type':
            ws.Input(attrs={
                "class": 'form-control',
                'placeholder': "请输入服务类型",
                "type": "text"
            }),
            'h_server':
            ws.SelectMultiple(attrs={
                'class': 'form-control select2',
                'multiple': 'multiple'
            }),
        }
Beispiel #22
0
    class Meta:
        model = Confd
        fields = ['conf_name','conf_path','conf_service','conf_host']
        labels = {
            'conf_name':'配置名称',
            'conf_path':'配置路径',
            'conf_service':'配置类型',
            'conf_host':'配置主机'
        }

        widgets = {
            'conf_name': widgets.Input(attrs={"class": 'form-control', 'placeholder': "conf_name", "type": "text"}),
            'conf_path': widgets.Input(attrs={"class": 'form-control', 'placeholder': "conf_path", "type": "text"}),
            'conf_service': widgets.SelectMultiple(attrs={'class': 'form-control select2', 'multiple': 'multiple'}),
            'conf_host': widgets.SelectMultiple(attrs={'class': 'form-control select2', 'multiple': 'multiple'}),
        }
Beispiel #23
0
class IssueForm(forms.ModelForm):
    checklists = forms.ModelMultipleChoiceField(
        queryset=None,
        required=False,
        widget=widgets.SelectMultiple(
            attrs={
                'class': 'selectpicker',
                'data-live-search': 'true',
                'multiple': 'multiple'
            }))

    def __init__(self, project, issue, *args, **kwargs):
        super(IssueForm, self).__init__(*args, **kwargs)
        # configure checklists field.
        self.fields['checklists'].queryset = project.checklist_set
        if issue:
            self.fields['checklists'].initial = issue.checklist_set.all()

    class Meta:
        model = Issue
        fields = ['name', 'description']

    def save(self, commit=True):
        instance = super(IssueForm, self).save(commit)

        # save checklists.
        instance.checklist_set.clear()
        for checklist in self.cleaned_data['checklists']:
            checklist.issues.add(instance)

        return instance
class WorkForms(Form):
    '工作表'
    title = fields.CharField(max_length=32,
                             min_length=2,
                             required=True,
                             widget=widgets.TextInput(attrs={
                                 'class': "form-control",
                                 'placeholder': "工作项目"
                             }))
    content = fields.CharField(max_length=255,
                               min_length=2,
                               required=True,
                               widget=widgets.Textarea(attrs={
                                   'class': "form-control",
                                   'placeholder': "工作进度"
                               }))
    main_response = fields.ChoiceField(widget=widgets.Select(
        attrs={'class': "form-control"}))
    sub_response = fields.MultipleChoiceField(
        widget=widgets.SelectMultiple(attrs={'class': "form-control"}),
        required=False)
    # create_time=fields.DateTimeField()
    status = fields.ChoiceField(
        widget=widgets.Select(attrs={'class': "form-control"}),
        choices=(
            (True, '是'),
            (False, '否'),
        ))

    def __init__(self, request, subtitle, *args, **kwargs):
        super(WorkForms, self).__init__(*args, **kwargs)
        self.request = request
        self.subtitle = subtitle
        print('----subtitle')
        print(self.subtitle)
        print('------request')
        print(self.request)
        print('-------args')
        print(args)
        print('------kwargs')
        print(kwargs)
        role_department_id = models.UserInfo.objects.filter(
            subtitle=self.subtitle).values('role_id', 'department_id',
                                           'uid').first()
        print('---------role_department_id')
        print(role_department_id)
        userinfo = models.UserInfo.objects.filter(
            role_id=role_department_id.get('role_id'),
            department_id=role_department_id.get('department_id')).values(
                'uid', 'username')
        print(userinfo)
        self.fields['main_response'].choices = models.UserInfo.objects.filter \
            (role_id=role_department_id.get('role_id'),
             department_id=role_department_id.get('department_id')).values_list('uid', 'username')
        self.fields['sub_response'].choices = models.UserInfo.objects.filter \
            (role_id=role_department_id.get('role_id'),
             department_id=role_department_id.get('department_id')).values_list('uid', 'username')
        self.fields['main_response'].initial = role_department_id.get('uid')
    def render(self, name, value, attrs={}, choices=(), renderer=None):
        rendered_attrs = {'class': HTML_ATTR_CLASS}
        rendered_attrs.update(attrs)

        final_attrs = self.build_attrs(rendered_attrs, dict(name=name))
        s = widgets.SelectMultiple(choices=self.choices)
        select_html = s.render(name=name, value=value, attrs=final_attrs)

        return mark_safe(''.join(select_html))
Beispiel #26
0
 class Meta:
     model = models.User
     fields = "__all__"
     widgets = {
         'name': form_widgets.TextInput(attrs={'class': 'form-control'}),
         'roles':
         form_widgets.SelectMultiple(attrs={'class': 'form-control'}),
     }
     error_messages = {'name': {'required': '*用户名不能为空'}}
Beispiel #27
0
 class Meta:
     model = models.User
     fields = '__all__'
     labels = {'name': '用户名', 'pwd': '密码', 'roles': '用户权限'}
     widgets = {
         'name': wid.TextInput(attrs={'class': 'form-control'}),
         'pwd': wid.PasswordInput(attrs={'class': 'form-control'}),
         'roles': wid.SelectMultiple(attrs={'class': 'form-control'})
     }
Beispiel #28
0
 class Meta:
     model = JenkinsJob
     fields = ['job_name','project','job_type','svn_url','emails']
     widgets = {
         'job_name': widgets.TextInput(attrs={'class':'form-control',"disabled":""}),
         'project': widgets.Select(attrs={'class': 'form-control', "disabled": ""}),
         'svn_url': widgets.TextInput(attrs={'class': 'form-control', "disabled": ""}),
         'job_type': widgets.Select(attrs={'class': 'form-control', "disabled": ""}),
         'emails': widgets.SelectMultiple(attrs={'class': 'form-control dual_select',}),
     }
Beispiel #29
0
 class Meta:
     model = models.UserInfo
     fields = "__all__"
     widgets = {
         "name": widgets.TextInput(attrs={"class": "form-control"}),
         "email": widgets.EmailInput(attrs={"class": "form-control"}),
         "gender": widgets.Select(attrs={"class": "form-control"}),
         "depart": widgets.Select(attrs={"class": "form-control"}),
         "roles": widgets.SelectMultiple(attrs={"class": "form-control"})
     }
Beispiel #30
0
 def __init__(
     self,
     choices: typing.Sequence[typing.Tuple[str, str]],
     attrs: typing.Optional[typing.Dict[str, str]] = None,
 ) -> None:
     _widgets = (
         widgets.SelectMultiple(choices=choices, attrs=attrs),
         LabeledCheckboxInput(label=_("critical")),
     )
     super().__init__(_widgets, attrs)