Vieux vieux bug…
[Plinn.git] / skins / custom_content / metadata_edit_control.py
1 ##parameters=allow_discussion=None, title=None, subject=None, description=None, contributors=None, effective_date=None, expiration_date=None, format=None, language=None, rights=None, ajax='', **kw
2 ##
3 from Products.CMFCore.utils import getToolByName
4 from Products.CMFDefault.exceptions import ResourceLockedError
5
6 dtool = getToolByName(script, 'portal_discussion')
7
8 def tuplify( value ):
9
10 if not same_type( value, () ):
11 value = tuple( value )
12
13 temp = filter( None, value )
14 return tuple( temp )
15
16 if title is None:
17 title = context.Title()
18
19 if subject is None:
20 subject = context.Subject()
21 else:
22 subject = tuplify( subject )
23
24 if description is None:
25 description = context.Description()
26
27 if contributors is None:
28 contributors = context.Contributors()
29 else:
30 contributors = tuplify( contributors )
31
32 if effective_date is None:
33 effective_date = context.effective()
34 else :
35 if dict(effective_date) == {'year':'1969', 'month':'12', 'day':'31', 'hour':'00', 'minute':'00'} :
36 effective_date = None
37 else :
38 effective_date = '%(year)s/%(month)s/%(day)s %(hour)s:%(minute)s' % effective_date
39
40 if expiration_date is None:
41 expiration_date = context.expires()
42 else :
43 expiration_date = '%(year)s/%(month)s/%(day)s %(hour)s:%(minute)s' % expiration_date
44
45
46 if format is None:
47 format = context.Format()
48
49 if language is None:
50 language = context.Language()
51
52 if rights is None:
53 rights = context.Rights()
54
55 if allow_discussion is not None :
56 if allow_discussion == 'default':
57 allow_discussion = None
58 if allow_discussion == 'off':
59 allow_discussion = False
60 elif allow_discussion == 'on':
61 allow_discussion = True
62 dtool.overrideDiscussionFor(context, allow_discussion)
63
64 try:
65 context.editMetadata( title=title
66 , description=description
67 , subject=subject
68 , contributors=contributors
69 , effective_date=effective_date
70 , expiration_date=expiration_date
71 , format=format
72 , language=language
73 , rights=rights
74 )
75 if ajax : return '...'
76 context.setStatus(True, 'Metadata changed.')
77 return context.setRedirect(context, 'object/edit')
78 except ResourceLockedError, errmsg:
79 return False