Changeset 3169 in products
- Timestamp:
- Apr 21, 2011 2:53:26 PM (13 years ago)
- Location:
- quintagroup.analytics/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.analytics/trunk/quintagroup/analytics/browser/views.py
r3029 r3169 14 14 except ImportError: 15 15 "Before plon4 we don't have an annotation storage for settings." 16 IPortletAssignmentSettings = lambda assignment: {}16 IPortletAssignmentSettings = lambda assignment: {} 17 17 18 18 from GChartWrapper import VerticalBarStack 19 19 20 20 from quintagroup.analytics.config import COLORS, OTHER_TYPES, NO_WF_BIND 21 21 22 22 23 class OwnershipByType(BrowserView): 23 24 MAX = 10 25 24 26 def __init__(self, context, request): 25 27 self.context = context … … 87 89 for type_ in types: 88 90 data.append(self.getContent(type_)) 89 other = [self.getContent(t) for t in self.getTypes(all=True)[self.MAX:]] 91 other = [self.getContent(t) for t in self.getTypes( 92 all=True)[self.MAX:]] 90 93 if other: 91 94 data.append([sum(l) for l in zip(*other)]) 92 95 max_value = max(self.getTotal()) 93 96 chart = VerticalBarStack(data, encoding='text') 94 types = other and types +OTHER_TYPES or types97 types = other and types + OTHER_TYPES or types 95 98 chart.title('Content ownership by type').legend(*(types)) 96 99 chart.bar('a', 10, 0).legend_pos("b") 97 100 chart.color(*COLORS) 98 chart.size(800, 375).scale(0, max_value).axes('xy').label(*self.users)101 chart.size(800, 375).scale(0, max_value).axes('xy').label(*self.users) 99 102 chart.axes.type("y") 100 chart.axes.range(0, 0,max_value)103 chart.axes.range(0, 0, max_value) 101 104 return chart.img() 102 105 … … 104 107 class OwnershipByState(BrowserView): 105 108 MAX = 10 109 106 110 def __init__(self, context, request): 107 111 self.context = context … … 160 164 data.append(l) 161 165 if len(data) > 0: 162 self.data[NO_WF_BIND] = map(lambda t,d:t-d, self.data[NO_WF_BIND], data) 166 self.data[NO_WF_BIND] = map(lambda t, d: t - d, 167 self.data[NO_WF_BIND], data) 163 168 return self.data[type_] 164 169 … … 181 186 max_value = max(self.getTotal()) 182 187 chart = VerticalBarStack(data, encoding='text') 183 chart.title('Content ownership by state').legend(*self.states+[NO_WF_BIND]) 188 title = 'Content ownership by state' 189 chart.title(title).legend(*self.states + [NO_WF_BIND]) 184 190 chart.bar('a', 10, 0).legend_pos("b") 185 191 chart.color(*COLORS) 186 chart.size(800, 375).scale(0, max_value).axes('xy').label(*self.users)192 chart.size(800, 375).scale(0, max_value).axes('xy').label(*self.users) 187 193 chart.axes.type("y") 188 chart.axes.range(0, 0,max_value)194 chart.axes.range(0, 0, max_value) 189 195 return chart.img() 190 196 … … 192 198 class TypeByState(BrowserView): 193 199 MAX = 10 200 194 201 def __init__(self, context, request): 195 202 self.context = context … … 249 256 data.append(l) 250 257 if len(data) > 0: 251 self.data[NO_WF_BIND] = map(lambda t,d:t-d, self.data[NO_WF_BIND], data) 258 self.data[NO_WF_BIND] = map(lambda t, d: t - d, 259 self.data[NO_WF_BIND], data) 252 260 return self.data[state] 253 261 … … 270 278 max_value = max(self.getTotal()) 271 279 chart = VerticalBarStack(data, encoding='text') 272 chart.title('Content type by state').legend(*self.states+[NO_WF_BIND]) 280 chart.title('Content type by state').legend( 281 *self.states + [NO_WF_BIND]) 273 282 chart.bar('a', 10, 0).legend_pos("b") 274 283 chart.color(*COLORS) 275 chart.size(800, 375).scale(0, max_value).axes('xy').label(*self.types)284 chart.size(800, 375).scale(0, max_value).axes('xy').label(*self.types) 276 285 chart.axes.type("y") 277 chart.axes.range(0, 0,max_value)286 chart.axes.range(0, 0, max_value) 278 287 return chart.img() 279 288 … … 300 309 if obj.hasProperty('left_slots'): 301 310 info['left_slots'] = obj.getProperty('left_slots') 302 self.expressions = self.expressions.union(set(info['left_slots'])) 311 self.expressions = self.expressions.union( 312 set(info['left_slots'])) 303 313 if obj.hasProperty('right_slots'): 304 314 info['right_slots'] = obj.getProperty('right_slots') 305 self.expressions = self.expressions.union(set(info['right_slots'])) 315 self.expressions = self.expressions.union( 316 set(info['right_slots'])) 306 317 return info 307 318 308 319 def _walk(self, obj, level=-1): 309 320 yield self._getInfo(obj) 310 if level != 0 and (IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj)): 321 if level != 0 and (IFolderish.providedBy(obj) \ 322 or IBaseFolder.providedBy(obj)): 311 323 for v in obj.contentValues(): 312 for i in self._walk(v, level -1):324 for i in self._walk(v, level - 1): 313 325 yield i 314 326 … … 321 333 infos = [] 322 334 for i in self._walk(self.context, level): 323 if self.DEBUG or i['left_slots'] is not None or i['right_slots'] is not None: 335 if self.DEBUG or i['left_slots'] is not None \ 336 or i['right_slots'] is not None: 324 337 infos.append(i) 325 338 self.total = len(infos) … … 341 354 return exprs 342 355 356 343 357 class PropertiesStats(BrowserView): 344 358 def __init__(self, context, request): … … 362 376 if IPropertyManager.providedBy(obj): 363 377 obj = aq_base(obj) 364 self.proplist.extend([i for i in obj.propertyIds() if i not in self.proplist]) 378 self.proplist.extend( 379 [i for i in obj.propertyIds() if i not in self.proplist]) 365 380 if obj.hasProperty(self.propname): 366 381 info['slots'] = obj.getProperty(self.propname) … … 368 383 info['slots'] = str(info['slots']) 369 384 if not isinstance(info['slots'], basestring): 370 self.expressions = self.expressions.union(set(info['slots'])) 371 else: 372 self.expressions = self.expressions.union(set([info['slots']])) 385 self.expressions = self.expressions.union( 386 set(info['slots'])) 387 else: 388 self.expressions = self.expressions.union( 389 set([info['slots']])) 373 390 return info 374 391 375 392 def _walk(self, obj, level=-1): 376 393 yield self._getInfo(obj) 377 if level != 0 and (IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj)): 394 if level != 0 and (IFolderish.providedBy(obj) \ 395 or IBaseFolder.providedBy(obj)): 378 396 for v in obj.contentValues(): 379 for i in self._walk(v, level -1):397 for i in self._walk(v, level - 1): 380 398 yield i 381 399 … … 405 423 return exprs 406 424 425 407 426 class PortletsStats(BrowserView): 408 427 def __init__(self, context, request): … … 416 435 417 436 def getAssignmentMappingUrl(self, context, manager): 418 baseUrl = str(getMultiAdapter((context, self.request), name='absolute_url')) 437 baseUrl = str(getMultiAdapter((context, self.request), 438 name='absolute_url')) 419 439 return '%s/++contextportlets++%s' % (baseUrl, manager.__name__) 420 440 421 441 def getAssignmentsForManager(self, context, manager): 422 assignments = getMultiAdapter((context, manager), IPortletAssignmentMapping) 442 assignments = getMultiAdapter((context, manager), 443 IPortletAssignmentMapping) 423 444 return assignments.values() 424 445 425 446 def getPortletsMapping(self, context): 426 leftcolumn = getUtility(IPortletManager, name=u'plone.leftcolumn', context=context) 427 rightcolumn = getUtility(IPortletManager, name=u'plone.rightcolumn', context=context) 428 leftmapping = getMultiAdapter((context, leftcolumn,), IPortletAssignmentMapping) 429 rightmapping = getMultiAdapter((context, rightcolumn,), IPortletAssignmentMapping) 447 leftcolumn = getUtility(IPortletManager, name=u'plone.leftcolumn', 448 context=context) 449 rightcolumn = getUtility(IPortletManager, name=u'plone.rightcolumn', 450 context=context) 451 leftmapping = getMultiAdapter((context, leftcolumn,), 452 IPortletAssignmentMapping) 453 rightmapping = getMultiAdapter((context, rightcolumn,), 454 IPortletAssignmentMapping) 430 455 return (leftmapping, rightmapping) 431 456 432 457 def getLocalPortletsManager(self, context): 433 leftcolumn = getUtility(IPortletManager, name='plone.leftcolumn', context=context) 434 rightcolumn = getUtility(IPortletManager, name='plone.rightcolumn', context=context) 435 leftmanager = getMultiAdapter((context, leftcolumn,), ILocalPortletAssignmentManager) 436 rightmanager = getMultiAdapter((context, rightcolumn,), ILocalPortletAssignmentManager) 458 leftcolumn = getUtility(IPortletManager, name='plone.leftcolumn', 459 context=context) 460 rightcolumn = getUtility(IPortletManager, name='plone.rightcolumn', 461 context=context) 462 leftmanager = getMultiAdapter((context, leftcolumn,), 463 ILocalPortletAssignmentManager) 464 rightmanager = getMultiAdapter((context, rightcolumn,), 465 ILocalPortletAssignmentManager) 437 466 return (leftmanager, rightmanager) 438 467 439 468 def getPortletsManager(self, context): 440 left = getUtility(IPortletManager, name='plone.leftcolumn', context=context) 441 right = getUtility(IPortletManager, name='plone.rightcolumn', context=context) 469 left = getUtility(IPortletManager, name='plone.leftcolumn', 470 context=context) 471 right = getUtility(IPortletManager, name='plone.rightcolumn', 472 context=context) 442 473 return (left, right) 443 474 … … 458 489 459 490 data.append({ 460 'title' 461 'editview' 462 'visible' 491 'title': assignments[idx].title, 492 'editview': editviewName, 493 'visible': settings.get('visible', True), 463 494 }) 464 495 return data … … 481 512 #leftmanager, rightmanager = self.getLocalPortletsManager(obj) 482 513 #info['left_slots'] = self.getPortlets(obj, leftmapping, leftmanager) 483 #info['right_slots'] = self.getPortlets(obj, rightmapping, 514 #info['right_slots'] = self.getPortlets(obj, rightmapping,rightmanager) 484 515 lass = self.getAssignmentsForManager(obj, left) 485 516 rass = self.getAssignmentsForManager(obj, right) … … 489 520 prass = self.portlets_for_assignments(rass, right, rurl) 490 521 #print obj, plass, prass 491 info['left_slots'] = plass #[i['title'] for i in plass]492 info['right_slots'] = prass #[i['title'] for i in prass]522 info['left_slots'] = plass # [i['title'] for i in plass] 523 info['right_slots'] = prass # [i['title'] for i in prass] 493 524 return info 494 525 … … 498 529 except: 499 530 pass 500 if level != 0 and (IFolderish.providedBy(obj) or IBaseFolder.providedBy(obj)): 531 if level != 0 and (IFolderish.providedBy(obj) \ 532 or IBaseFolder.providedBy(obj)): 501 533 for v in obj.contentValues(): 502 for i in self._walk(v, level -1):534 for i in self._walk(v, level - 1): 503 535 yield i 504 536 … … 511 543 infos = [] 512 544 for i in self._walk(self.context, level): 513 if self.DEBUG or i['left_slots'] is not None or i['right_slots'] is not None: 545 if self.DEBUG or i['left_slots'] is not None \ 546 or i['right_slots'] is not None: 514 547 infos.append(i) 515 548 self.total = len(infos) -
quintagroup.analytics/trunk/quintagroup/analytics/config.py
r2999 r3169 1 COLORS = ['669933', 'CC9966', '993300', 'FF6633', 'E8E4E3', 'A9A486', 'DCB57E', 'FFCC99', '996633', '333300', '00FF00'] 1 COLORS = ['669933', 'CC9966', '993300', 'FF6633', 'E8E4E3', 'A9A486', 2 'DCB57E', 'FFCC99', '996633', '333300', '00FF00'] 2 3 OTHER_TYPES = ['Other types'] 3 4 NO_WF_BIND = 'No workflow' -
quintagroup.analytics/trunk/quintagroup/analytics/tests.py
r3043 r3169 17 17 18 18 ptc.setupPloneSite() 19 19 20 20 21 class Installed(PloneSite): … … 41 42 pass 42 43 44 43 45 class SetUpContent(Installed): 44 46 45 47 max = 10 46 48 types_ = ['Document', 'Event', 'Folder'] 47 users = [('user%s' %i, 'user%s'%i, 'Member', None)49 users = [('user%s' % i, 'user%s' % i, 'Member', None) 48 50 for i in xrange(max)] 49 51 … … 71 73 user = user.__of__(uf) 72 74 newSecurityManager(None, user) 73 for i in xrange(users.index(u)+cls.max): 74 map(folder.invokeFactory, cls.types_, [t+str(i) for t in cls.types_]) 75 for i in xrange(users.index(u) + cls.max): 76 map(folder.invokeFactory, cls.types_, 77 [t + str(i) for t in cls.types_]) 75 78 transaction.commit() 76 77 79 78 80 @classmethod … … 87 89 pass 88 90 91 89 92 class TestCase(ptc.PloneTestCase): 90 93 layer = Installed … … 99 102 """This test validates control panel action. """ 100 103 control_panel = self.portal.portal_controlpanel 101 self.assert_('QAnalytics' in [a.id for a in control_panel.listActions()], 102 "Configlet for quintagroup.analitycs isn't registered.") 104 self.assert_( 105 'QAnalytics' in [a.id for a in control_panel.listActions()], 106 "Configlet for quintagroup.analitycs isn't registered.") 103 107 104 108 def test_OwnershipByType(self): … … 147 151 self.assert_(view, "Properties Stats view isn't registered") 148 152 149 150 153 def test_PortletsStats(self): 151 154 """ This test validates registration of … … 156 159 157 160 self.assert_(view, "Portlets Stats view isn't registered") 161 158 162 159 163 class TestOwnershipByType(TestCase): … … 171 175 users = [u[0] for u in self.layer.users] 172 176 users.reverse() 173 self.assert_(False not in map(lambda u1, u2: u1==u2,177 self.assert_(False not in map(lambda u1, u2: u1 == u2, 174 178 users, self.view.getUsers())) 175 179 … … 190 194 data.reverse() 191 195 types = [i[0] for i in data] 192 self.assert_(False not in map(lambda t1, t2: t1==t2,196 self.assert_(False not in map(lambda t1, t2: t1 == t2, 193 197 self.view.getTypes(), types)) 194 198 … … 204 208 for type_ in self.layer.types_: 205 209 self.assert_(False not in \ 206 map(lambda i, j:i==j, [len(self.pc(portal_type=type_, Creator=user)) 210 map(lambda i, j: i == j, [len(self.pc(portal_type=type_, 211 Creator=user)) 207 212 for user in self.view.getUsers()], 208 213 self.view.getContent(type_))) … … 216 221 19.0,18.0,17.0,16.0,15.0,14.0,13.0,12.0,11.0,10.0|0.0, 217 222 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0|0.0,0.0,0.0,0.0, 218 0.0,0.0,0.0,0.0,0.0,0.0&chxr=0,0,57&chco=669933,cc9966, 219 993300,ff6633,e8e4e3,a9a486,dcb57e,ffcc99,996633,333300,00ff00& 223 0.0,0.0,0.0,0.0,0.0,0.0&chxr=0,0,57& 224 chco=669933,cc9966,993300,ff6633,e8e4e3,a9a486, 225 dcb57e,ffcc99,996633,333300,00ff00& 220 226 chl=user9|user8|user7|user6|user5|user4|user3|user2|user1| 221 227 user0&chbh=a,10,0&chs=800x375&cht=bvs& … … 239 245 240 246 self.loginAsPortalOwner() 241 self.assertEqual(*map(lambda s: ''.join(s.split()),247 self.assertEqual(*map(lambda s: ''.join(s.split()), 242 248 [chart_tag, self.view.getChart()])) 249 243 250 244 251 class TestOwnershipByState(TestCase): … … 258 265 users = [u[0] for u in self.layer.users] 259 266 users.reverse() 260 self.assert_(False not in map(lambda u1, u2: u1==u2,267 self.assert_(False not in map(lambda u1, u2: u1 == u2, 261 268 users, self.view.getUsers())) 262 269 263 270 def test_getStates(self): 264 271 """ Tests method that returns ordered list of states.""" 265 self.assert_(False not in map(lambda s1, s2: s1==s2,272 self.assert_(False not in map(lambda s1, s2: s1 == s2, 266 273 ['private', 'published'], self.view.getStates())) 267 274 … … 277 284 for state in self.states: 278 285 self.assert_(False not in \ 279 map(lambda i, j:i==j,[len(self.pc(review_state=state, Creator=user)) 286 map(lambda i, j: i == j, [len(self.pc(review_state=state, 287 Creator=user)) 280 288 for user in self.view.getUsers()], 281 289 self.view.getContent(state))) … … 294 302 published|No+workflow&chdlp=b"/>""" 295 303 self.loginAsPortalOwner() 296 self.assertEqual(*map(lambda s: ''.join(s.split()),304 self.assertEqual(*map(lambda s: ''.join(s.split()), 297 305 [chart_tag, self.view.getChart()])) 306 298 307 299 308 class TestTypeByState(TestCase): … … 323 332 data.reverse() 324 333 types = [i[0] for i in data] 325 self.assert_(False not in map(lambda t1, t2: t1==t2, types,334 self.assert_(False not in map(lambda t1, t2: t1 == t2, types, 326 335 self.view.getTypes())) 327 336 328 337 def test_getStates(self): 329 338 """ Tests method that returns ordered list of states.""" 330 self.assert_(False not in map(lambda s1, s2: s1==s2,339 self.assert_(False not in map(lambda s1, s2: s1 == s2, 331 340 ['private', 'published'], self.view.getStates())) 332 341 … … 342 351 for state in self.states: 343 352 self.assert_(False not in \ 344 map(lambda i, j: i==j, [len(self.pc(portal_type=type_,353 map(lambda i, j: i == j, [len(self.pc(portal_type=type_, 345 354 review_state=state)) 346 355 for type_ in self.view.getTypes()], … … 373 382 374 383 self.loginAsPortalOwner() 375 self.assertEqual(*map(lambda s: ''.join(s.split()),384 self.assertEqual(*map(lambda s: ''.join(s.split()), 376 385 [chart_tag, self.view.getChart()])) 386 377 387 378 388 class LegacyPortlets(TestCase): 379 389 """Test all legasy_portlets view methods.""" 380 390 381 382 391 def afterSetUp(self): 383 392 self.view = queryMultiAdapter((self.portal, self.portal.REQUEST), … … 395 404 # this is true for Plone 4 396 405 self.assert_(self.view.getAllPortletExpressions() == []) 406 397 407 398 408 class TestPropertiesStats(TestCase): … … 429 439 mapping.restrictedTraverse('+/' + portlet.addview)() 430 440 431 plone_portlets_info = filter(lambda info: info['path'] == '/plone',441 plone_portlets_info = filter(lambda info: info['path'] == '/plone', 432 442 self.view.getPropsList()) 433 443 lslots = plone_portlets_info[0]['left_slots'] -
quintagroup.analytics/trunk/setup.py
r2880 r3169 9 9 long_description=open("README.txt").read() + "\n" + 10 10 open(os.path.join("docs", "HISTORY.txt")).read(), 11 # Get more strings from http://www.python.org/pypi?%3Aaction=list_classifiers12 11 classifiers=[ 13 12 "Framework :: Plone",
Note: See TracChangeset
for help on using the changeset viewer.