allura
Révision | 6df449b5a97903d2fe31711f67b9afb49f369081 (tree) |
---|---|
l'heure | 2012-05-15 00:09:12 |
Auteur | bolkimen <bolkimen@yaho...> |
Commiter | Yaroslav Luzin |
ticket:45 add file stats
@@ -183,7 +183,7 @@ class ThreadController(BaseController): | ||
183 | 183 | if not kw['text']: |
184 | 184 | flash('Your post was not saved. You must provide content.', 'error') |
185 | 185 | redirect(request.referer) |
186 | - file_info = kw.pop('file_info', None) | |
186 | + file_info = kw.get('file_info', None) | |
187 | 187 | p = self.thread.add_post(**kw) |
188 | 188 | if hasattr(file_info, 'file'): |
189 | 189 | p.attach( |
@@ -194,7 +194,8 @@ class Thread(Artifact): | ||
194 | 194 | post = self.post_class()(**kwargs) |
195 | 195 | if ignore_security or has_access(self, 'unmoderated_post')(): |
196 | 196 | log.info('Auto-approving message from %s', c.user.username) |
197 | - post.approve() | |
197 | + file_info = kw.get('file_info', None) | |
198 | + post.approve(file_info) | |
198 | 199 | else: |
199 | 200 | self.notify_moderators(post) |
200 | 201 | return post |
@@ -461,7 +462,7 @@ class Post(Message, VersionedArtifact): | ||
461 | 462 | super(Post, self).delete() |
462 | 463 | self.thread.num_replies = max(0, self.thread.num_replies - 1) |
463 | 464 | |
464 | - def approve(self): | |
465 | + def approve(self, file_info=None): | |
465 | 466 | from allura.model.notification import Notification |
466 | 467 | if self.status == 'ok': return |
467 | 468 | self.status = 'ok' |
@@ -478,7 +479,7 @@ class Post(Message, VersionedArtifact): | ||
478 | 479 | self.acl, author.project_role()._id, 'unmoderated_post') |
479 | 480 | g.post_event('discussion.new_post', self.thread_id, self._id) |
480 | 481 | artifact = self.thread.artifact or self.thread |
481 | - n = Notification.post(artifact, 'message', post=self) | |
482 | + n = Notification.post(artifact, 'message', post=self, file_info=file_info) | |
482 | 483 | if hasattr(self.discussion,"monitoring_email") and self.discussion.monitoring_email: |
483 | 484 | n.send_simple(self.discussion.monitoring_email) |
484 | 485 | session(self).flush() |
@@ -115,6 +115,17 @@ class Notification(MappedClass): | ||
115 | 115 | c.project.shortname, c.app.config.options.mount_point) |
116 | 116 | if topic == 'message': |
117 | 117 | post = kwargs.pop('post') |
118 | + text = post.text | |
119 | + file_info = kwargs.pop('file_info', None) | |
120 | + if file_info is not None: | |
121 | + MAX_READ = 1024 * 32 | |
122 | + bytecount= 0 | |
123 | + while 1: | |
124 | + data = file_info.file.read(MAX_READ) | |
125 | + if not data: break | |
126 | + bytecount += len(data) | |
127 | + text = "%s\n%s (%s bytes in %s)" % (text, file_info.filename, bytecount, file_info.type) | |
128 | + | |
118 | 129 | subject = post.subject or '' |
119 | 130 | if post.parent_id and not subject.lower().startswith('re:'): |
120 | 131 | subject = 'Re: ' + subject |
@@ -125,7 +136,7 @@ class Notification(MappedClass): | ||
125 | 136 | reply_to_address='"%s" <%s>' % ( |
126 | 137 | subject_prefix, getattr(artifact, 'email_address', 'noreply@in.sf.net')), |
127 | 138 | subject=subject_prefix + subject, |
128 | - text=post.text, | |
139 | + text=text, | |
129 | 140 | in_reply_to=post.parent_id, |
130 | 141 | author_id=author._id, |
131 | 142 | pubdate=datetime.utcnow()) |