Switch to unified view

a/Allura/allura/controllers/discuss.py b/Allura/allura/controllers/discuss.py
1
from mimetypes import guess_type
2
from urllib import unquote
1
from urllib import unquote
3
from datetime import datetime
2
from datetime import datetime
4
3
5
from tg import expose, redirect, validate, request, response, flash
4
from tg import expose, redirect, validate, request, response, flash
6
from tg.decorators import before_validate, with_trailing_slash, without_trailing_slash
5
from tg.decorators import before_validate, with_trailing_slash, without_trailing_slash
...
...
11
from ming.base import Object
10
from ming.base import Object
12
from ming.utils import LazyProperty
11
from ming.utils import LazyProperty
13
12
14
from allura import model as M
13
from allura import model as M
15
from base import BaseController
14
from base import BaseController
15
from allura.lib import utils
16
from allura.lib import helpers as h
16
from allura.lib import helpers as h
17
from allura.lib.security import require, has_artifact_access
17
from allura.lib.security import require, has_artifact_access
18
from allura.lib.helpers import DateTimeConverter
18
from allura.lib.helpers import DateTimeConverter
19
19
20
from allura.lib.widgets import discuss as DW
20
from allura.lib.widgets import discuss as DW
...
...
292
    @h.vardec
292
    @h.vardec
293
    @expose()
293
    @expose()
294
    def attach(self, file_info=None):
294
    def attach(self, file_info=None):
295
        require(has_artifact_access('moderate', self.post))
295
        require(has_artifact_access('moderate', self.post))
296
        if hasattr(file_info, 'file'):
296
        if hasattr(file_info, 'file'):
297
            mime_type = file_info.type
298
            # If mime type was not passed or bogus, guess it
299
            if not mime_type or '/' not in mime_type:
300
                mime_type = utils.guess_mime_type(file_info.filename)
297
            self.post.attach(
301
            self.post.attach(
298
                file_info.filename, file_info.file, content_type=file_info.type,
302
                file_info.filename, file_info.file, content_type=mime_type,
299
                post_id=self.post._id,
303
                post_id=self.post._id,
300
                thread_id=self.post.thread_id,
304
                thread_id=self.post.thread_id,
301
                discussion_id=self.post.discussion_id)
305
                discussion_id=self.post.discussion_id)
302
        redirect(request.referer)
306
        redirect(request.referer)
303
307