comparison roundup/cgi/client.py @ 1358:e0bf31867fa5

support propety setting on message and file through web and email interface
author Richard Jones <richard@users.sourceforge.net>
date Sat, 11 Jan 2003 23:52:28 +0000
parents f798e4c5dd9a
children 3931614b1cce
comparison
equal deleted inserted replaced
1357:a51c2a389c13 1358:e0bf31867fa5
1 # $Id: client.py,v 1.65 2003-01-08 04:39:36 richard Exp $ 1 # $Id: client.py,v 1.66 2003-01-11 23:52:28 richard Exp $
2 2
3 __doc__ = """ 3 __doc__ = """
4 WWW request handler (also used in the stand-alone server). 4 WWW request handler (also used in the stand-alone server).
5 """ 5 """
6 6
1048 ''' 1048 '''
1049 # handle file attachments 1049 # handle file attachments
1050 files = [] 1050 files = []
1051 if self.form.has_key(':file'): 1051 if self.form.has_key(':file'):
1052 file = self.form[':file'] 1052 file = self.form[':file']
1053
1054 # if there's a filename, then we create a file
1053 if file.filename: 1055 if file.filename:
1056 # see if there are any file properties we should set
1057 file_props={};
1058 if self.form.has_key(':file_fields'):
1059 for field in self.form[':file_fields'].value.split(','):
1060 if self.form.has_key(field):
1061 if field.startswith("file_"):
1062 file_props[field[5:]] = self.form[field].value
1063 else :
1064 file_props[field] = self.form[field].value
1065
1066 # try to determine the file content-type
1054 filename = file.filename.split('\\')[-1] 1067 filename = file.filename.split('\\')[-1]
1055 mime_type = mimetypes.guess_type(filename)[0] 1068 mime_type = mimetypes.guess_type(filename)[0]
1056 if not mime_type: 1069 if not mime_type:
1057 mime_type = "application/octet-stream" 1070 mime_type = "application/octet-stream"
1071
1058 # create the new file entry 1072 # create the new file entry
1059 files.append(self.db.file.create(type=mime_type, 1073 files.append(self.db.file.create(type=mime_type,
1060 name=filename, content=file.file.read())) 1074 name=filename, content=file.file.read(), **file_props))
1061 1075
1062 # we don't want to do a message if none of the following is true... 1076 # we don't want to do a message if none of the following is true...
1063 cn = self.classname 1077 cn = self.classname
1064 cl = self.db.classes[self.classname] 1078 cl = self.db.classes[self.classname]
1065 props = cl.getprops() 1079 props = cl.getprops()
1090 # handle the messageid 1104 # handle the messageid
1091 # TODO: handle inreplyto 1105 # TODO: handle inreplyto
1092 messageid = "<%s.%s.%s@%s>"%(time.time(), random.random(), 1106 messageid = "<%s.%s.%s@%s>"%(time.time(), random.random(),
1093 self.classname, self.instance.config.MAIL_DOMAIN) 1107 self.classname, self.instance.config.MAIL_DOMAIN)
1094 1108
1109 # see if there are any message properties we should set
1110 msg_props={};
1111 if self.form.has_key(':msg_fields'):
1112 for field in self.form[':msg_fields'].value.split(','):
1113 if self.form.has_key(field):
1114 if field.startswith("msg_"):
1115 msg_props[field[4:]] = self.form[field].value
1116 else :
1117 msg_props[field] = self.form[field].value
1118
1095 # now create the message, attaching the files 1119 # now create the message, attaching the files
1096 content = '\n'.join(m) 1120 content = '\n'.join(m)
1097 message_id = self.db.msg.create(author=self.userid, 1121 message_id = self.db.msg.create(author=self.userid,
1098 recipients=[], date=date.Date('.'), summary=summary, 1122 recipients=[], date=date.Date('.'), summary=summary,
1099 content=content, files=files, messageid=messageid) 1123 content=content, files=files, messageid=messageid, **msg_props)
1100 1124
1101 # update the messages property 1125 # update the messages property
1102 return message_id, files 1126 return message_id, files
1103 1127
1104 def _post_editnode(self, nid): 1128 def _post_editnode(self, nid):

Roundup Issue Tracker: http://roundup-tracker.org/