Esempio n. 1
0
    def extract_record(self, record, values):
        fields = {
            'contact': lambda r: extract_value(r, 'contact', 'name'),
            'contact_email': lambda r: r.contact_email,
            'contact_phone': lambda r: r.contact_phone,
            'communication_type': lambda r: r.contact_type,
            'created_on': lambda r: r.created_on,
            'created_by': lambda r: extract_value(r, 'created_by', 'email'),
            'date_time': lambda r: r.date_time,
            'job_applications': lambda r: r.job_applications,
            'job_hires': lambda r: r.job_hires,
            'job_id': lambda r: r.job_id,
            'job_interviews': lambda r: r.job_interviews,
            'last_action_time': lambda r: r.last_action_time,
            'length': lambda r: r.length,
            'location': lambda r: r.location,
            'notes': lambda r: self.normalize_html(r.notes),
            'partner': lambda r: extract_value(r, 'partner', 'name'),
            'subject': lambda r: r.subject,
            'tags': lambda r: extract_tags(r.tags),
        }

        if values:
            return_values = values
        else:
            return_values = fields.keys()

        return {
            k: v(record)
            for k, v in fields.iteritems() if k in return_values
        }
Esempio n. 2
0
    def extract_record(self, record, values):
        fields = {
            'contact': lambda r: extract_value(r, 'contact', 'name'),
            'contact_email': lambda r: r.contact_email,
            'contact_phone': lambda r: r.contact_phone,
            'communication_type': lambda r: r.contact_type,
            'created_on': lambda r: r.created_on,
            'created_by': lambda r: extract_value(r, 'created_by', 'email'),
            'date_time': lambda r: r.date_time,
            'job_applications': lambda r: r.job_applications,
            'job_hires': lambda r: r.job_hires,
            'job_id': lambda r: r.job_id,
            'job_interviews': lambda r: r.job_interviews,
            'last_action_time': lambda r: r.last_action_time,
            'length': lambda r: r.length,
            'location': lambda r: r.location,
            'notes': lambda r: self.normalize_html(r.notes),
            'partner': lambda r: extract_value(r, 'partner', 'name'),
            'subject': lambda r: r.subject,
            'tags': lambda r: extract_tags(r.tags),
        }

        if values:
            return_values = values
        else:
            return_values = fields.keys()

        return {
            k: v(record)
            for k, v in fields.iteritems()
            if k in return_values
        }
Esempio n. 3
0
    def extract_record(self, record, values):
        """Translate from a query set record to a dictionary."""
        fields = {
            'name':
            lambda r: r.name,
            'partner':
            lambda r: extract_value(r, 'partner', 'name'),
            'email':
            lambda r: r.email,
            'phone':
            lambda r: r.phone,
            'notes':
            lambda r: r.notes,
            'locations':
            lambda r: [{
                'city': l.city,
                'state': l.state
            } for l in r.locations.all()],
            'date':
            lambda r: r.last_action_time,
            'tags':
            lambda r: extract_tags(r.tags.all()),
        }

        if values:
            return_values = values
        else:
            return_values = fields.keys()

        return {
            k: v(record)
            for k, v in fields.iteritems() if k in return_values
        }
Esempio n. 4
0
    def extract_record(self, record, values):
        """Translate from a query set record to a dictionary."""
        fields = {
            'name': lambda r: r.name,
            'partner': lambda r: extract_value(r, 'partner', 'name'),
            'email': lambda r: r.email,
            'phone': lambda r: r.phone,
            'notes': lambda r: r.notes,
            'locations': lambda r: [
                {'city': l.city, 'state': l.state}
                for l in r.locations.all()
            ],
            'date': lambda r: r.last_action_time,
            'tags': lambda r: extract_tags(r.tags.all()),
        }

        if values:
            return_values = values
        else:
            return_values = fields.keys()

        return {
            k: v(record)
            for k, v in fields.iteritems()
            if k in return_values
        }
Esempio n. 5
0
    def test_extract_value(self):
        """Tests that the proper values are extracted from an object."""

        class Foo(object):
            value = 'foo'


        class Bar(object):
            value = 'bar'
            foo = Foo()

        foo = Foo()
        bar = Bar()

        # single-level object traversal
        self.assertEqual(extract_value(foo, 'value'), 'foo')
        self.assertEqual(extract_value(foo, 'bar'), None)

        # default values
        self.assertEqual(extract_value(foo, 'bar', default='bar'), 'bar')
        self.assertEqual(extract_value(foo, 'value', default='bar'), 'foo')

        # multiple-level object traversal
        self.assertEqual(extract_value(bar, 'foo', 'value'), 'foo')
        self.assertEqual(extract_value(bar, 'foo', 'buz'), None)
Esempio n. 6
0
    def test_extract_value(self):
        """Tests that the proper values are extracted from an object."""
        class Foo(object):
            value = 'foo'

        class Bar(object):
            value = 'bar'
            foo = Foo()

        foo = Foo()
        bar = Bar()

        # single-level object traversal
        self.assertEqual(extract_value(foo, 'value'), 'foo')
        self.assertEqual(extract_value(foo, 'bar'), None)

        # default values
        self.assertEqual(extract_value(foo, 'bar', default='bar'), 'bar')
        self.assertEqual(extract_value(foo, 'value', default='bar'), 'foo')

        # multiple-level object traversal
        self.assertEqual(extract_value(bar, 'foo', 'value'), 'foo')
        self.assertEqual(extract_value(bar, 'foo', 'buz'), None)