Пример #1
0
 def export(self, request=None, objects=None):
     if not objects:
         if IOrganization.providedBy(self.context):
             objects = [self.context]
         else:
             search = getAdapter(self.context, interface=ISearch, name='organization')
             objects = search.search()
     return self._export(objects, len(objects)>1 and 'organizations' or objects[0].getId(), request)
Пример #2
0
 def export(self, request=None, objects=None):
     if not objects:
         if IOrganization.providedBy(self.context):
             objects = [self.context]
         else:
             search = getAdapter(self.context,
                                 interface=ISearch,
                                 name='organization')
             objects = search.search()
     return self._export(
         objects,
         len(objects) > 1 and 'organizations' or objects[0].getId(),
         request)
Пример #3
0
 def rows(self):
     attrs = {}
     if hasattr(self.request, 'SESSION'):
         if self.newSearch():
             attrs = {}
             for attr in self.attrs:
                 self.request.SESSION.set('%s.%s' % (self.name, attr), self.request.get('form.%s' % attr, None))
                 
         for attr in self.attrs:
             attrs[attr] = self.request.SESSION.get('%s.%s' % (self.name, attr), None)
     
     search = getAdapter(self.context, interface=ISearch, name=self.name)
     results = search.search(query=attrs, sort=self.sort)
     if not results:
         return []
 
     columns = self.cols.get_columns()
     countries = getUtility(IVocabularyFactory, name='contacts.countries')(self.context)
     states = getUtility(IVocabularyFactory, name='contacts.states')(self.context)
     rows = []
     for result in results:
         row = []
         for col in columns:
             html = '<span>'
             if col == 'country':
                 try:
                     value = countries.getTerm(result.country).title
                     if value:
                         html += value
                 except LookupError:
                     pass
             elif col == 'state':
                 try:
                     value = states.getTerm(result.state).title
                     if value:
                         html += value
                 except LookupError:
                     pass
             elif col == 'organization':
                 value = getattr(result, col, '')
                 if IOrganization.providedBy(value):
                     html += value.Title()
             elif col == 'photo':
                 photo = getattr(result, col, '')
                 if isinstance(photo, Image):
                     html += result.tag(scale='thumb')
             elif col == 'birthdate':
                 msg = result.getField('birthdate').getLocalized(result)
                 if msg:
                     html += translate(msg, context=self.request)
             else:
                 html += getattr(result, col, '')
             html += '</span>'
 
             # If the column is the title (Full name), the short name, first
             # name, or last name, i need to wrap it between <a> tags
             if col in ('title', 'shortName', 'firstName', 'lastName'):
                 html = '<a href="%s">%s</a>' % (result.absolute_url(), html)
 
             # If the column is the organization, then i wrap it between
             # <a> tags with the organization's URL
             if col == 'organization':
                 value = getattr(result, col, '')
                 if IOrganization.providedBy(value):
                     html = '<a href="%s">%s</a>' % (value.absolute_url(), html)
                         
             # If the column is the email address (any of them), i need to
             # wrap it between <a> tags with mailto:
             if col in ('email', 'workEmail', 'workEmail2', 'workEmail3'):
                 html = '<a href="mailto:%s">%s</a>' % (getattr(result, col, ''), html)
                         
             # If the column is the phone number (any of them), i need to
             # wrap it between <a> tags with callto:
             if col in ('phone', 'workPhone', 'workPhoneInternal', 'phoneInternal'):
                 html = '<a href="callto:%s">%s</a>' % (getattr(result, col, ''), html)
 
             # If the column is the website field, i need also <a> tags
             if col == 'web':
                 html = '<a href="%s">%s</a>' % (getattr(result, col, ''), html)
                 
             if col == 'members':
                 html = len(result.persons)
 
             row.append(html)
         rows.append({'object': result,
                      'cells': row})
     return rows
Пример #4
0
    def rows(self):
        attrs = {}
        if hasattr(self.request, 'SESSION'):
            if self.newSearch():
                attrs = {}
                for attr in self.attrs:
                    self.request.SESSION.set(
                        '%s.%s' % (self.name, attr),
                        self.request.get('form.%s' % attr, None))

            for attr in self.attrs:
                attrs[attr] = self.request.SESSION.get(
                    '%s.%s' % (self.name, attr), None)

        search = getAdapter(self.context, interface=ISearch, name=self.name)
        results = search.search(query=attrs, sort=self.sort)
        if not results:
            return []

        columns = self.cols.get_columns()
        countries = getUtility(IVocabularyFactory,
                               name='contacts.countries')(self.context)
        states = getUtility(IVocabularyFactory,
                            name='contacts.states')(self.context)
        rows = []
        for result in results:
            row = []
            for col in columns:
                html = '<span>'
                if col == 'country':
                    try:
                        value = countries.getTerm(result.country).title
                        if value:
                            html += value
                    except LookupError:
                        pass
                elif col == 'state':
                    try:
                        value = states.getTerm(result.state).title
                        if value:
                            html += value
                    except LookupError:
                        pass
                elif col == 'organization':
                    value = getattr(result, col, '')
                    if IOrganization.providedBy(value):
                        html += value.Title()
                elif col == 'photo':
                    photo = getattr(result, col, '')
                    if isinstance(photo, Image):
                        html += result.tag(scale='thumb')
                elif col == 'birthdate':
                    msg = result.getField('birthdate').getLocalized(result)
                    if msg:
                        html += translate(msg, context=self.request)
                else:
                    html += getattr(result, col, '')
                html += '</span>'

                # If the column is the title (Full name), the short name, first
                # name, or last name, i need to wrap it between <a> tags
                if col in ('title', 'shortName', 'firstName', 'lastName'):
                    html = '<a href="%s">%s</a>' % (result.absolute_url(),
                                                    html)

                # If the column is the organization, then i wrap it between
                # <a> tags with the organization's URL
                if col == 'organization':
                    value = getattr(result, col, '')
                    if IOrganization.providedBy(value):
                        html = '<a href="%s">%s</a>' % (value.absolute_url(),
                                                        html)

                # If the column is the email address (any of them), i need to
                # wrap it between <a> tags with mailto:
                if col in ('email', 'workEmail', 'workEmail2', 'workEmail3'):
                    html = '<a href="mailto:%s">%s</a>' % (getattr(
                        result, col, ''), html)

                # If the column is the phone number (any of them), i need to
                # wrap it between <a> tags with callto:
                if col in ('phone', 'workPhone', 'workPhoneInternal',
                           'phoneInternal'):
                    html = '<a href="callto:%s">%s</a>' % (getattr(
                        result, col, ''), html)

                # If the column is the website field, i need also <a> tags
                if col == 'web':
                    html = '<a href="%s">%s</a>' % (getattr(result, col,
                                                            ''), html)

                if col == 'members':
                    html = len(result.persons)

                row.append(html)
            rows.append({'object': result, 'cells': row})
        return rows