Parent: [f15b58] (diff)

Child: [c03569] (diff)

Download this file

project_main.py    151 lines (125 with data), 4.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import difflib
import logging
from pprint import pformat
import pkg_resources
from pylons import c, request
from tg import expose, redirect, flash
from tg.decorators import with_trailing_slash
from webob import exc
from allura import version
from allura.app import Application, WidgetController, ConfigOption, SitemapEntry
from allura.lib import helpers as h
from allura.controllers import BaseController
from allura.ext.project_home import model as M
from allura import model
from allura.lib.security import require, require_access
from allura.lib.decorators import require_post
from allura.lib.widgets.project_list import ProjectScreenshots
log = logging.getLogger(__name__)
class W:
screenshot_list = ProjectScreenshots()
class ProjectWidgets(WidgetController):
widgets=['welcome']
def __init__(self, app): pass
def welcome(self):
return self.portlet('<p><!-- Please configure your widgets --></p>')
class ProjectHomeApp(Application):
__version__ = version.__version__
widget = ProjectWidgets
installable = False
tool_label = 'home'
default_mount_label='Project Home'
icons={
24:'images/home_24.png',
32:'images/home_32.png',
48:'images/home_48.png'
}
def __init__(self, project, config):
Application.__init__(self, project, config)
self.root = ProjectHomeController()
self.api_root = RootRestController()
self.templates = pkg_resources.resource_filename(
'allura.ext.project_home', 'templates')
def is_visible_to(self, user):
'''Whether the user can view the app.'''
return True
@property
@h.exceptionless([], log)
def sitemap(self):
menu_id = 'Home'
return [
SitemapEntry('Home', '.') ]
@h.exceptionless([], log)
def sidebar_menu(self):
return [ SitemapEntry('Configure', 'configuration')]
def admin_menu(self):
return []
def install(self, project):
pr = c.user.project_role()
if pr:
self.config.acl = [
model.ACE.allow(pr._id, perm)
for perm in self.permissions ]
def uninstall(self, project): # pragma no cover
raise NotImplementedError, "uninstall"
class ProjectHomeController(BaseController):
def _check_security(self):
require_access(c.project, 'read')
@with_trailing_slash
@expose('jinja:allura.ext.project_home:templates/project_index.html')
def index(self, **kw):
config = M.PortalConfig.current()
c.screenshot_list = W.screenshot_list
return dict(
layout_class=config.layout_class,
layout=config.rendered_layout())
@expose('jinja:allura.ext.project_home:templates/project_dashboard_configuration.html')
def configuration(self):
config = M.PortalConfig.current()
mount_points = [
(ac.options.mount_point, ac.load())
for ac in c.project.app_configs ]
widget_types = [
dict(mount_point=mp, widget_name=w)
for mp, app_class in mount_points
for w in app_class.widget.widgets ]
return dict(
layout_class=config.layout_class,
layout=config.layout,
widget_types=widget_types)
@h.vardec
@expose()
@require_post()
def update_configuration(self, divs=None, layout_class=None, new_div=None, **kw):
require_access(c.project, 'update')
config = M.PortalConfig.current()
config.layout_class = layout_class
# Handle updated and deleted divs
if divs is None: divs = []
new_divs = []
for div in divs:
log.info('Got div update:%s', pformat(div))
if div.get('del'): continue
new_divs.append(div)
# Handle new divs
if new_div:
new_divs.append(dict(name=h.nonce(), content=[]))
config.layout = []
for div in new_divs:
content = []
for w in div.get('content', []):
if w.get('del'): continue
mp,wn = w['widget'].split('/')
content.append(dict(mount_point=mp, widget_name=wn))
if div.get('new_widget'):
content.append(dict(mount_point='home', widget_name='welcome'))
config.layout.append(dict(
name=div['name'],
content=content))
redirect('configuration')
class RootRestController(BaseController):
def _check_security(self):
require_access(c.project, 'read')
@expose('json:')
def index(self, **kwargs):
return dict(shortname=c.project.shortname)