Esempio n. 1
0
 def __init__(self, *args, **kwargs):
     self.allowed_extensions = kwargs.pop('allowed_extensions',
                                          get_allowed_upload_file_exts())
     self.allowed_mimetypes = kwargs.pop(
         'allowed_mimetypes',
         get_allowed_mimetypes(self.allowed_extensions))
     self.max_size = kwargs.pop('max_size',
                                get_max_file_upload_size(file_module=True))
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        context = super(FileTinymceCreateView, self).get_context_data(**kwargs)
        context['app_label'] = self.request.GET.get('app_label', '')
        context['model'] = self.request.GET.get('model', '')
        context['object_id'] = self.request.GET.get('object_id', 0)
        context['max_file_size'] = get_max_file_upload_size(file_module=True)
        context['upload_type'] = self.request.GET.get('type', '')
        context['accept_file_types'] = '|'.join(x[1:] for x in get_allowed_upload_file_exts(context['upload_type']))

        return context
Esempio n. 3
0
    def clean(self):
        # file type check
        data = self.cleaned_data
        upload_type = data.get('upload_type', u'').strip()
        file = data.get('file', None)
        allowed_exts = get_allowed_upload_file_exts(upload_type)
        ext = os.path.splitext(file.name)[-1]
        if ext not in allowed_exts:
            raise forms.ValidationError(_('{file_name} - File extension "{extension}" not supported.').format(file_name=file.name, extension=ext))

        return data
Esempio n. 4
0
    def __init__(self, *args, **kwargs):
        if 'user' in kwargs:
            self.user = kwargs.pop('user', None)
        else:
            self.user = None
        request_data = kwargs.pop('request_data')
        super(TinymceUploadForm, self).__init__(*args, **kwargs)

        if request_data.method.lower() == 'post':
            upload_type = request_data.POST.get('upload_type', 'other')
        else:
            upload_type = request_data.GET.get('upload_type', 'other')
        allowed_exts = get_allowed_upload_file_exts(upload_type)
        self.fields['file'].validators = [
            FileValidator(allowed_extensions=allowed_exts)
        ]
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     self.allowed_extensions = kwargs.pop('allowed_extensions', get_allowed_upload_file_exts())
     self.allowed_mimetypes = kwargs.pop('allowed_mimetypes', get_allowed_mimetypes(self.allowed_extensions))
     self.max_size = kwargs.pop('max_size', get_max_file_upload_size(file_module=True))
Esempio n. 6
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)
Esempio n. 7
0
 def __init__(self, *args, **kwargs):
     super(FileForm, self).__init__(*args, **kwargs)
     self.fields['file'].validators = [
         FileValidator(allowed_extensions=get_allowed_upload_file_exts(
             file_type='image'))
     ]