def __call__(self): request = self.request form = request.form self.current() ajax = request.get('HTTP_X_REQUESTED_WITH', None) position, (member, level, show) = self.current_entry() from_url = '' if form: self.change_skill(position, member, level, show, form) from_url = form.get('from_url', '') if not ajax: return request.response.redirect(from_url) context = self.context url = context.absolute_url() if not ajax: return request.response.redirect(url) position, (member, level, show) = self.current_entry() levels = [] if level in ['x', 'X']: title = context.translate(_(u"(Experience level unknown)")) levels.append(LEVEL % ('X', SELECTED, title)) e_val = True if level is False else False for l in self.levels: v, t = l[:2] s = SELECTED if v == level or v == '' and e_val else '' levels.append(LEVEL % (v, s, t)) levels = LEVELS % '\n'.join(levels) show = SHOW % (' checked="checked"' if show not in ['', 'n', False] else '', context.translate(_(u'On profile'))) return TEMPLATE % (url, position, levels, show, from_url)
def __call__(self): request = self.request form = request.form self.current() ajax = request.get('HTTP_X_REQUESTED_WITH', None) position, (member, level, show) = self.current_entry() from_url = '' if form: self.change_skill(position, member, level, show, form) from_url = form.get('from_url', '') if not ajax: return request.response.redirect(from_url) context = self.context url = context.absolute_url() if not ajax: return request.response.redirect(url) position, (member, level, show) = self.current_entry() levels = [] if level in ['x', 'X']: title = context.translate(_(u"(Experience level unknown)")) levels.append(LEVEL % ('X', SELECTED, title)) e_val = True if level is False else False for l in self.levels: v, t = l[:2] s = SELECTED if v == level or v == '' and e_val else '' levels.append(LEVEL % (v, s, t)) levels = LEVELS % '\n'.join(levels) show = SHOW % ( ' checked="checked"' if show not in ['', 'n', False] else '', context.translate(_(u'On profile'))) return TEMPLATE % (url, position, levels, show, from_url)
def _set_messages(self): """ Add portal messages """ ptools = self.context.plone_utils if self.e_count: if self.e_count == self.skill_count: ptools.addPortalMessage( _(u'You have empty profile, ' u'please qualify your experience level for each skill.'), 'error') else: ptools.addPortalMessage( _(u'You have empty entries in your profile, ' u'please add an experience level.'), 'error') if self.x_count: ptools.addPortalMessage( _(u'You have entries with an x value in your profile, ' u'please qualify your experience level.'), 'warning')
def cleanup_skills(self, remove, skills): for skill in skills: new_member_level_show = [] for mls in skill.member_level_show: member, level, show = mls.split('|') member = member.strip() if member not in remove: new_member_level_show.append(mls) skill.member_level_show = new_member_level_show self.context.plone_utils.addPortalMessage( _(u'The following users were removed from all skills: ') + ', '.join(remove))
def __call__(self): """ """ data = self.data() # Add legend with some space levels = self.levels data.append([]) data.append([]) data.append([self.context.translate(_(u"Legend"))]) data += self.legend # Clean up entries data = [[self.processEntry(column) for column in row] for row in data] # Create and send back a *.csv file return self.export_csv('knowledge', data, self.request.RESPONSE)
def data(self, single=False): """ Build up data table """ context = self.context self._setup_members(single) # Set up headers Expertise = context.translate(_(u"Expertise")) Subgroup = context.translate(_(u"Subgroup")) Name = context.translate(_(u"Name")) Searchterms = context.translate(_(u"Searchterms")) if not single: Total = context.translate(_(u"Total")) # Row with employee names names = [''] * 4 # Prefill with 5 empties names.append(Total) names += self.fullnames employee_count = len(self.fullnames) # Row with headers and column_counts total = 0 totals = [Expertise, Subgroup, Name, Searchterms] totals += [0] * employee_count else: # Row with headers headers = [ Expertise, Subgroup, Name, Searchterms, self.current_fullname] # Full data set _d = [] # Data self.x_count, self.e_count = 0, 0 # Count _expertise, _group = '', '' # Sticky expertise and group for skill in self.skills: row_total = 0 # Row headers expertise_group = skill.group.split('|') if len(expertise_group) == 2: expertise, group = expertise_group else: expertise, group = ('', '') title = skill.title description = skill.description # Prepend headers row = [expertise if expertise != _expertise else '', group if group != _group else '', title, description] # Update sticky expertise and group _expertise, _group = expertise, group # Parse member_level_show levels = dict([ (x.split('|')[0], (x.split('|')[1], x.split('|')[2])) for x in skill.member_level_show if len(x.split('|')) == 3] if skill.member_level_show else []) for i, member in enumerate(self.ordered_members): level, show = levels.get(member, (False, False)) is_current = member == self.current_id cell_class, x_val = '', False # Calculations if level: try: amount = int(level) except ValueError: if level in ['x', 'X']: amount = 1 x_val = True if is_current: self.x_count += 1 cell_class = 'update' else: amount = 0 if level is False and is_current: self.e_count += 1 cell_class = 'empty' # Add level to row if not single: row.append(level if level else '') row_total += amount total += amount totals[i + 4] += amount else: row.append({ "level": level if level else '', "x_val": x_val, "show": ( True if show not in ['', 'n', False] else False), 'url': skill.absolute_url(), 'cclass': cell_class }) if not single: row.insert(4, row_total) _d.append(row) if not single: totals.insert(4, total) _d.insert(0, names) _d.insert(1, totals) else: _d.insert(0, headers) if not self.other_id: self._set_messages() return _d
def experience(self): return _(u"Experience")