File: validatePosting.py

package info (click to toggle)
squishdot 1.3.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 896 kB
  • ctags: 349
  • sloc: python: 2,313; makefile: 56; sh: 54
file content (50 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
## Script (Python) "validate"
##title=Validate Postings
##parameters=raw=None

if raw is None:
    # being called from previewPosting
    raw = context.REQUEST
    posting = context.dummyPosting()
else:
    posting = context
    
Processed = {}

# get the encoding and specify a site default
encoding = raw.get('encoding','HTML')
Processed['encoding']=encoding

# get fields and make their html safe
for field in posting.getFields():
    value = raw.get(field,None)
    if value is not None:
        if encoding!='Plain':
            value = context.html2safehtml(value)
        Processed[field]=value

# stick notify in processed
Processed['notify']=raw.get('notify','')

# integrity checks
if raw.get('notify') and not raw.get('email'):
    return Processed,'You must enter an email address for notification!'

if   posting.meta_type=='Article':
    
    if not raw.get('title') or \
       not raw.get('author') or \
       not raw.get('subject') or \
       not raw.get('summary'):
        
        return Processed,'You must enter a title, author, subject and summary!'

elif posting.meta_type=='Comment':
    
    if not raw.get('title') or \
       not raw.get('author') or \
       not raw.get('body'):

        return Processed,'You must enter a title, author and body!'

return Processed,None