def project_brains_for(self, member): if not IReMember.providedBy(member): return [] mships = self.mship_brains_for(member) teams = [i.getPath().split('/')[-2] for i in mships] projects = self.catalog(portal_type='OpenProject', id=teams) return sorted(projects, key=lambda b:b.getId.lower())
def get_cookie_hash(self): if self.request.environ['REQUEST_METHOD'] != "POST": self.request.response.setStatus(405) return mem_folder = self.context pm = getToolByName(mem_folder, "portal_membership") mem_id = mem_folder.getId() member = pm.getMemberById(mem_id) if not IReMember.providedBy(member): # we're only interested in site members, not root level # admins self.request.response.setStatus(400) return pw = self.request.form.get('__ac_password') acl = getToolByName(self.context, "acl_users") auth = acl.credentials_signed_cookie_auth if not member.verifyCredentials(dict(login=mem_id, password=pw)): self.request.response.setStatus(400) return return auth.generateCookie(mem_id)
def member_profile_tags(self, member, field): """ Returns a list of dicts mapping each tag in the given field of the given member's profile to a url corresponding to a search for that tag. """ # XXX This isn't used anywhere as of 2009-05-21? see comment # in profile.pt. - PW if IReMember.providedBy(member): tags = getattr(member, 'get%s' % field.title())() tags = tags.split(',') tags = [tag.strip() for tag in tags if tag.strip()] tagsearchurl = self.portal.absolute_url() + '/tagsearch/' urls = [tagsearchurl + urllib.quote(tag) for tag in tags] return [{'tag': tag, 'url': url} for tag, url in zip(tags, urls)] return []
def testInterfaces(self): individual = self.createMember(login='******', password='******', fullname="Individual One") self.failUnless(IReMember.providedBy(individual), "Individual doesn't provide IReMember")
def member_info_for_member(self, member): if member == None: # Not logged in. return {} id = member.getId() result = {'id': id} folder = self.membertool.getHomeFolder(id) if folder: # we only add a URL to the result dict if the member folder exists. # if the folder does not exist, that means that the member has never # logged in (since member folders are created on first login, after # account confirmation) # if the folder does not exist, we have no good link to the member # so we just don't provide one result['url'] = folder.absolute_url() result['absolute_url'] = folder.absolute_url() if IReMember.providedBy(member): logintime = member.getLogin_time() if logintime == DateTime.DateTime('2000/01/01'): # XXX hack around zope logintime = 'never' else: logintime = logintime and prettyDate(logintime) or 'member.getLogin_time() is None?' result.update( id = id, Title = member.Title(), fullname = member.getFullname(), email = member.getEmail(), membersince = prettyDate(member.creation_date), lastlogin = logintime, folder_url = self.memfolder_url(id_=id), home_url = self.memhome_url(id_=id), projects = self.project_brains_for(member), location = member.getLocation(), statement = member.getStatement(), background = member.getBackground(), skills = member.getSkills(), affiliations= member.getAffiliations(), website = member.getWebsite(), favorites = member.getFavorites(), anon_email = member.getUseAnonByDefault(), ) else: # XXX TODO # we're an old school member object, e.g. an admin user result.update(fullname=member.fullname) for key in 'membersince', 'lastlogin','location', \ 'statement', 'affiliations', 'skills', \ 'background', 'url', 'favorites', 'folder_url': result[key] = '' folder = self.membertool.getHomeFolder(result['id']) if folder: result['url'] = folder.absolute_url() # @@ DWM: should be in an adapter or on the member object result['portrait_url'] = self.defaultPortraitURL portrait = member.getProperty('portrait', None) if portrait: result['portrait_url'] = portrait.absolute_url() result['portrait_thumb_url'] = "%s_thumb" %portrait.absolute_url() result['portrait_width'] = str(portrait.width) else: result['portrait_thumb_url'] = self.defaultPortraitThumbURL result['portrait_width'] = '200' # XXX don't hard code width of default portrait # XXX We should do something like the following to avoid # potential UnicodeDecodeErrors all over the place; But lots # of tests are wired to expect str output and I don't have # time to chase those down and decide if I'm right. - Paul W. # for key, val in result.items(): # # Much of this came from archetypes data, which # # horrifically stores everything as encoded bytes...decode # # it to be safe. # if isinstance(val, str): # try: # result[key] = val.decode('utf-8') # except UnicodeDecodeError: # # XXX we have non-utf8 data? dunno what to do then. # pass return result