Parent: [d69cb3] (diff)

Child: [573203] (diff)

Download this file

dl_main.py    111 lines (90 with data), 3.7 kB

  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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#-*- python -*-
import logging
# Non-stdlib imports
import pkg_resources
from tg import expose, validate, redirect, response, config
from tg.decorators import with_trailing_slash, without_trailing_slash
from pylons import g, c, request
# Pyforge-specific imports
from allura.app import Application, ConfigOption, SitemapEntry, DefaultAdminController
from allura.lib import helpers as h
from allura.lib.security import require, has_artifact_access
from allura.model import ProjectRole
from allura.controllers import BaseController
# Local imports
from forgedownloads import version
log = logging.getLogger(__name__)
class ForgeDownloadsApp(Application):
__version__ = version.__version__
permissions = [ 'configure', 'read' ]
searchable=True
# installable=config['auth.method'] == 'sfx'
templates=None
tool_label='Downloads'
default_mount_label='Downloads'
default_mount_point='downloads'
ordinal=8
def __init__(self, project, config):
Application.__init__(self, project, config)
self.root = RootController()
self.admin = DownloadAdminController(self)
@property
@h.exceptionless([], log)
def sitemap(self):
menu_id = self.config.options.mount_label.title()
url='/downloads/' + c.project.get_tool_data('sfx', 'unix_group_name') + '/'
return [SitemapEntry(menu_id, url)[self.sidebar_menu()] ]
def sidebar_menu(self):
return []
def admin_menu(self):
admin_url = c.project.url()+'admin/'+self.config.options.mount_point+'/'
links = super(ForgeDownloadsApp, self).admin_menu()
if has_artifact_access('configure', app=self)():
links.append(SitemapEntry('Options', admin_url + 'options', className='nav_child'))
return links
def install(self, project):
'Set up any default permissions and roles here'
super(ForgeDownloadsApp, self).install(project)
# Setup permissions
role_anon = ProjectRole.anonymous()._id
c.project.show_download_button = True
self.config.acl.update(
configure=c.project.acl['tool'],
read=[role_anon])
def uninstall(self, project):
"Remove all the tool's artifacts from the database"
c.project.show_download_button = False
super(ForgeDownloadsApp, self).uninstall(project)
class RootController(BaseController):
def __init__(self):
setattr(self, 'nav.json', self.nav)
@expose('json:')
def nav(self):
if c.app.sitemap:
my_entry = c.app.sitemap[0]
else:
my_entry = None
def _entry(s):
d = dict(name=s.label, url=s.url, icon=s.ui_icon)
if my_entry and s.url == my_entry.url:
d['selected'] = True
return d
return dict(menu=[ _entry(s) for s in c.project.sitemap() ] )
class DownloadAdminController(DefaultAdminController):
def _check_security(self):
require(has_artifact_access('configure', app=self.app), 'Requires permission to "configure"')
@with_trailing_slash
def index(self, **kw):
redirect('options')
@expose('jinja:downloads/admin_options.html')
def options(self):
return dict(app=self.app,
allow_config=has_artifact_access('configure', app=self.app)())
@h.vardec
@expose()
def update_options(self, **kw):
show_download_button = kw.pop('show_download_button', '')
if bool(show_download_button) != c.project.show_download_button:
h.log_action(log, 'update project download button').info('')
c.project.show_download_button = bool(show_download_button)
redirect(request.referrer)