##// END OF EJS Templates
Properly order attachments across one post
Properly order attachments across one post

File last commit:

r1757:d84474c9 default
r1759:eaa1de72 default
Show More
fields.py
42 lines | 1.3 KiB | text/x-python | PythonLexer
from django import forms
from django.utils.translation import ugettext_lazy as _, ungettext_lazy
ATTRIBUTE_PLACEHOLDER = 'placeholder'
class UrlFileWidget(forms.MultiWidget):
def __init__(self, *args, **kwargs):
widgets = (
forms.ClearableFileInput(attrs={'accept': 'file/*'}),
forms.TextInput(attrs={ATTRIBUTE_PLACEHOLDER:
'http://example.com/image.png'}),
)
super().__init__(widgets, *args, **kwargs)
def decompress(self, value):
return [None, None]
class UrlFileField(forms.MultiValueField):
widget = UrlFileWidget
def __init__(self, *args, **kwargs):
fields = (
forms.FileField(required=False, label=_('File'),
widget=forms.ClearableFileInput(
attrs={'accept': 'file/*'})),
forms.CharField(required=False, label=_('File URL'),
widget=forms.TextInput(
attrs={ATTRIBUTE_PLACEHOLDER:
'http://example.com/image.png'})),
)
super().__init__(
fields=fields,
require_all_fields=False, *args, **kwargs)
def compress(self, data_list):
if data_list and len(data_list) >= 2:
return data_list[0] or data_list[1]