|
a/Allura/allura/controllers/project.py |
|
b/Allura/allura/controllers/project.py |
|
... |
|
... |
8 |
from tg import expose, flash, redirect, validate, request, response
|
8 |
from tg import expose, flash, redirect, validate, request, response
|
9 |
from tg.decorators import with_trailing_slash, without_trailing_slash
|
9 |
from tg.decorators import with_trailing_slash, without_trailing_slash
|
10 |
from pylons import c, g
|
10 |
from pylons import c, g
|
11 |
from paste.httpheaders import CACHE_CONTROL
|
11 |
from paste.httpheaders import CACHE_CONTROL
|
12 |
from webob import exc
|
12 |
from webob import exc
|
13 |
from pymongo.bson import ObjectId
|
13 |
from bson import ObjectId
|
14 |
import pymongo
|
14 |
import pymongo
|
15 |
from formencode import validators
|
15 |
from formencode import validators
|
16 |
|
16 |
|
17 |
import ming.orm.ormsession
|
17 |
import ming.orm.ormsession
|
|
|
18 |
from ming.utils import LazyProperty
|
18 |
|
19 |
|
19 |
import allura
|
20 |
import allura
|
20 |
from allura import model as M
|
21 |
from allura import model as M
|
21 |
from allura.app import SitemapEntry
|
22 |
from allura.app import SitemapEntry
|
22 |
from allura.lib.base import BaseController
|
23 |
from allura.lib.base import BaseController
|
|
... |
|
... |
182 |
@expose()
|
183 |
@expose()
|
183 |
def icon(self):
|
184 |
def icon(self):
|
184 |
icon = self.neighborhood.icon
|
185 |
icon = self.neighborhood.icon
|
185 |
if not icon:
|
186 |
if not icon:
|
186 |
raise exc.HTTPNotFound
|
187 |
raise exc.HTTPNotFound
|
187 |
with icon.open() as fp:
|
|
|
188 |
filename = fp.metadata['filename'].encode('utf-8')
|
|
|
189 |
response.headers['Content-Type'] = ''
|
|
|
190 |
response.content_type = fp.content_type.encode('utf-8')
|
|
|
191 |
return fp.read()
|
|
|
192 |
return icon.filename
|
188 |
return icon.serve()
|
193 |
|
189 |
|
194 |
class NeighborhoodProjectBrowseController(ProjectBrowseController):
|
190 |
class NeighborhoodProjectBrowseController(ProjectBrowseController):
|
195 |
def __init__(self, neighborhood=None, category_name=None, parent_category=None):
|
191 |
def __init__(self, neighborhood=None, category_name=None, parent_category=None):
|
196 |
self.neighborhood = neighborhood
|
192 |
self.neighborhood = neighborhood
|
197 |
super(NeighborhoodProjectBrowseController, self).__init__(category_name=category_name, parent_category=parent_category)
|
193 |
super(NeighborhoodProjectBrowseController, self).__init__(category_name=category_name, parent_category=parent_category)
|
|
... |
|
... |
307 |
@expose()
|
303 |
@expose()
|
308 |
def icon(self):
|
304 |
def icon(self):
|
309 |
icon = c.project.icon
|
305 |
icon = c.project.icon
|
310 |
if not icon:
|
306 |
if not icon:
|
311 |
raise exc.HTTPNotFound
|
307 |
raise exc.HTTPNotFound
|
312 |
with icon.open() as fp:
|
|
|
313 |
filename = fp.metadata['filename'].encode('utf-8')
|
|
|
314 |
response.headers['Content-Type'] = ''
|
|
|
315 |
response.content_type = fp.content_type.encode('utf-8')
|
|
|
316 |
return fp.read()
|
|
|
317 |
return icon.filename
|
308 |
return icon.serve()
|
318 |
|
309 |
|
319 |
@expose()
|
310 |
@expose()
|
320 |
def user_icon(self):
|
311 |
def user_icon(self):
|
321 |
try:
|
312 |
try:
|
322 |
return self.icon()
|
313 |
return self.icon()
|
|
... |
|
... |
337 |
|
328 |
|
338 |
class ScreenshotsController(object):
|
329 |
class ScreenshotsController(object):
|
339 |
|
330 |
|
340 |
@expose()
|
331 |
@expose()
|
341 |
def _lookup(self, filename, *args):
|
332 |
def _lookup(self, filename, *args):
|
|
|
333 |
if args:
|
342 |
filename=unquote(filename)
|
334 |
filename=unquote(filename)
|
|
|
335 |
else:
|
|
|
336 |
filename = unquote(request.path.rsplit('/', 1)[-1])
|
343 |
return ScreenshotController(filename), args
|
337 |
return ScreenshotController(filename), args
|
344 |
|
338 |
|
345 |
class ScreenshotController(object):
|
339 |
class ScreenshotController(object):
|
346 |
|
340 |
|
347 |
def __init__(self, filename):
|
341 |
def __init__(self, filename):
|
348 |
self.filename = filename
|
342 |
self.filename = filename
|
349 |
|
343 |
|
350 |
@expose()
|
344 |
@expose()
|
351 |
def index(self, embed=True, **kw):
|
345 |
def index(self, embed=True, **kw):
|
352 |
screenshot = M.ProjectFile.query.find({'metadata.project_id':c.project._id, 'metadata.category':'screenshot', 'filename':self.filename}).first()
|
346 |
return self._screenshot.serve(embed)
|
353 |
with screenshot.open() as fp:
|
|
|
354 |
filename = fp.metadata['filename'].encode('utf-8')
|
|
|
355 |
response.headers['Content-Type'] = ''
|
|
|
356 |
response.content_type = fp.content_type.encode('utf-8')
|
|
|
357 |
if not embed:
|
|
|
358 |
response.headers.add('Content-Disposition',
|
|
|
359 |
'attachment;filename=%s' % filename)
|
|
|
360 |
return fp.read()
|
|
|
361 |
return self.filename
|
|
|
362 |
|
347 |
|
363 |
@expose()
|
348 |
@expose()
|
364 |
def thumb(self, embed=True):
|
349 |
def thumb(self, embed=True):
|
365 |
thumb = M.ProjectFile.query.find({'metadata.project_id':c.project._id, 'metadata.category':'screenshot_thumb', 'metadata.filename':self.filename}).first()
|
350 |
return self._thumb.serve(embed)
|
366 |
with thumb.open() as fp:
|
351 |
|
367 |
filename = fp.metadata['filename'].encode('utf-8')
|
352 |
@LazyProperty
|
368 |
response.headers['Content-Type'] = ''
|
353 |
def _screenshot(self):
|
369 |
response.content_type = fp.content_type.encode('utf-8')
|
354 |
f = M.ProjectFile.query.get(
|
370 |
if not embed:
|
355 |
project_id=c.project._id,
|
371 |
response.headers.add('Content-Disposition',
|
356 |
category='screenshot',
|
372 |
'attachment;filename=%s' % filename)
|
357 |
filename=self.filename)
|
373 |
return fp.read()
|
358 |
if not f: raise exc.HTTPNotFound
|
374 |
return self.filename
|
359 |
return f
|
|
|
360 |
|
|
|
361 |
@LazyProperty
|
|
|
362 |
def _thumb(self):
|
|
|
363 |
f = M.ProjectFile.query.get(
|
|
|
364 |
project_id=c.project._id,
|
|
|
365 |
category='screenshot_thumb',
|
|
|
366 |
filename=self.filename)
|
|
|
367 |
if not f: raise exc.HTTPNotFound
|
|
|
368 |
return f
|
375 |
|
369 |
|
376 |
class NeighborhoodAdminController(object):
|
370 |
class NeighborhoodAdminController(object):
|
377 |
|
371 |
|
378 |
def __init__(self, neighborhood):
|
372 |
def __init__(self, neighborhood):
|
379 |
self.neighborhood = neighborhood
|
373 |
self.neighborhood = neighborhood
|
|
... |
|
... |
442 |
self.neighborhood.homepage = homepage
|
436 |
self.neighborhood.homepage = homepage
|
443 |
self.neighborhood.css = css
|
437 |
self.neighborhood.css = css
|
444 |
self.neighborhood.allow_browse = 'allow_browse' in kw
|
438 |
self.neighborhood.allow_browse = 'allow_browse' in kw
|
445 |
if icon is not None and icon != '':
|
439 |
if icon is not None and icon != '':
|
446 |
if self.neighborhood.icon:
|
440 |
if self.neighborhood.icon:
|
447 |
M.NeighborhoodFile.query.remove({'metadata.neighborhood_id':self.neighborhood._id})
|
441 |
self.neighborhood.icon.delete()
|
448 |
M.NeighborhoodFile.save_image(
|
442 |
M.NeighborhoodFile.save_image(
|
449 |
icon.filename, icon.file, content_type=icon.type,
|
443 |
icon.filename, icon.file, content_type=icon.type,
|
450 |
square=True, thumbnail_size=(48,48),
|
444 |
square=True, thumbnail_size=(48,48),
|
451 |
thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
|
445 |
thumbnail_meta=dict(neighborhood_id=self.neighborhood._id))
|
452 |
redirect('overview')
|
446 |
redirect('overview')
|
|
... |
|
... |
614 |
@expose()
|
608 |
@expose()
|
615 |
def icon(self):
|
609 |
def icon(self):
|
616 |
icon = self.award.icon
|
610 |
icon = self.award.icon
|
617 |
if not icon:
|
611 |
if not icon:
|
618 |
raise exc.HTTPNotFound
|
612 |
raise exc.HTTPNotFound
|
619 |
with icon.open() as fp:
|
|
|
620 |
filename = fp.metadata['filename'].encode('utf-8')
|
|
|
621 |
response.headers['Content-Type'] = ''
|
|
|
622 |
response.content_type = fp.content_type.encode('utf-8')
|
|
|
623 |
return fp.read()
|
|
|
624 |
return icon.filename
|
613 |
return icon.serve()
|
625 |
|
614 |
|
626 |
@expose()
|
615 |
@expose()
|
627 |
def grant(self, recipient=None):
|
616 |
def grant(self, recipient=None):
|
628 |
if request.method != 'POST':
|
617 |
if request.method != 'POST':
|
629 |
raise Exception('award_grant must be a POST request')
|
618 |
raise Exception('award_grant must be a POST request')
|
|
... |
|
... |
640 |
def delete(self):
|
629 |
def delete(self):
|
641 |
if self.award:
|
630 |
if self.award:
|
642 |
grants = M.AwardGrant.query.find(dict(award_id=self.award._id))
|
631 |
grants = M.AwardGrant.query.find(dict(award_id=self.award._id))
|
643 |
for grant in grants:
|
632 |
for grant in grants:
|
644 |
grant.delete()
|
633 |
grant.delete()
|
645 |
M.AwardFile.query.remove({'metadata.award_id':self.award._id})
|
634 |
M.AwardFile.query.remove(dict(award_id=self.award._id))
|
646 |
self.award.delete()
|
635 |
self.award.delete()
|
647 |
redirect('../..')
|
636 |
redirect('../..')
|
648 |
|
637 |
|
649 |
class GrantController(object):
|
638 |
class GrantController(object):
|
650 |
|
639 |
|
|
... |
|
... |
671 |
@expose()
|
660 |
@expose()
|
672 |
def icon(self):
|
661 |
def icon(self):
|
673 |
icon = self.award.icon
|
662 |
icon = self.award.icon
|
674 |
if not icon:
|
663 |
if not icon:
|
675 |
raise exc.HTTPNotFound
|
664 |
raise exc.HTTPNotFound
|
676 |
with icon.open() as fp:
|
|
|
677 |
filename = fp.metadata['filename'].encode('utf-8')
|
|
|
678 |
response.headers['Content-Type'] = ''
|
|
|
679 |
response.content_type = fp.content_type.encode('utf-8')
|
|
|
680 |
return fp.read()
|
|
|
681 |
return icon.filename
|
665 |
return icon.serve()
|
682 |
|
666 |
|
683 |
@expose()
|
667 |
@expose()
|
684 |
def revoke(self):
|
668 |
def revoke(self):
|
685 |
self.grant.delete()
|
669 |
self.grant.delete()
|
686 |
redirect(request.referer)
|
670 |
redirect(request.referer)
|