0004-formdef-rewrite-update_mimetypes-as-update_filetype-.patch
tests/test_admin_pages.py | ||
---|---|---|
2201 | 2201 |
formdef.name = 'form title' |
2202 | 2202 |
formdef.fields = [fields.FileField( |
2203 | 2203 |
id='1', label='1st field', type='file', |
2204 |
file_type=['application/pdf,application/msword'])] |
|
2204 |
document_type={ |
|
2205 |
'id': 1, |
|
2206 |
'mimetypes': ['application/pdf', 'application/msword'], |
|
2207 |
'label': 'Text files', |
|
2208 |
})] |
|
2205 | 2209 |
formdef.store() |
2206 |
assert FormDef.get(formdef.id).fields[0].file_type == ['application/pdf,application/msword'] |
|
2210 |
assert FormDef.get(formdef.id).fields[0].document_type == { |
|
2211 |
'id': 1, |
|
2212 |
'mimetypes': ['application/pdf', 'application/msword'], |
|
2213 |
'label': 'Text files', |
|
2214 |
} |
|
2207 | 2215 | |
2208 | 2216 |
resp = resp.click('Text files') |
2209 | 2217 |
resp.forms[0]['mimetypes'] = 'application/vnd.oasis.opendocument.text, .doc, .docx, .pdf' |
2210 | 2218 |
resp = resp.forms[0].submit('submit') |
2211 | 2219 |
assert 'application/pdf' in pub.cfg['filetypes'][1]['mimetypes'] |
2212 |
assert FormDef.get(formdef.id).fields[0].file_type == ['application/vnd.oasis.opendocument.text,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf'] |
|
2220 |
assert FormDef.get(formdef.id).fields[0].document_type == { |
|
2221 |
'id': 1, |
|
2222 |
'mimetypes': ['application/vnd.oasis.opendocument.text', |
|
2223 |
'application/msword', |
|
2224 |
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
2225 |
'application/pdf' ], |
|
2226 |
'label': 'Text files', |
|
2227 |
} |
|
2228 | ||
2213 | 2229 | |
2214 | 2230 |
def test_data_sources(pub): |
2215 | 2231 |
create_superuser(pub) |
wcs/admin/settings.py | ||
---|---|---|
324 | 324 |
return redirect('.') |
325 | 325 | |
326 | 326 |
if form.get_submit() == 'submit': |
327 |
old_filetype = filetype.copy() |
|
327 | 328 |
filetype['label'] = form.get_widget('label').parse() |
328 |
previous_mimetypes = filetype['mimetypes'] |
|
329 | 329 |
filetype['mimetypes'] = self.parse_mimetypes(form.get_widget('mimetypes').parse()) |
330 |
FormDef.update_mimetypes(previous_mimetypes, filetype['mimetypes'])
|
|
330 |
FormDef.update_filetype(filetype_id, old_filetype, filetype)
|
|
331 | 331 |
get_publisher().write_cfg() |
332 | 332 |
return redirect('.') |
333 | 333 |
wcs/formdef.py | ||
---|---|---|
957 | 957 |
return False |
958 | 958 | |
959 | 959 |
@classmethod |
960 |
def update_mimetypes(cls, previous_mimetypes, new_mimetypes):
|
|
960 |
def update_filetype(cls, filetype_id, previous_filetype, new_filetype):
|
|
961 | 961 |
# look for file fields in all formdefs, to update them with the |
962 | 962 |
# new mimetypes. |
963 |
if previous_mimetypes == new_mimetypes:
|
|
963 |
if previous_filetype == new_filetype:
|
|
964 | 964 |
return |
965 |
previous_mimetypes = ','.join(previous_mimetypes) |
|
966 |
new_mimetypes = ','.join(new_mimetypes) |
|
967 | 965 |
for formdef in cls.select(): |
968 | 966 |
changed = False |
969 | 967 |
for field in formdef.fields: |
970 |
if not hasattr(field, 'file_type'):
|
|
968 |
if not hasattr(field, 'document_type'):
|
|
971 | 969 |
continue |
972 |
if not field.file_type:
|
|
970 |
if not field.document_type:
|
|
973 | 971 |
continue |
974 |
if previous_mimetypes in field.file_type: |
|
975 |
field.file_type.remove(previous_mimetypes) |
|
976 |
field.file_type.append(new_mimetypes) |
|
972 |
if field.document_type['id'] == filetype_id: |
|
973 |
previous_filetype = field.document_type.copy() |
|
974 |
del previous_filetype['id'] |
|
975 |
if previous_filetype == new_filetype: |
|
976 |
continue |
|
977 |
field.document_type = new_filetype.copy() |
|
978 |
field.document_type['id'] = filetype_id |
|
977 | 979 |
changed = True |
978 | 980 |
if changed: |
979 | 981 |
formdef.store() |
980 |
- |