示例#1
0
    def __init__(self, *args, **kwargs):
        if hasattr(self, 'user'):
            kwargs.update({'user': self.user})
        super(JobForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields['description'].widget.mce_attrs[
                'app_instance_id'] = self.instance.pk
            #self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0]
            if self.user.profile.is_superuser:
                self.fields['status_detail'].choices = STATUS_DETAIL_CHOICES
        else:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = 0
            self.fields['group'].initial = Group.objects.get_initial_group_id()

        self.fields['pricing'].choices = pricing_choices(self.user)

        if 'payment_method' in self.fields:
            choices = get_payment_method_choices(self.user)
            self.fields['payment_method'].widget = forms.RadioSelect(
                choices=choices)
            self.fields['payment_method'].choices = choices
            #self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            if choices and len(choices) == 1:
                self.fields['payment_method'].initial = choices[0][0]

        # adjust fields depending on user status
        fields_to_pop = []
        if not self.user.is_authenticated():
            fields_to_pop += [
                'entity', 'allow_anonymous_view', 'user_perms', 'group_perms',
                'member_perms', 'post_dt', 'activation_dt', 'expiration_dt',
                'syndicate', 'status_detail'
            ]
        else:
            fields_to_pop += ['captcha']

        if not self.user.profile.is_superuser:
            fields_to_pop += [
                'slug', 'entity', 'group', 'allow_anonymous_view',
                'user_perms', 'member_perms', 'group_perms', 'post_dt',
                'activation_dt', 'expiration_dt', 'syndicate', 'status_detail'
            ]

        for f in list(set(fields_to_pop)):
            if f in self.fields:
                self.fields.pop(f)
示例#2
0
    def __init__(self, *args, **kwargs):
        if hasattr(self, 'user'):
            kwargs.update({'user': self.user})
        super(JobForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = self.instance.pk
            #self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0]
            if self.user.profile.is_superuser:
                self.fields['status_detail'].choices = STATUS_DETAIL_CHOICES
        else:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = 0
            self.fields['group'].initial = Group.objects.get_initial_group_id()

        # cat and sub_cat
        if self.user.profile.is_superuser:
            self.fields['sub_cat'].help_text = mark_safe('<a href="{0}">{1}</a>'.format(
                                        reverse('admin:jobs_category_changelist'),
                                        _('Manage Categories'),))
        if self.instance and self.instance.pk:
            self.fields['sub_cat'].queryset = JobCategory.objects.filter(
                                                        parent=self.instance.cat)
        if args:
            post_data = args[0]
        else:
            post_data = None
        if post_data:
            cat = post_data.get('cat', '0')
            if cat and cat != '0' and cat != u'':
                cat = JobCategory.objects.get(pk=int(cat))
                self.fields['sub_cat'].queryset = JobCategory.objects.filter(parent=cat)

        self.fields['pricing'].choices = pricing_choices(self.user)

        if 'payment_method' in self.fields:
            choices=get_payment_method_choices(self.user)
            self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            self.fields['payment_method'].choices = choices
            #self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            if choices and len(choices) == 1:
                self.fields['payment_method'].initial = choices[0][0]

        # adjust fields depending on user status
        fields_to_pop = []
        if not self.user.is_authenticated:
            fields_to_pop += [
                'entity',
                'allow_anonymous_view',
                'user_perms',
                'group_perms',
                'member_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]
        else:
            fields_to_pop += [
                'captcha'
            ]

        if not self.user.profile.is_superuser:
            fields_to_pop += [
                'slug',
                'entity',
                'group',
                'allow_anonymous_view',
                'user_perms',
                'member_perms',
                'group_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]

        for f in list(set(fields_to_pop)):
            if f in self.fields:
                self.fields.pop(f)
示例#3
0
文件: forms.py 项目: BIGGANI/tendenci
    def __init__(self, *args, **kwargs):
        if hasattr(self, 'user'):
            kwargs.update({'user': self.user})
        super(JobForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = self.instance.pk
            #self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0]
            if self.user.profile.is_superuser:
                self.fields['status_detail'].choices = STATUS_DETAIL_CHOICES
        else:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = 0
            self.fields['group'].initial = Group.objects.get_initial_group_id()

        self.fields['pricing'].choices = pricing_choices(self.user)

        if 'payment_method' in self.fields:
            choices=get_payment_method_choices(self.user)
            self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            self.fields['payment_method'].choices = choices
            #self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            if choices and len(choices) == 1:
                self.fields['payment_method'].initial = choices[0][0]            

        # adjust fields depending on user status
        fields_to_pop = []
        if not self.user.is_authenticated():
            fields_to_pop += [
                'entity',
                'allow_anonymous_view',
                'user_perms',
                'group_perms',
                'member_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]
        else:
            fields_to_pop += [
                'captcha'
            ]

        if not self.user.profile.is_superuser:
            fields_to_pop += [
                'slug',
                'entity',
                'group',
                'allow_anonymous_view',
                'user_perms',
                'member_perms',
                'group_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]

        for f in list(set(fields_to_pop)):
            if f in self.fields:
                self.fields.pop(f)
示例#4
0
    def __init__(self, *args, **kwargs):
        if hasattr(self, 'user'):
            kwargs.update({'user': self.user})
        super(JobForm, self).__init__(*args, **kwargs)
        if self.instance.pk:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = self.instance.pk
            #self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0]
            if self.user.profile.is_superuser:
                self.fields['status_detail'].choices = STATUS_DETAIL_CHOICES
        else:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = 0
            self.fields['group'].initial = Group.objects.get_initial_group_id()

        # cat and sub_cat
        if self.user.profile.is_superuser:
            self.fields['sub_cat'].help_text = mark_safe('<a href="{0}">{1}</a>'.format(
                                        reverse('admin:jobs_category_changelist'),
                                        _('Manage Categories'),))
        if self.instance and self.instance.pk:
            self.fields['sub_cat'].queryset = JobCategory.objects.filter(
                                                        parent=self.instance.cat)
        if args:
            post_data = args[0]
        else:
            post_data = None
        if post_data:
            cat = post_data.get('cat', '0')
            if cat and cat != '0' and cat != u'':
                cat = JobCategory.objects.get(pk=int(cat))
                self.fields['sub_cat'].queryset = JobCategory.objects.filter(parent=cat)

        self.fields['pricing'].choices = pricing_choices(self.user)

        if 'payment_method' in self.fields:
            choices=get_payment_method_choices(self.user)
            self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            self.fields['payment_method'].choices = choices
            #self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            if choices and len(choices) == 1:
                self.fields['payment_method'].initial = choices[0][0]

        # adjust fields depending on user status
        fields_to_pop = []
        if not self.user.is_authenticated:
            fields_to_pop += [
                'entity',
                'allow_anonymous_view',
                'user_perms',
                'group_perms',
                'member_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]
        else:
            fields_to_pop += [
                'captcha'
            ]

        if not self.user.profile.is_superuser:
            fields_to_pop += [
                'slug',
                'entity',
                'group',
                'allow_anonymous_view',
                'user_perms',
                'member_perms',
                'group_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]

        for f in list(set(fields_to_pop)):
            if f in self.fields:
                self.fields.pop(f)
示例#5
0
    def __init__(self, *args, **kwargs):
        if hasattr(self, 'user'):
            kwargs.update({'user': self.user})
        super(JobForm, self).__init__(*args, **kwargs)
        if self.instance.header_image:
            print('A' * 30)
            print(self.instance.header_image)
            self.fields['header_image'].help_text = '<input name="remove_photo" id="id_remove_photo" type="checkbox"/> %s: <a target="_blank" href="/files/%s/">%s</a>' % (_('Remove current image'), self.instance.header_image.id, basename(self.instance.header_image.file.name))
        else:
            self.fields.pop('remove_photo')
        self.fields['header_image'].validators = [FileValidator(allowed_extensions=get_allowed_upload_file_exts('image'))]
        if self.instance.pk:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = self.instance.pk
            #self.fields['pricing'].initial = JobPricing.objects.filter(duration=self.instance.requested_duration)[0]
            if self.user.profile.is_superuser:
                self.fields['status_detail'].choices = STATUS_DETAIL_CHOICES
        else:
            self.fields['description'].widget.mce_attrs['app_instance_id'] = 0
            self.fields['group'].initial = Group.objects.get_initial_group_id()

        # cat and sub_cat
        if self.user.profile.is_superuser:
            self.fields['sub_cat'].help_text = mark_safe('<a href="{0}">{1}</a>'.format(
                                        reverse('admin:jobs_category_changelist'),
                                        _('Manage Categories'),))
        if self.instance and self.instance.pk:
            self.fields['sub_cat'].queryset = JobCategory.objects.filter(
                                                        parent=self.instance.cat)
        if args:
            post_data = args[0]
        else:
            post_data = None
        if post_data:
            cat = post_data.get('cat', '0')
            if cat and cat != '0' and cat != u'':
                cat = JobCategory.objects.get(pk=int(cat))
                self.fields['sub_cat'].queryset = JobCategory.objects.filter(parent=cat)

        self.fields['pricing'].choices = pricing_choices(self.user)

        if 'payment_method' in self.fields:
            choices=get_payment_method_choices(self.user)
            self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            self.fields['payment_method'].choices = choices
            #self.fields['payment_method'].widget = forms.RadioSelect(choices=choices)
            if choices and len(choices) == 1:
                self.fields['payment_method'].initial = choices[0][0]

        # adjust fields depending on user status
        fields_to_pop = []
        if not self.user.is_authenticated:
            fields_to_pop += [
                'entity',
                'allow_anonymous_view',
                'user_perms',
                'group_perms',
                'member_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]
        else:
            fields_to_pop += [
                'captcha'
            ]

        if not self.user.profile.is_superuser:
            fields_to_pop += [
                'entity',
                'group',
                'allow_anonymous_view',
                'user_perms',
                'member_perms',
                'group_perms',
                'post_dt',
                'activation_dt',
                'expiration_dt',
                'syndicate',
                'status_detail'
            ]

        for f in list(set(fields_to_pop)):
            if f in self.fields:
                self.fields.pop(f)