Parent: [bea16d] (diff)

Child: [fca687] (diff)

Download this file

project_list.py    166 lines (147 with data), 6.4 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import ew as ew_core
import ew.jinja2_ew as ew
from pylons import tmpl_context as c, app_globals as g
from allura import model as M
from allura.lib.security import Credentials
class ProjectSummary(ew_core.Widget):
template='jinja:allura:templates/widgets/project_summary.html'
defaults=dict(
ew_core.Widget.defaults,
sitemap=None,
icon=None,
value=None,
icon_url=None,
accolades=None,
columns=1,
show_proj_icon=True,
show_download_button=True,
show_awards_banner=True,
grid_view_tools='')
def prepare_context(self, context):
response = super(ProjectSummary, self).prepare_context(context)
value = response['value']
if response['sitemap'] is None:
response['sitemap'] = [ s for s in value.sitemap() if s.url ]
if response['grid_view_tools'] != '':
view_tools_list = response['grid_view_tools'].split(',')
icon_tool_list = ["tool-%s" % vt.lower() for vt in view_tools_list]
old_sitemap = response['sitemap']
response['sitemap'] = []
for sm in old_sitemap:
if sm.ui_icon is not None and sm.ui_icon.lower() in icon_tool_list:
response['sitemap'].append(sm)
if response['icon_url'] is None:
if value.icon:
response['icon_url'] = value.url()+'icon'
if response['accolades'] is None:
response['accolades'] = value.accolades
if type(response['columns']) == unicode:
response['columns'] = int(response['columns'])
true_list = ['true', 't', '1', 'yes', 'y']
if type(response['show_proj_icon']) == unicode:
if response['show_proj_icon'].lower() in true_list:
response['show_proj_icon'] = True
else:
response['show_proj_icon'] = False
if type(response['show_download_button']) == unicode:
if response['show_download_button'].lower() in true_list:
response['show_download_button'] = True
else:
response['show_download_button'] = False
if type(response['show_awards_banner']) == unicode:
if response['show_awards_banner'].lower() in true_list:
response['show_awards_banner'] = True
else:
response['show_awards_banner'] = False
return response
def resources(self):
yield ew.JSLink('js/jquery.tools.min.js')
yield ew.JSScript('''
$(document).ready(function () {
var badges = $('small.badge');
var i = badges.length;
while (i) {
i--;
var tipHolder = document.createElement('div');
tipHolder.id = "tip" + i;
tipHolder.className = "tip";
document.body.appendChild(tipHolder);
$(badges[i]).parent('a[title]').tooltip({
tip: '#tip' + i,
opacity: '.9',
offset: [-10, 0]
});
}
});
''')
class ProjectList(ew_core.Widget):
template='jinja:allura:templates/widgets/project_list_widget.html'
defaults=dict(
ew_core.Widget.defaults,
projects=[],
project_summary=ProjectSummary(),
display_mode='list',
sitemaps=None,
icon_urls=None,
accolades_index=None,
columns=1,
show_proj_icon=True,
show_download_button=True,
show_awards_banner=True,
grid_view_tools='')
def prepare_context(self, context):
response = super(ProjectList, self).prepare_context(context)
cred = Credentials.get()
projects = response['projects']
cred.load_user_roles(c.user._id, *[p._id for p in projects])
cred.load_project_roles(*[p._id for p in projects])
if response['sitemaps'] is None:
response['sitemaps'] = M.Project.menus(projects)
if response['icon_urls'] is None:
response['icon_urls'] = M.Project.icon_urls(projects)
if response['accolades_index'] is None:
response['accolades_index'] = M.Project.accolades_index(projects)
if type(response['columns']) == unicode:
response['columns'] = int(response['columns'])
true_list = ['true', 't', '1', 'yes', 'y']
if type(response['show_proj_icon']) == unicode:
if response['show_proj_icon'].lower() in true_list:
response['show_proj_icon'] = True
else:
response['show_proj_icon'] = False
if type(response['show_download_button']) == unicode:
if response['show_download_button'].lower() in true_list:
response['show_download_button'] = True
else:
response['show_download_button'] = False
if type(response['show_awards_banner']) == unicode:
if response['show_awards_banner'].lower() in true_list:
response['show_awards_banner'] = True
else:
response['show_awards_banner'] = False
return response
def resources(self):
for r in self.project_summary.resources():
yield r
class ProjectScreenshots(ew_core.Widget):
template='jinja:allura:templates/widgets/project_screenshots.html'
defaults=dict(
ew_core.Widget.defaults,
project=None,
edit=False)